#include "ipf.h" #include "qif.h" #include "kmem.h" /* * Given a pointer to an interface in the kernel, return a pointer to a * string which is the interface name. */ char *getifname(ptr) struct ifnet *ptr; { #if SOLARIS char *ifname; s_ill_t ill; if ((void *)ptr == (void *)-1) return "!"; if (ptr == NULL) return "-"; if (kmemcpy((char *)&ill, (u_long)ptr, sizeof(ill)) == -1) return "X"; ifname = malloc(sizeof(ill.ill_name) + 1); strncpy(ifname, ill.ill_name, sizeof(ill.ill_name)); ifname[sizeof(ill.ill_name)] = '\0'; return ifname; #else # if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \ defined(__OpenBSD__) #else char buf[32]; int len; # endif struct ifnet netif; if ((void *)ptr == (void *)-1) return "!"; if (ptr == NULL) return "-"; if (kmemcpy((char *)&netif, (u_long)ptr, sizeof(netif)) == -1) return "X"; # if defined(NetBSD) && (NetBSD >= 199905) && (NetBSD < 1991011) || \ defined(__OpenBSD__) return strdup(netif.if_xname); # else if (kstrncpy(buf, (u_long)netif.if_name, sizeof(buf)) == -1) return "X"; if (netif.if_unit < 10) len = 2; else if (netif.if_unit < 1000) len = 3; else if (netif.if_unit < 10000) len = 4; else len = 5; buf[sizeof(buf) - len] = '\0'; sprintf(buf + strlen(buf), "%d", netif.if_unit % 10000); return strdup(buf); # endif #endif }