`getaddrinfo(3)` provides network address and service translation.
From the man page:
Name
getaddrinfo
, freeaddrinfo
, gai_strerror
- network address and service translation
Synopsis
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
int getaddrinfo(const char *node, const char *service,
const struct addrinfo *hints,
struct addrinfo **res);
void freeaddrinfo(struct addrinfo *res);
const char *gai_strerror(int errcode);
Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
getaddrinfo(), freeaddrinfo(), gai_strerror():
_POSIX_C_SOURCE >= 1 || _XOPEN_SOURCE || _POSIX_SOURCE
Description
Given node and service, which identify an Internet host and a service, getaddrinfo()
returns one or more addrinfo
structures, each of which contains an Internet address that can be specified in a call to bind(2)
or connect(2)
. The getaddrinfo()
function combines the functionality provided by the getservbyname(3)
and getservbyport(3)
functions into a single interface, but unlike the latter functions, getaddrinfo()
is reentrant and allows programs to eliminate IPv4-versus-IPv6 dependencies.