netdev
[Top] [All Lists]

C and/or ioctl question

To: netdev@xxxxxxxxxxx
Subject: C and/or ioctl question
From: Stephen Waters <swaters@xxxxxxxxxx>
Date: 08 Aug 2001 11:45:38 -0500
Sender: owner-netdev@xxxxxxxxxxx
hi, I've been studying the net-tools ifconfig implementation a bit in my
efforts to better learn C and ioctl for Linux.

I've noticed that the following snippet of code compiles and runs just
fine with gcc-2.95.4 but gcc-3.0.1 compile returns error.

CFLAGS: -Wall -g

Error message in question: SIOCGIFCONF: Bad address

Code Snippet:
#include <stdio.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>

int main () {
   struct ifconf ifc;
   int skfd;
   skfd = socket(AF_INET, SOCK_DGRAM, 0);
   if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) {
      perror("SIOCGIFCONF");
      close(skfd);
      return -1;
   }
   close(skfd);
   return 0;
}


Thanks for any help!
-s


<Prev in Thread] Current Thread [Next in Thread>