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 *node, const char *service,
15                       const struct addrinfo *hints,
16                       struct addrinfo **res);
17
18       void freeaddrinfo(struct addrinfo *res);
19
20       const char *gai_strerror(int errcode);
21
22   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
23
24       getaddrinfo(), freeaddrinfo(), gai_strerror():
25           Since glibc 2.22: _POSIX_C_SOURCE >= 200112L
26           Glibc 2.21 and earlier: _POSIX_C_SOURCE
27

DESCRIPTION

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