Hi all:
Here is C code that I am written
to enumerate the available interfaces.
The development environment is
32-bit uniprocessor OpenSuSe 10.2 Linux kernel 2.6.18.2-34
(not on *BSD or any other UNIX)
int main(int argc, char *argv[])
{
const int MAX_IFS = 16;
char buf[sizeof(struct ifreq) * MAX_IFS];
int sfd;
struct ifconf ifc;
unsigned int nif = 0;
sfd = socket(PF_INET, SOCK_STREAM, 0);
perror("SOCKET");
printf("socket fd: %d\n", sfd);
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
ioctl(sfd, SIOCGIFCONF, (char*)&ifc);
perror("SIOCGIFCONF");
printf("number of interfaces : %d\n", nif);
return 0;
}
On running the program,
"SIOCGIFCONF: Illegal seek" is the error message.
To investigate the issue in depth, I ran 'strace'
and here is the output.
1 execve("./a.out", ["./a.out"], [/* 83 vars */]) = 0
2 brk(0) = 0x804b000
3 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0xb7fb4000
4 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or
directory)
5 open("/etc/ld.so.cache", O_RDONLY) = 3
6 fstat64(3, {st_mode=S_IFREG|0644, st_size=156713, ...}) = 0
7 mmap2(NULL, 156713, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7f8d000
8 close(3) = 0
9 open("/lib/libc.so.6", O_RDONLY) = 3
10 read(3, "\177ELF\1\1\1\0\0\0\0\0\0\0\0\0\3\0\3\0\1\0\0\0\340`\1"..., 512)
= 512
11 fstat64(3, {st_mode=S_IFREG|0755, st_size=1491141, ...}) = 0
12 mmap2(NULL, 1234372, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0)
= 0xb7e5f000
13 fadvise64(3, 0, 1234372, POSIX_FADV_WILLNEED) = 0
14 mmap2(0xb7f87000, 12288, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x128) = 0xb7f87000
15 mmap2(0xb7f8a000, 9668, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0xb7f8a000
16 close(3) = 0
17 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0xb7e5e000
18 set_thread_area({entry_number:-1 -> 6, base_addr:0xb7e5e6c0,
limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, li
mit_in_pages:1, seg_not_present:0, useable:1}) = 0
19 mprotect(0xb7f87000, 4096, PROT_READ) = 0
20 mprotect(0x8049000, 4096, PROT_READ) = 0
21 munmap(0xb7f8d000, 156713) = 0
22 socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
23 dup(2) = 4
24 fcntl64(4, F_GETFL) = 0x8001 (flags
O_WRONLY|O_LARGEFILE)
25 close(4) = 0
26 write(2, "SOCKET: Success\n", 16SOCKET: Success
27 ) = 16
28 fstat64(1, {st_mode=S_IFREG|0644, st_size=1733, ...}) = 0
29 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0)
= 0xb7fb3000
30 ioctl(3, SIOCGIFCONF, {96, {{"lo", {AF_INET, inet_addr("127.0.0.1")}},
{"wlan0", {AF_INET, inet_addr("192.168.1.253")}}, {"eth0", {AF_INET,
inet_addr("192.168.1.254")}}}}) = 0
31 write(2, "SIOCGIFCONF: Invalid argument\n", 30SIOCGIFCONF: Invalid
argument
32 ) = 30
33 write(1, "socket fd: 3\nnumber of interface"..., 38socket fd: 3
NOTE:
. Entry 30 ie. ioctl() shows that the SIOCGIFCONF command was processed
and three interface entries were seen.
. running the program as root or under 'sudo' gives the same error.
Anybody has an idea what I could be missing ?
thanks
Saifi.