From owner-freebsd-bugs Wed Feb 19 18:36:11 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id SAA07934 for bugs-outgoing; Wed, 19 Feb 1997 18:36:11 -0800 (PST) Received: from secretariat.astroarch.com (secretariat.astroarch.com [207.170.64.37]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id SAA07928 for ; Wed, 19 Feb 1997 18:36:06 -0800 (PST) Received: (from elh@localhost) by secretariat.astroarch.com (8.7.4/8.7.3) id UAA09387; Wed, 19 Feb 1997 20:36:28 -0600 Date: Wed, 19 Feb 1997 20:36:28 -0600 Message-Id: <199702200236.UAA09387@secretariat.astroarch.com> To: freebsd-bugs@FreeBSD.ORG X-URL: http://www.freebsd.org/support.html X-Mailer: Lynx, Version 2.6 X-Personal_name: Edward L. Haletky From: elh@astroarch.com Subject: SIOCGIFPHYS Cc: elh@secretariat.astroarch.com Sender: owner-bugs@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk 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 #include #include #include #include #include #include #include #include /* IP */ #include #include #include #include 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