Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Feb 2007 22:10:09 +0100
From:      nocturnal <>
Subject:   Which file to request SIOCGIFMAC on?
Message-ID:  <>

Next in thread | Raw E-Mail | Index | Archive | Help

I'm trying to get the ethernet address and from the manuals i understand 
that i need the ifreq structure for this. So i'm trying to request 
SIOCGIFMAC with ioctl on a socket of type SOCK_DGRAM.

Now i couldn't figure out from the manuals which format but i've tried 
PF_LOCAL, PF_INET and AF_INET. With PF_LOCAL i get the error "Operation 
not supported" from ioctl but with AF_INET or PF_INET i get "Invalid 

This is a snippet of code that i use to get the ethernet address. 
Earlier code has already verified the char *ifname which contains the 
interface name.

     int if_socket;
     struct ifreq ifr;

     memset(&ifr, 0, sizeof(ifr));
     strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));

     if((if_socket = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
         perror("socket: ");

     if(ioctl(if_socket, SIOCGIFMAC, &ifr) < 0) {
         perror("ioctl: SIOCGIFMAC: ");

I know the rest of the code works fine because this is something i'm 
adding to a working program. Also it's obviously stopping at the ioctl 
since i get the error "ioctl: SIOCGIFMAC: : Invalid argument".

Med vänliga hälsningar

Stefan Midjich aka nocturnal

Want to link to this message? Use this URL: <>