4 * Copyright (C) 2002-2004 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: getifname.c,v 1.5.2.3 2006/07/14 06:12:24 darrenr Exp
16 * Given a pointer to an interface in the kernel, return a pointer to a
17 * string which is the interface name.
23 #if SOLARIS || defined(__hpux)
25 # include <sys/mutex.h>
26 # include <sys/condvar.h>
31 # include "../pfil/qif.h"
35 if ((void *)ptr
== (void *)-1)
40 if (kmemcpy((char *)&qif
, (u_long
)ptr
, sizeof(qif
)) == -1)
42 ifname
= strdup(qif
.qf_name
);
43 if ((ifname
!= NULL
) && (*ifname
== '\0')) {
49 # if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \
50 defined(__OpenBSD__) || \
51 (defined(__FreeBSD__) && (__FreeBSD_version >= 501113))
58 if ((void *)ptr
== (void *)-1)
63 if (kmemcpy((char *)&netif
, (u_long
)ptr
, sizeof(netif
)) == -1)
65 # if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \
66 defined(__OpenBSD__) || defined(linux) || \
67 (defined(__FreeBSD__) && (__FreeBSD_version >= 501113))
68 return strdup(netif
.if_xname
);
70 if (kstrncpy(buf
, (u_long
)netif
.if_name
, sizeof(buf
)) == -1)
72 if (netif
.if_unit
< 10)
74 else if (netif
.if_unit
< 1000)
76 else if (netif
.if_unit
< 10000)
80 buf
[sizeof(buf
) - len
] = '\0';
81 sprintf(buf
+ strlen(buf
), "%d", netif
.if_unit
% 10000);