From owner-freebsd-hackers Wed Aug 1 2:50:27 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from chrobd01.vailsys.com (chrobd01.vailsys.com [63.210.102.138]) by hub.freebsd.org (Postfix) with ESMTP id 4C09237B406 for ; Wed, 1 Aug 2001 02:50:24 -0700 (PDT) (envelope-from hal@vailsys.com) Received: from area51.vail (area51.vail [192.168.129.30]) by chrobd01.vailsys.com (Postfix) with ESMTP id E22494963 for ; Wed, 1 Aug 2001 04:50:18 -0500 (CDT) Received: from gamera.vail (root@gamera.vail [172.16.15.1]) by area51.vail (8.9.3/8.9.3) with ESMTP id EAA74602 for ; Wed, 1 Aug 2001 04:50:18 -0500 (CDT) (envelope-from hal@vailsys.com) Received: (from hal@localhost) by gamera.vail (8.11.4/8.11.3) id f719oCx20321; Wed, 1 Aug 2001 04:50:12 -0500 (CDT) X-Authentication-Warning: gamera.vail: hal set sender to hal@vailsys.com using -f To: Subject: Re: Finding MAC address of interface - programming question References: <36F7B20351634E4FBFFE6C6A216B30D54C81@ecx1.edifecs.com> From: Hal Snyder Date: 01 Aug 2001 04:50:11 -0500 In-Reply-To: <36F7B20351634E4FBFFE6C6A216B30D54C81@ecx1.edifecs.com> (Michael VanLoon's message of "Tue, 31 Jul 2001 16:34:17 -0700") Message-ID: <873d7c9kj0.fsf@gamera.vail> Lines: 58 User-Agent: Gnus/5.090004 (Oort Gnus v0.04) XEmacs/21.1 (Cuyahoga Valley) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Michael VanLoon writes: > Thanks that's just exactly the information I was looking for. :-) > > I'm slow grunging through the code and man pages that take this apart. > > As far as UNPv1 I assume you're referring to Stevens' "Unix Network > Programming"? If I'm not mistaken he doesn't go much below the > socket level. A quick glance through didn't reveal anything of this > nature. See UNIX Network Programming 2ed, Vol.1, pp434-435 for SIOCGIFCONF explanation. But nowadays getifaddrs(3) is easier: /* hacked from netbsd ifconfig.c */ #include #include #include #include #include int main (void) { struct ifaddrs *ifap, *ifaphead; int rtnerr; const struct sockaddr_dl *sdl; caddr_t ap; int alen; rtnerr = getifaddrs(&ifaphead); if (rtnerr) { perror(NULL); return 1; } for (ifap = ifaphead; ifap; ifap = ifap->ifa_next) { if (ifap->ifa_addr->sa_family == AF_LINK) { sdl = (const struct sockaddr_dl *) ifap->ifa_addr; ap = ((caddr_t)((sdl)->sdl_data + (sdl)->sdl_nlen)); alen = sdl->sdl_alen; if (ap && alen > 0) { int i; printf ("%s:", ifap->ifa_name); for (i = 0; i < alen; i++, ap++) printf("%c%02x", i > 0 ? ':' : ' ', 0xff&*ap); putchar('\n'); } } } putchar('\n'); freeifaddrs(ifaphead); return 0; } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message