From owner-freebsd-hackers@FreeBSD.ORG Fri Aug 4 12:43:57 2006 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E96C516A4DA for ; Fri, 4 Aug 2006 12:43:57 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9C9FC43D45 for ; Fri, 4 Aug 2006 12:43:57 +0000 (GMT) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id C2B2046D22; Fri, 4 Aug 2006 08:43:56 -0400 (EDT) Date: Fri, 4 Aug 2006 13:43:56 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Mario Lobo In-Reply-To: <200608040759.49390.mario.lobo@ipad.com.br> Message-ID: <20060804134258.R56045@fledge.watson.org> References: <200608040759.49390.mario.lobo@ipad.com.br> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-hackers@freebsd.org Subject: Re: getting interface MAC addr from C X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 04 Aug 2006 12:43:58 -0000 On Fri, 4 Aug 2006, Mario Lobo wrote: > Would anyone have a tip on how to get the MAC from a C program? > > I tried: > > struct ifreq ifreq; > unsigned char *hw; > > strcpy(ifreq.ifr_name, "rl0"); > ioctl(fd, SIOCGIFMAC, &ifreq); > hw = ifreq.ifr_ifru.ifru_data; ???? > > but i don't know if this is right or, if it is, where to get the MAC from > the structure. I doesn't issue any error compiling or running though. Usually the general purpose interface recommended for inspecting interface information is getifaddrs(), which will build a userspace list of interfaces and their various addresses, including link-layer addresses. Something like the above will work, but may not be preferred. Robert N M Watson Computer Laboratory University of Cambridge > > In linux i used: > > struct ifreq ifreq; > unsigned char *hw; > > strcpy(ifreq.ifr_name, "rl0"); > ioctl(fd, SIOCGIFHWADDR, &ifreq); > hw = ifreq.ifr_hwaddr.sa_data; > > Thanks, > > Mario > _______________________________________________ > freebsd-hackers@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-hackers > To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org" >