Date: Wed, 19 Feb 1997 20:36:28 -0600 From: elh@astroarch.com To: freebsd-bugs@FreeBSD.ORG Cc: elh@secretariat.astroarch.com Subject: SIOCGIFPHYS Message-ID: <199702200236.UAA09387@secretariat.astroarch.com>
next in thread | raw e-mail | index | archive | help
I am in need of code that can query the physical hardware address of an ethernet. I have written the following code but it is to no avail. The SIOCIFPHYS and ifi_physical return 0. I am running 2.1 of FreeBSD. The code follows: #include <sys/param.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <sys/sysctl.h> #include <sys/time.h> #include <net/if.h> #include <net/if_dl.h> #include <net/if_types.h> #include <net/route.h> /* IP */ #include <netinet/in.h> #include <netinet/in_var.h> #include <arpa/inet.h> #include <netdb.h> main() { size_t needed; int mib[6]; char *buf, *lim, *next; struct if_msghdr *ifm; struct sockaddr_dl *sdl; int s,flags; int af = AF_INET; char name[32]; struct ifreq ifr; mib[0] = CTL_NET; mib[1] = PF_ROUTE; mib[2] = 0; mib[3] = 0; /* address family */ mib[4] = NET_RT_IFLIST; mib[5] = 0; /* if particular family specified, only ask about it */ sysctl(mib, 6, NULL, &needed, NULL, 0); buf = (char *)malloc(needed); sysctl(mib, 6, buf, &needed, NULL, 0); lim=buf+needed; for (next = buf; next < lim; next += ifm->ifm_msglen) { ifm = (struct if_msghdr *)next; /* XXX: Swallow up leftover NEWADDR messages */ if (ifm->ifm_type == RTM_NEWADDR) continue; if (ifm->ifm_type == RTM_IFINFO) { sdl = (struct sockaddr_dl *)(ifm + 1); flags = ifm->ifm_flags; } strncpy(name, sdl->sdl_data, sdl->sdl_nlen); name[sdl->sdl_nlen] = '\0'; printf("%s %s\n",name,ifm->ifm_data.ifi_physical); s = socket(af, SOCK_DGRAM, 0); strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); ioctl(s, SIOCGIFPHYS, (caddr_t)&ifr); printf("%s %d\n",name,ifr.ifr_phys); } } Suggestions are welcome. :) Best regards, Ed Haletky
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702200236.UAA09387>