SIOCGIFADDR bug?

Zachary Roger Amsden (amsden+@andrew.cmu.edu)
Mon, 17 Jun 1996 12:40:19 -0400 (EDT)


The ioctl call SIOCGIFADDR, when used to get the internet addresss of an
interface, behaves erradically. Specifically, it works perfectly fine
in a normal program such as ifconfig. In inetd server programs (ftp-gw,
a proxy for the TIS firewall toolkit), it returns an invalid address,
and not the same address as is returned outside of this program. This
happens on kernels 1.3.100 and 2.0. I have not yet found a kernel that
it works on.

Here is the code I am using:
(non-important stuff truncated)

int skfd = -1;
struct ifreq ifr;
struct sockaddr_in addr;

if ((skfd = socket(AF_INET, SOCK_DGRAM,0)) < 0) {
syslog(LLEV, "fwtksyserr: socket failed: %s", sys_errlist[errno]);
return(0);
}
memset(&ifr, 0, sizeof(struct ifreq));
strcpy(ifr.ifr_name, ifname);
if (ioctl(skfd, SIOCGIFADDR, &ifr) < 0)
return(0);
memcpy(&addr, &(ifr.ifr_addr), sizeof(struct sockaddr_in));
close(skfd);

now, addr.sin_addr.s_addr should be the encoded ethernet address,
but it is not the same value when called outside of this program.
The kernel code for the glue layer in the net stuff looks fine, so if
there is a bug here, it is probably somewhere in the ip code.

Zachary Amsden
PLEASE E-MAIL THIS ADDRESS
amsdenz@aavid.com