Date: Mon, 6 Nov 2000 13:14:56 +0100 (CET) From: Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at> To: <ports@freebsd.org>, <emulation@freebsd.org> Subject: Wine port: How to obtain MAC address? Message-ID: <Pine.BSF.4.30.0011061305430.64453-100000@taygeta.dbai.tuwien.ac.at>
next in thread | raw e-mail | index | archive | help
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 <stdio.h> #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <net/if.h> #include <errno.h> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.30.0011061305430.64453-100000>