TCP/IP Programming Manual

struct sockaddr_in sin;
struct hostent *hp;
...
if ((hp = gethostbyname (nameptr)) != (struct hostent *)
NULL) {
memmove ((char *)&sin.sin_addr.s_addr,
(char *)hp -> h_addr,
(size_t) hp -> h_length );
} ...
If the return value is not NULL, the pointer hp is used to move the address from the h_addr field
of the hp structure to the Internet address field of the sin structure.
gethostbyname2
The gethostbyname2 function gets the Internet address (IPv4 or IPv6) of the host whose name
is specified. gethostbyname2 works like gethostbyname but also allows specifying the address
family to which the returned Internet address must belong. (This function is supported for G06.27
and later G-series RVUs and H06.05 and later H-series RVUs of NonStop TCP/IPv6.)
C Synopsis
#include <netdb.h>
host_entry_ptr = gethostbyname2(name, af);
TAL Synopsis
?NOLIST, SOURCE SOCKDEFT
?NOLIST, SOURCE SOCKPROC
host_entry_ptr := gethostbyname2(name, af);
INT(32) host_entry_ptr;
STRING .EXT name;
INT af;
host_entry_ptr
return value; points to a structure (based on the hostent structure) in which information on
the specified host is returned. The information includes the official name, aliases, and addresses
for the host. If the lookup fails, NULL is returned.
name
input value; points to either the official name or an alias of the host whose Internet address is
to be found.
af
input value; an integer that sets the address type searched for by the function and returned by
the function. af is either AF_INET (IPv4) or AF_INET6 (IPv6).
Errors
gethostbyname2 returns NULL to indicate an error. In this case, the global variable h_errno
contains one of these error codes (as defined in netdb.h):
HOST_NOT_FOUND
The specified host was not found. This is the only possible value if the resolver code has been
disabled.
TRY_AGAIN
The local server did not receive a response from an authoritative server. Try again later.
112 Library Routines