TCP/IP Programming Manual

functionality beyond what getipnodebyname provides because getaddrinfo handles both
the hostname and the service.
Appropriate use of this function can eliminate calls to getservbyname and at the same time
provide protocol independence.
getaddrinfo function converts hostnames and service names into socket address structures.
You allocate a hints structure, initialize it to 0 (zero), fill in the needed fields, and then call
this function.
This function returns through the result pointer a linked list of addrinfo structs that you
can use with other socket functions. For a description of the addrinfo struct, see addrinfo
(page 64). Each addrinfo struct contains the following members:
A TCP or UDP client typically specifies non-NULL values for both the hostname and service
parameters. A TCP client loops through all the returned socket address structures, calling the
socket and connect functions for each address until a connection succeeds. A UDP client
calls connect or the sendto function.
A TCP or UDP server typically specifies a non-NULL value for service but not hostname. It also
specifies the AI_PASSIVE flag in the hints struct. The returned socket address structs should
contain the IP address INADDR_ANY or in6addr_any. A TCP server then calls the socket,
bind, and listen functions. A UDP server calls the socket, bind, and the recvfrom
functions.
If the client or server handles only one type of socket, set hints.ai_socktype to
SOCK_STREAM or SOCK_DGRAM to avoid having multiple addrinfo structs returned.
Upon successful completion, this function returns 0 (zero), and result points to a new address
information structure. Otherwise, getaddrinfo returns the error codes described in ecode
.
The freeaddrinfo (page 104) function returns the storage allocated by the getaddrinfo
function.
Ensure that the protocol file ($SYSTEM.ZTCPIP.PROTOCOL on the Guardian side or
/etc/protocols on the OSS side) exists. This helps to avoid the following error:
ENOENT(4002): No such file or directory.
gethostbyaddr, host_file_gethostbyaddr
The gethostbyaddr and host_file_gethostbyaddr functions get the name of the host with
the specified Internet address. These functions are for INET addresses only; for protocol-independent
applications, see getnameinfo (page 117) or getipnodebyaddr (page 114). Although these two
functions provide the same service, they accomplish the service in different ways. To determine
which function best suits your purpose, see the Usage Guidelines (page 110).
C Synopsis
#include <socket.h>
#include <netdb.h>
host_entry_ptr = gethostbyaddr (host_addr_ptr, length,
addr_type);
host_entry_ptr = host_file_gethostbyaddr (host_addr_ptr,
length, addr_type);
struct hostent *host_entry_ptr;
char *host_addr_ptr;
int length, addr_type;
TAL Synopsis
gethostbyaddr, host_file_gethostbyaddr 109