From owner-freebsd-ports Mon Nov 6 11: 4:15 2000 Delivered-To: freebsd-ports@freebsd.org Received: from seven.watermarkgroup.com (seven.watermarkgroup.com [207.202.73.98]) by hub.freebsd.org (Postfix) with ESMTP id 3DE3237B4CF; Mon, 6 Nov 2000 11:04:09 -0800 (PST) Received: (from luoqi@localhost) by seven.watermarkgroup.com (8.9.3/8.9.3) id OAA09537; Mon, 6 Nov 2000 14:04:08 -0500 (EST) (envelope-from luoqi) Date: Mon, 6 Nov 2000 14:04:08 -0500 (EST) From: Luoqi Chen Message-Id: <200011061904.OAA09537@seven.watermarkgroup.com> To: emulation@FreeBSD.ORG, pfeifer@dbai.tuwien.ac.at, ports@FreeBSD.ORG Subject: Re: Wine port: How to obtain MAC address? In-Reply-To: Sender: owner-freebsd-ports@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org > For the Wine port I'd need to obtain the MAC address of an ethernet > interface, alas it seems that this is not easily possible the way it > is done in Linux/Solaris? > > For Linux, the code in Wine looks as follows: > > strcpy(ifInfo.ifr_name, ifName); > if (ioctl(sock, SIOCGIFHWADDR, &ifInfo) < 0) > { > ERR ("Error obtaining MAC Address!\n"); > close(sock); > return (-1); > } > else > { > /* FIXME: Is it correct to assume size of 6? */ > memcpy(IntInfo->if_physaddr, ifInfo.ifr_hwaddr.sa_data, 6); > IntInfo->if_physaddrlen=6; > } > > For FreeBSD I tried the following program, which doesn't really do what > I want. If I use SIOCSIFPHYADDR, I get errno=22, and SIOCGIFADDR leads > to a crash later on. > > Any hints? (Most probably I'm tried completely stupid things, but > unfortunately, that part of the system is not really documented apart > from the include files, so I had to take a guess&check approach. :-( ) > There's no easy way (that I know of) to get the mac address in FreeBSD. (time for a SIOCGIFLLADDR?) You may look at how ifconfig does it, but I think the following method is a little bit easier: #include #include #include #include #include #include #include main() { struct ifconf ifc; struct ifreq *ifr; struct sockaddr_dl *sdl; char buf[4096], *p; int s; s = socket(AF_INET, SOCK_DGRAM, 0); if (s < 0) err(-1, "socket"); ifc.ifc_len = sizeof buf; ifc.ifc_buf = buf; if (ioctl(s, SIOCGIFCONF, &ifc) < 0) err(-1, "ioctl"); close(s); for (p = buf; p < buf + ifc.ifc_len; ) { ifr = (struct ifreq *)p; if (ifr->ifr_addr.sa_family == AF_LINK) { sdl = (struct sockaddr_dl *)&ifr->ifr_addr; if (sdl->sdl_type == IFT_ETHER) { unsigned char *ea = LLADDR(sdl); printf("%s\t%x:%x:%x:%x:%x:%x\n", ifr->ifr_name, ea[0], ea[1], ea[2], ea[3], ea[4], ea[5]); } } p += _SIZEOF_ADDR_IFREQ(*ifr); } } -lq To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message