1145519Sdarrenr/* $FreeBSD$ */ 2145510Sdarrenr 3170268Sdarrenr/* 4255332Scy * Copyright (C) 2012 by Darren Reed. 5255332Scy * 6255332Scy * See the IPFILTER.LICENCE file for details on licencing. 7255332Scy * 8255332Scy * $Id$ 9255332Scy */ 10170268Sdarrenr 11145510Sdarrenr#include "ipf.h" 12145510Sdarrenr 13145510Sdarrenr#include "kmem.h" 14145510Sdarrenr 15145510Sdarrenr/* 16145510Sdarrenr * Given a pointer to an interface in the kernel, return a pointer to a 17145510Sdarrenr * string which is the interface name. 18145510Sdarrenr */ 19170268Sdarrenr#if 0 20145510Sdarrenrchar *getifname(ptr) 21255332Scy struct ifnet *ptr; 22145510Sdarrenr{ 23145510Sdarrenr#if SOLARIS || defined(__hpux) 24145510Sdarrenr# if SOLARIS 25145510Sdarrenr# include <sys/mutex.h> 26145510Sdarrenr# include <sys/condvar.h> 27145510Sdarrenr# endif 28145510Sdarrenr# ifdef __hpux 29145510Sdarrenr# include "compat.h" 30145510Sdarrenr# endif 31145510Sdarrenr# include "../pfil/qif.h" 32145510Sdarrenr char *ifname; 33145510Sdarrenr qif_t qif; 34145510Sdarrenr 35145510Sdarrenr if ((void *)ptr == (void *)-1) 36145510Sdarrenr return "!"; 37145510Sdarrenr if (ptr == NULL) 38145510Sdarrenr return "-"; 39145510Sdarrenr 40145510Sdarrenr if (kmemcpy((char *)&qif, (u_long)ptr, sizeof(qif)) == -1) 41145510Sdarrenr return "X"; 42145510Sdarrenr ifname = strdup(qif.qf_name); 43145510Sdarrenr if ((ifname != NULL) && (*ifname == '\0')) { 44145510Sdarrenr free(ifname); 45145510Sdarrenr return "!"; 46145510Sdarrenr } 47145510Sdarrenr return ifname; 48145510Sdarrenr#else 49145510Sdarrenr# if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \ 50145510Sdarrenr defined(__OpenBSD__) || \ 51145510Sdarrenr (defined(__FreeBSD__) && (__FreeBSD_version >= 501113)) 52145510Sdarrenr#else 53255332Scy char buf[LIFNAMSIZ]; 54145510Sdarrenr int len; 55145510Sdarrenr# endif 56145510Sdarrenr struct ifnet netif; 57145510Sdarrenr 58145510Sdarrenr if ((void *)ptr == (void *)-1) 59145510Sdarrenr return "!"; 60145510Sdarrenr if (ptr == NULL) 61145510Sdarrenr return "-"; 62145510Sdarrenr 63145510Sdarrenr if (kmemcpy((char *)&netif, (u_long)ptr, sizeof(netif)) == -1) 64145510Sdarrenr return "X"; 65145510Sdarrenr# if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \ 66145510Sdarrenr defined(__OpenBSD__) || defined(linux) || \ 67145510Sdarrenr (defined(__FreeBSD__) && (__FreeBSD_version >= 501113)) 68145510Sdarrenr return strdup(netif.if_xname); 69145510Sdarrenr# else 70145510Sdarrenr if (kstrncpy(buf, (u_long)netif.if_name, sizeof(buf)) == -1) 71145510Sdarrenr return "X"; 72145510Sdarrenr if (netif.if_unit < 10) 73145510Sdarrenr len = 2; 74145510Sdarrenr else if (netif.if_unit < 1000) 75145510Sdarrenr len = 3; 76145510Sdarrenr else if (netif.if_unit < 10000) 77145510Sdarrenr len = 4; 78145510Sdarrenr else 79145510Sdarrenr len = 5; 80145510Sdarrenr buf[sizeof(buf) - len] = '\0'; 81145510Sdarrenr sprintf(buf + strlen(buf), "%d", netif.if_unit % 10000); 82145510Sdarrenr return strdup(buf); 83145510Sdarrenr# endif 84145510Sdarrenr#endif 85145510Sdarrenr} 86170268Sdarrenr#else 87170268Sdarrenrchar *getifname(ptr) 88255332Scy struct ifnet *ptr; 89170268Sdarrenr{ 90255332Scy#if 0 91255332Scy ptr = ptr; 92255332Scy#endif 93170268Sdarrenr return "X"; 94170268Sdarrenr} 95170268Sdarrenr#endif 96