Which file to request SIOCGIFMAC on?
nocturnal
nocturnal at swehack.se
Tue Feb 20 21:09:52 UTC 2007
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
More information about the freebsd-questions
mailing list