Is gethostbyname guaranteed to return hostent structures with IPv4 addresses?
- by Robert
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;
}