Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!hplabs!hpfcso!hpfcmgw!jeff From: jeff@hpfcmgw.HP.COM (Jeff Taylor) Newsgroups: comp.sys.hp Subject: Re: How to get Ethernet Address Message-ID: <17780030@hpfcmgw.HP.COM> Date: 10 Jun 91 19:07:51 GMT References: <899@bcstec.boeing.com> Organization: HP Fort Collins, CO Lines: 47 > How does one programmaticcaly ascertain the machine address > (the 6 byte code of the communications card) of a connected peer. I think this will help. No promises. Jeff Taylor #include -------------------------------------------------------------------------- /* * Example code to show the use of an ioctl to fetch the ethernet address * of a workstation. The 48 bit address of the local Ethernet/IEEE802 * device is returned in arg.value.s. */ #include #include #include #include static char *hex="0123456789ABCDEF"; main() { int fildes,request; struct fis arg; int i; char addr[15]; fildes=open("/dev/lan", O_RDWR); request = NETSTAT; arg.reqtype = LOCAL_ADDRESS; if (ioctl(fildes,request,&arg)<0) { printf("netstat failed\n"); exit(-1); } /* convert the address into a string of hex characters and print. */ addr[0]='0'; addr[1]='x'; for (i=0; i<6; i++) { addr[i*2+2] = hex[arg.value.s[i] >> 4]; /* high nibble of i'th byte */ addr[i*2+3] = hex[arg.value.s[i] & 0x0f]; /* low nibble of i'th byte */ } addr[14]='\000'; printf("ethernet address is %s\n",addr); }