From owner-freebsd-hackers Thu Aug 2 10:19:45 2001 Delivered-To: freebsd-hackers@freebsd.org Received: from fledge.watson.org (fledge.watson.org [204.156.12.50]) by hub.freebsd.org (Postfix) with ESMTP id 3B5DB37B401 for ; Thu, 2 Aug 2001 10:19:42 -0700 (PDT) (envelope-from robert@fledge.watson.org) Received: from fledge.watson.org (robert@fledge.pr.watson.org [192.0.2.3]) by fledge.watson.org (8.11.4/8.11.4) with SMTP id f72HJNf73274; Thu, 2 Aug 2001 13:19:24 -0400 (EDT) (envelope-from robert@fledge.watson.org) Date: Thu, 2 Aug 2001 13:19:23 -0400 (EDT) From: Robert Watson X-Sender: robert@fledge.watson.org To: Jag Johal Cc: "'hackers@freebsd.org'" , Michael VanLoon Subject: RE: Finding MAC address of interface - programming question In-Reply-To: Message-ID: 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 I actually prefer the API call getifaddrs(3), which does much the same thing, but hides the MIB management interface behind a fairly well-defined API, which also does the memory management. You can just pull out the link layer addresses along with interface description. Robert N M Watson FreeBSD Core Team, TrustedBSD Project robert@fledge.watson.org NAI Labs, Safeport Network Services On Tue, 31 Jul 2001, Jag Johal wrote: > Use sysctl(3), basically, its something like this. > mib[0] = CTL_NET; > mib[1] = AF_ROUTE; > mib[2] = 0; > mib[3] = AF_INET; > mib[4] = NET_RT_IFLIST; > mib[5] = 0; > > sysctl(mib, 6, buf, &len, NULL, 0); > buf will contain for each interface, an if_msghdr followed by a sockaddr_dl, > the sockaddr_dl will contain the interface name and mac addr. Following that > will be a ifa_msghdr for each ip address on the interface. You may want to > check out UNPv1. > > Jag > > -----Original Message----- > From: Chris Faulhaber [mailto:jedgar@fxp.org] > Sent: Tuesday, July 31, 2001 3:56 PM > To: Michael VanLoon > Cc: 'hackers@freebsd.org' > Subject: Re: Finding MAC address of interface - programming question > > > On Tue, Jul 31, 2001 at 03:56:40PM -0700, Michael VanLoon wrote: > > Please point me to a more appropriate forum if there is one. I'm kinda > out > > of my depth on this question. Pseudo code is fine. :-) > > > > What I'm looking for is how to enumerate the network interfaces and get > the > > Ethernet MAC address of one programmatically. Can anyone point me in the > > right direction? > > > > /usr/src/sbin/ifconfig > > -- > Chris D. Faulhaber - jedgar@fxp.org - jedgar@FreeBSD.org > -------------------------------------------------------- > FreeBSD: The Power To Serve - http://www.FreeBSD.org > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-hackers" in the body of the message > To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message