lkml.org 
[lkml]   [1996]   [Jun]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectSIOCGIFADDR bug?

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


\
 
 \ /
  Last update: 2005-03-22 13:37    [W:0.058 / U:8.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site