Sync usage with man page.
[netbsd-mini2440.git] / dist / ipf / lib / getifname.c
blobb4c8649d850bc0bf6f392ba17770288a0c6a759c
1 /* $NetBSD$ */
3 /*
4 * Copyright (C) 2002-2004 by Darren Reed.
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 * Id: getifname.c,v 1.5.2.3 2006/07/14 06:12:24 darrenr Exp
9 */
11 #include "ipf.h"
13 #include "kmem.h"
16 * Given a pointer to an interface in the kernel, return a pointer to a
17 * string which is the interface name.
19 #if 0
20 char *getifname(ptr)
21 struct ifnet *ptr;
23 #if SOLARIS || defined(__hpux)
24 # if SOLARIS
25 # include <sys/mutex.h>
26 # include <sys/condvar.h>
27 # endif
28 # ifdef __hpux
29 # include "compat.h"
30 # endif
31 # include "../pfil/qif.h"
32 char *ifname;
33 qif_t qif;
35 if ((void *)ptr == (void *)-1)
36 return "!";
37 if (ptr == NULL)
38 return "-";
40 if (kmemcpy((char *)&qif, (u_long)ptr, sizeof(qif)) == -1)
41 return "X";
42 ifname = strdup(qif.qf_name);
43 if ((ifname != NULL) && (*ifname == '\0')) {
44 free(ifname);
45 return "!";
47 return ifname;
48 #else
49 # if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \
50 defined(__OpenBSD__) || \
51 (defined(__FreeBSD__) && (__FreeBSD_version >= 501113))
52 #else
53 char buf[32];
54 int len;
55 # endif
56 struct ifnet netif;
58 if ((void *)ptr == (void *)-1)
59 return "!";
60 if (ptr == NULL)
61 return "-";
63 if (kmemcpy((char *)&netif, (u_long)ptr, sizeof(netif)) == -1)
64 return "X";
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);
69 # else
70 if (kstrncpy(buf, (u_long)netif.if_name, sizeof(buf)) == -1)
71 return "X";
72 if (netif.if_unit < 10)
73 len = 2;
74 else if (netif.if_unit < 1000)
75 len = 3;
76 else if (netif.if_unit < 10000)
77 len = 4;
78 else
79 len = 5;
80 buf[sizeof(buf) - len] = '\0';
81 sprintf(buf + strlen(buf), "%d", netif.if_unit % 10000);
82 return strdup(buf);
83 # endif
84 #endif
86 #else
87 char *getifname(ptr)
88 struct ifnet *ptr;
90 return "X";
92 #endif