From owner-freebsd-ports Mon Nov 6 4:15:17 2000 Delivered-To: freebsd-ports@freebsd.org Received: from vexpert.dbai.tuwien.ac.at (vexpert.dbai.tuwien.ac.at [128.130.111.12]) by hub.freebsd.org (Postfix) with ESMTP id 668AE37B479; Mon, 6 Nov 2000 04:15:07 -0800 (PST) Received: from [128.130.111.77] (taygeta [128.130.111.77]) by vexpert.dbai.tuwien.ac.at (8.9.3/8.9.3) with ESMTP id NAA16527; Mon, 6 Nov 2000 13:14:55 +0100 (MET) Date: Mon, 6 Nov 2000 13:14:56 +0100 (CET) From: Gerald Pfeifer To: , Subject: Wine port: How to obtain MAC address? Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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. :-( ) -------- cut -------- #include #include #include #include #include #include main() { struct ifreq ifInfo; int sock; int status; if ( (sock = socket (AF_INET, SOCK_DGRAM, 0)) < 0 ) { printf("Error creating socket!\n"); return -1; } memset(&ifInfo,0,sizeof ifInfo); strcpy(ifInfo.ifr_name,"fxp0"); if ( (status = ioctl(sock,/*SIOCSIFPHYADDR*/SIOCGIFADDR,&ifInfo)) < 0) { printf("Error %d obtaining MAC Address!\n",errno); close(sock); return -1; } else { char *p=ifInfo.ifr_data; unsigned u; printf("Pointer=%ld\nMAC Address=",(long int)p); fflush(stdout); for(u=0; u < 6; u++) printf("%d:",(int)*p); } } -------- cut -------- Gerald -- Gerald "Jerry" pfeifer@dbai.tuwien.ac.at http://www.dbai.tuwien.ac.at/~pfeifer/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-ports" in the body of the message