TCP/IP Programming Manual

Example
The following programming example calls the gai_strerror routine to print error messages:
error = getaddrinfo(hostname, servicename, &hints, &res);
if(error != 0) {
(void)fprintf(stderr,"myFunction: getaddrinfo returned error
%i ", error);
(void)fprintf(stderr,"%s0", gai_strerror(error));
return -1;
}
Errors
errno is set only on the return of EAI_SYSTEM. See ecode for further information about error
codes.
getaddrinfo
The getaddrinfo function converts hostnames and service names into socket address structures.
(This function is supported for NonStop TCP/IPv6 only.)
NOTE: The C synopsis is given in ANSI C format rather than the pre-ANSI C formats of the other
library routines because the only NonStop servers you can use these routines on all support ANSI
C. (ANSI C format defines the function and the arguments in the same line rather than using an
assign statement and defining the arguments underneath.)
C Synopsis
#include <netdb.h>
int getaddrinfo (const char *hostname, const char *service,
const struct addrinfo *hints, struct addrinfo **result);
TAL Synopsis
?NOLIST, SOURCE SOCKDEFT
?NOLIST, SOURCE SOCKPROC
error := getaddrinfo (hostname, service, hints, result);
INT(32) error;
STRING .EXT hostname;
STRING .EXT service;
INT .EXT hints(addrinfo);
INT .EXT result(addrinfo);
error
return value; it is 0 upon success or a nonzero error code upon failure. The error codes are
described in gai_strerror (page 105).
hostname
input value; specifies a pointer to a character representing one of the following:
An Internet node hostname.
An IPv4 address in dotted-decimal format.
An IPv6 address in hexadecimal format.
NULL if no hostname requires converting; when NULL is used, either service or hints
must be non-NULL.
getaddrinfo 107