1GETADDRINFO(3)             Linux Programmer's Manual            GETADDRINFO(3)
2
3
4

NAME

6       getaddrinfo,  freeaddrinfo,  gai_strerror - network address and service
7       translation
8

SYNOPSIS

10       #include <sys/types.h>
11       #include <sys/socket.h>
12       #include <netdb.h>
13
14       int getaddrinfo(const char *restrict node,
15                       const char *restrict service,
16                       const struct addrinfo *restrict hints,
17                       struct addrinfo **restrict res);
18
19       void freeaddrinfo(struct addrinfo *res);
20
21       const char *gai_strerror(int errcode);
22
23   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
24
25       getaddrinfo(), freeaddrinfo(), gai_strerror():
26           Since glibc 2.22:
27               _POSIX_C_SOURCE >= 200112L
28           Glibc 2.21 and earlier:
29               _POSIX_C_SOURCE
30

DESCRIPTION

32       Given node and service, which identify an Internet host and a  service,
33       getaddrinfo()  returns  one  or more addrinfo structures, each of which
34       contains an Internet address that can be specified in a call to bind(2)
35       or  connect(2).   The getaddrinfo() function combines the functionality
36       provided by the gethostbyname(3) and getservbyname(3) functions into  a
37       single  interface,  but  unlike  the latter functions, getaddrinfo() is
38       reentrant and allows programs to eliminate  IPv4-versus-IPv6  dependen‐
39       cies.
40
41       The  addrinfo  structure  used  by getaddrinfo() contains the following
42       fields:
43
44           struct addrinfo {
45               int              ai_flags;
46               int              ai_family;
47               int              ai_socktype;
48               int              ai_protocol;
49               socklen_t        ai_addrlen;
50               struct sockaddr *ai_addr;
51               char            *ai_canonname;
52               struct addrinfo *ai_next;
53           };
54
55       The hints argument points to an addrinfo structure that specifies  cri‐
56       teria  for selecting the socket address structures returned in the list
57       pointed to by res.  If hints is not  NULL  it  points  to  an  addrinfo
58       structure  whose ai_family, ai_socktype, and ai_protocol specify crite‐
59       ria that limit the set of socket addresses returned  by  getaddrinfo(),
60       as follows:
61
62       ai_family
63              This field specifies the desired address family for the returned
64              addresses.  Valid values for  this  field  include  AF_INET  and
65              AF_INET6.   The  value  AF_UNSPEC  indicates  that getaddrinfo()
66              should return socket addresses for any  address  family  (either
67              IPv4  or  IPv6, for example) that can be used with node and ser‐
68              vice.
69
70       ai_socktype
71              This field specifies the  preferred  socket  type,  for  example
72              SOCK_STREAM or SOCK_DGRAM.  Specifying 0 in this field indicates
73              that socket addresses of any type  can  be  returned  by  getad‐
74              drinfo().
75
76       ai_protocol