From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,a684a3049b399a41 X-Google-Attributes: gidfee84,public From: John Kohl Subject: Re: Getting Ethernet (MAC) address on DU 4.0 Date: 1998/09/08 Message-ID: <6chfyi908e.fsf@rational.com>#1/1 X-Deja-AN: 389037895 X-Us-Snail: Rational Software Corp., 20 Maguire Road, Lexington, MA 02173-3104 Sender: jtk@dextrose References: <35F3AE4E.413E4BF3@nospam.sebb.bel.alcatel.be> Organization: Rational Software Corporation Newsgroups: comp.unix.osf.osf1 Niel Markwick writes: >So, is there another way to get the MAC address (I suspect not). >Alternatively, is there a way to get the names of the network interfaces >on a system, so that I can then use these with the SIOCRPHYSADDR ioctl >to get the addresses. Yes, you can use SIOCGIFCONF. Here's a code snippet: struct ifreq *ifrq, ifreqs[32]; struct ifdevea eaddr; struct ifconf ifc; s = socket(AF_INET, SOCK_STREAM, 0); if (s == -1) /* XXX what? */ ; ifc.ifc_req = ifreqs; ifc.ifc_len = sizeof(ifreqs); if (ioctl(s, SIOCGIFCONF, &ifc) == -1) /* XXX what? */; for (ifrq = ifreqs; ifc.ifc_len > 0; ifrq++, ifc.ifc_len -= sizeof(*ifrq)) { /* for each known interface, try to get a physaddr. */ strncpy(eaddr.ifr_name, ifrq->ifr_name, IFNAMSIZ); if (ioctl(s, SIOCRPHYSADDR, &eaddr) == 0) { .... break; } }