Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Feb 2007 22:10:09 +0100
From:      nocturnal <nocturnal@swehack.se>
To:        freebsd-questions@freebsd.org
Subject:   Which file to request SIOCGIFMAC on?
Message-ID:  <45DB63B1.7050004@swehack.se>

next in thread | raw e-mail | index | archive | help
Hi

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 
argument".

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: ");
         exit(-1);
     }

     if(ioctl(if_socket, SIOCGIFMAC, &ifr) < 0) {
         perror("ioctl: SIOCGIFMAC: ");
         exit(-1);
     }
[..]

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
[Swehack] http://swehack.se



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?45DB63B1.7050004>