Re: ioctl SIOCGIFADDR bug

Bernd Eckenfels (ecki@lina.inka.de)
Fri, 06 Aug 1999 03:09:42 +0200


In article <199908052031.QAA29714@smtp3.mindspring.com> you wrote:
> struct ifreq ifr;
> inet_sock = socket(AF_INET, SOCK_DGRAM, 0);
> strcpy(ifr.ifr_name, "eth0");
> if (ioctl(inet_sock, SIOCGIFADDR, &ifr) < 0)
> perror("zzz: ioctl");

You need to set the address family before you read smething.

Thats why ifconfig does not suffer from it:
strcpy(ifr.ifr_name, ifname);
ifr.ifr_addr.sa_family = AF_INET;
if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) {

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/