SIOCFIGGLAGS: Why does it not report right?

David Walker dave at mudsite.com
Mon Apr 10 17:15:40 UTC 2006


I am having a problem, (and have scoured over google) but was not able 
to find something that, either gave me a good enough answer, or I am 
just stupid.

Ok so the problem I am having is with DHCPv6c.  I am trying to get the 
DHCP client for ipv6 to work. (dhcpv6.sf.net)  Granted this program is 
not Ubuntu specific but in a test case I wrote I found the same problem.

So I start my machine w/o network cable connected.  Dhclient fails to 
get an address and so on.

Below is code, that should get the devices on the system (to the best of 
my knowledge), and what is happening is that ETH0 is not detected as a 
device.  The loop in get_devices only find 'lo'.  However, the following 
code DOES detect eth0 when I reconnect the cable, run dhclient and get 
the address.  I am also able to stop dhclient and release my ipv4 
address, and still detect eth0 with the code below.

int get_devices ()
{
    int num_devices;
    struct ifconf ifc;
    struct ifreq *ifr;
   
    sock = socket(AF_INET, SOCK_DGRAM, 0);

    if (ioctl(sock, SIOCGIFCONF, &ifc) < 0)
    {
        //Bork bork bork
        exit(1);
    }

    ifr = ifc.ifc_req;

    for (i = ifc.ifc_len / sizeof(struct ifreq);
        --i >=0 && num_device < MAX_DEVICE;
        ifr++)
    {
        if(!strcmp(ifr->ifr_name, "lo"))
           continue; //We dont care about loopback

        // Process other devices ... eg eth0
        ...
        num_device++;
    }

    return num_device;
}


Any help or ideas?

--
Dave




More information about the ubuntu-users mailing list