TCP/IP Programming Manual

hints.ai_socktype = SOCK_STREAM;
ret = getaddrinfo(hostname, servname, &hints, &res);
if (ret != 0) {
fprintf(stderr, "%s not found in name service database\n",
hostname);
exit(1);
}
for (ainfo = res; ainfo != NULL; ainfo = ainfo->ai_next) {
/* Create the socket. */
s = socket(ainfo->ai_family, ainfo->ai_socktype,
ainfo->ai_protocol);
if (connect(s, ainfo->ai_addr, ainfo->ai_addrlen) == -1) {
perror(argv[0]);
fprintf(stderr, "unable to connect\n");
FILE_CLOSE(S);
continue;
}
else
break;
}
Usage Guidelines
This function is a protocol-independent replacement for lwres_gethostbyname and
lwres_getipnodebyname. lwres_getaddrinfo provides extra functionality because
lwres_getaddrinfo handles both the hostname and the service.
The lwres_getaddrinfo function converts hostnames and service names into socket address
structures. You allocate a hints structure, initialize it to zero (0), fill in the needed fields, and
call this function.
This function returns, through the result pointer, a linked list of addrinfo structures (defined
in netdb.h) that you can use with other socket functions.
The lwres_freeaddrinfo function returns the storage allocated by the
lwres_getaddrinfo function.
lwres_gethostbyaddr
The lwres_gethostbyaddr function gets the name of the host that has the specified Internet
address and address family. (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 = lwres_gethostbyaddr(addr, len, type);
TAL Synopsis
?NOLIST, SOURCE SOCKDEFT
?NOLIST, SOURCE SOCKPROC
host_entry_ptr := lwres_gethostbyaddr(addr, len, type);
INT(32) host_entry_ptr;
STRING .EXT addr;
INT len, type;
144 Library Routines