Is gethostbyname guaranteed to return hostent structures with IPv4 addresses?

Posted by Robert on Stack Overflow See other posts from Stack Overflow or by Robert
Published on 2010-05-06T18:45:30Z Indexed on 2010/05/06 18:48 UTC
Read the original article Hit count: 284

Filed under:
|
|
|

I cannot use getaddrinfo(...) for resolving hostnames and therefore must stick to gethostbyname(...)

Is the gethostbyname(...) function guaranteed to return hostent structures that contain only IPv4 (AF_INET) addresses on success, so that the following code would always lead to an IPv4 address:

int resolve(const char *name, struct in_addr *addr) {

    struct hostent *he = gethostbyname(name);

    if (!he)
        return 1;

    memcpy(addr,he->h_addr_list[0],4);

    return 0;
}

© Stack Overflow or respective owner

Related posts about c

    Related posts about gethostbyname