gethostbyname problem

David Francois dfrancois at sierrawireless.com
Mon Oct 12 11:41:30 UTC 2009


Hi,

I have some troubles with the gethostbyname function on uclibc-0.9.29.

I have developed a short program which does periodically a gethostbyname.
The problem is if I change the network interface (ETH to WLAN for example) while this short program is running, the gethostbyname function returns a host not found error,  but the network is correctly mounted since I can ping  any URLs or IP address.

When I remount the previous unmounted network interface, the program logs the IP address of the given server.

Here the source  code:

#include <netdb.h>
#include <stdio.h>
#include <stdint.h>
extern int h_errno;


int main(int argn, char* argv[])
{
    struct hostent* host;

    while (1)
    {
        host = gethostbyname(argv[1]);
        if (host)
        {
            printf("Host: %s, addr: %d.%d.%d.%d\n", argv[1], ((uint8_t*)host->h_addr_list[0])[0],
                    ((uint8_t*)host->h_addr_list[0])[1],
                    ((uint8_t*)host->h_addr_list[0])[2],
                    ((uint8_t*)host->h_addr_list[0])[3]);
        }
        else
        {
            printf("lookup error %d: %s\n", h_errno, hstrerror(h_errno));
        }
        fflush(stdout);
        sleep(1);
    }

    return 0;
}


Thanks for your help,

D. FRANCOIS



More information about the uClibc mailing list