]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/lib/getifname.c
Merge openmp trunk r366426, resolve conflicts, and add FREEBSD-Xlist.
[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 #if 0
20 char *getifname(ptr)
21         struct ifnet *ptr;
22 {
23 #if SOLARIS || defined(__hpux)
24 # if SOLARIS
25 #  include <sys/mutex.h>
26 #  include <sys/condvar.h>
27 # endif
28 # include "../pfil/qif.h"
29         char *ifname;
30         qif_t qif;
31
32         if ((void *)ptr == (void *)-1)
33                 return "!";
34         if (ptr == NULL)
35                 return "-";
36
37         if (kmemcpy((char *)&qif, (u_long)ptr, sizeof(qif)) == -1)
38                 return "X";
39         ifname = strdup(qif.qf_name);
40         if ((ifname != NULL) && (*ifname == '\0')) {
41                 free(ifname);
42                 return "!";
43         }
44         return ifname;
45 #else
46 # if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \
47     defined(__OpenBSD__) || \
48     (defined(__FreeBSD__) && (__FreeBSD_version >= 501113))
49 #else
50         char buf[LIFNAMSIZ];
51         int len;
52 # endif
53         struct ifnet netif;
54
55         if ((void *)ptr == (void *)-1)
56                 return "!";
57         if (ptr == NULL)
58                 return "-";
59
60         if (kmemcpy((char *)&netif, (u_long)ptr, sizeof(netif)) == -1)
61                 return "X";
62 # if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \
63     defined(__OpenBSD__) || defined(linux) || \
64     (defined(__FreeBSD__) && (__FreeBSD_version >= 501113))
65         return strdup(netif.if_xname);
66 # else
67         if (kstrncpy(buf, (u_long)netif.if_name, sizeof(buf)) == -1)
68                 return "X";
69         if (netif.if_unit < 10)
70                 len = 2;
71         else if (netif.if_unit < 1000)
72                 len = 3;
73         else if (netif.if_unit < 10000)
74                 len = 4;
75         else
76                 len = 5;
77         buf[sizeof(buf) - len] = '\0';
78         sprintf(buf + strlen(buf), "%d", netif.if_unit % 10000);
79         return strdup(buf);
80 # endif
81 #endif
82 }
83 #else
84 char *getifname(ptr)
85         struct ifnet *ptr;
86 {
87 #if 0
88         ptr = ptr;
89 #endif
90         return "X";
91 }
92 #endif