Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 06 Nov 2000 12:31:49 -0500
From:      Marcel Moolenaar <marcel@cup.hp.com>
To:        Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>
Cc:        emulation@FreeBSD.ORG
Subject:   Re: Wine port: How to obtain MAC address?
Message-ID:  <3A06EB05.F908822@cup.hp.com>
References:  <Pine.BSF.4.30.0011061305430.64453-100000@taygeta.dbai.tuwien.ac.at>

next in thread | previous in thread | raw e-mail | index | archive | help
Gerald Pfeifer wrote:
> 
> 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;
>     }

See /sys/compat/linux/linux_ioctl.c:1370

case LINUX_SIOCGIFHWADDR: {
	int ifn;
	struct ifnet *ifp;
	struct ifaddr *ifa;
	struct sockaddr_dl *sdl;
	struct linux_ifreq *ifr = (struct linux_ifreq *)args->arg;

	/* Note that we don't actually respect the name in the ifreq
	 * structure, as Linux interface names are all different.
	 */
	for (ifn = 0; ifn < if_index; ifn++) {
		ifp = ifnet_addrs[ifn]->ifa_ifp;
		if (ifp->if_type == IFT_ETHER) {
			ifa = TAILQ_FIRST(&ifp->if_addrhead);
			while (ifa) {
				sdl=(struct sockaddr_dl*)ifa->ifa_addr;
				if (sdl != NULL &&
				    (sdl->sdl_family == AF_LINK) &&
				    (sdl->sdl_type == IFT_ETHER)) {
					return (copyout(LLADDR(sdl),
					    &ifr->ifr_hwaddr.sa_data,
					    LINUX_IFHWADDRLEN));
				}
				ifa = TAILQ_NEXT(ifa, ifa_link);
			}
		}
	}
	return (ENOENT);
}

This gives you a kernel-space datapoint. With that, you should be able
to mimic what ifconfig (as Will suggested) does.

HTH,

-- 
Marcel Moolenaar
  mail: marcel@cup.hp.com / marcel@FreeBSD.org
  tel:  (408) 447-4222


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-emulation" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3A06EB05.F908822>