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