]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/lib/getifname.c
ipfilter getifname ifdef cleanup.
[FreeBSD/FreeBSD.git] / contrib / ipfilter / lib / getifname.c
1 /*      $FreeBSD$       */
2
3 /*
4  * Copyright (C) 2012 by Darren Reed.
5  *
6  * See the IPFILTER.LICENCE file for details on licencing.
7  *
8  * $Id$
9  */
10
11 #include "ipf.h"
12
13 #include "kmem.h"
14
15 /*
16  * Given a pointer to an interface in the kernel, return a pointer to a
17  * string which is the interface name.
18  */
19 char *getifname(ptr)
20         struct ifnet *ptr;
21 {
22 #if SOLARIS
23 #  include <sys/mutex.h>
24 #  include <sys/condvar.h>
25 # include "../pfil/qif.h"
26         char *ifname;
27         qif_t qif;
28
29         if ((void *)ptr == (void *)-1)
30                 return "!";
31         if (ptr == NULL)
32                 return "-";
33
34         if (kmemcpy((char *)&qif, (u_long)ptr, sizeof(qif)) == -1)
35                 return "X";
36         ifname = strdup(qif.qf_name);
37         if ((ifname != NULL) && (*ifname == '\0')) {
38                 free(ifname);
39                 return "!";
40         }
41         return ifname;
42 #else
43         struct ifnet netif;
44
45         if ((void *)ptr == (void *)-1)
46                 return "!";
47         if (ptr == NULL)
48                 return "-";
49
50         if (kmemcpy((char *)&netif, (u_long)ptr, sizeof(netif)) == -1)
51                 return "X";
52         return strdup(netif.if_xname);
53 #endif
54 }