1netdb.h(0P) POSIX Programmer's Manual netdb.h(0P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 netdb.h — definitions for network database operations
13
15 #include <netdb.h>
16
18 The <netdb.h> header may define the in_port_t type and the in_addr_t
19 type as described in <netinet/in.h>.
20
21 The <netdb.h> header shall define the hostent structure, which shall
22 include at least the following members:
23
24
25 char *h_name Official name of the host.
26 char **h_aliases A pointer to an array of pointers to
27 alternative host names, terminated by a
28 null pointer.
29 int h_addrtype Address type.
30 int h_length The length, in bytes, of the address.
31 char **h_addr_list A pointer to an array of pointers to network
32 addresses (in network byte order) for the host,
33 terminated by a null pointer.
34
35 The <netdb.h> header shall define the netent structure, which shall
36 include at least the following members:
37
38
39 char *n_name Official, fully-qualified (including the
40 domain) name of the host.
41 char **n_aliases A pointer to an array of pointers to
42 alternative network names, terminated by a
43 null pointer.
44 int n_addrtype The address type of the network.
45 uint32_t n_net The network number, in host byte order.
46
47 The <netdb.h> header shall define the uint32_t type as described in
48 <inttypes.h>.
49
50 The <netdb.h> header shall define the protoent structure, which shall
51 include at least the following members:
52
53
54 char *p_name Official name of the protocol.
55 char **p_aliases A pointer to an array of pointers to
56 alternative protocol names, terminated by
57 a null pointer.
58 int p_proto The protocol number.
59
60 The <netdb.h> header shall define the servent structure, which shall
61 include at least the following members:
62
63
64 char *s_name Official name of the service.
65 char **s_aliases A pointer to an array of pointers to
66 alternative service names, terminated by
67 a null pointer.
68 int s_port A value which, when converted to uint16_t,
69 yields the port number in network byte order
70 at which the service resides.
71 char *s_proto The name of the protocol to use when
72 contacting the service.
73
74 The <netdb.h> header shall define the IPPORT_RESERVED symbolic constant
75 with the value of the highest reserved Internet port number.
76
77 Address Information Structure
78 The <netdb.h> header shall define the addrinfo structure, which shall
79 include at least the following members:
80
81
82 int ai_flags Input flags.
83 int ai_family Address family of socket.
84 int ai_socktype Socket type.
85 int ai_protocol Protocol of socket.
86 socklen_t ai_addrlen Length of socket address.
87 struct sockaddr *ai_addr Socket address of socket.
88 char *ai_canonname Canonical name of service location.
89 struct addrinfo *ai_next Pointer to next in list.
90
91 The <netdb.h> header shall define the following symbolic constants that
92 evaluate to bitwise-distinct integer constants for use in the flags
93 field of the addrinfo structure:
94
95 AI_PASSIVE Socket address is intended for bind().
96
97 AI_CANONNAME Request for canonical name.
98
99 AI_NUMERICHOST
100 Return numeric host address as name.
101
102 AI_NUMERICSERV
103 Inhibit service name resolution.
104
105 AI_V4MAPPED If no IPv6 addresses are found, query for IPv4 addresses
106 and return them to the caller as IPv4-mapped IPv6
107 addresses.
108
109 AI_ALL Query for both IPv4 and IPv6 addresses.
110
111 AI_ADDRCONFIG Query for IPv4 addresses only when an IPv4 address is
112 configured; query for IPv6 addresses only when an IPv6
113 address is configured.
114
115 The <netdb.h> header shall define the following symbolic constants that
116 evaluate to bitwise-distinct integer constants for use in the flags
117 argument to getnameinfo():
118
119 NI_NOFQDN Only the nodename portion of the FQDN is returned for
120 local hosts.
121
122 NI_NUMERICHOST
123 The numeric form of the node's address is returned
124 instead of its name.
125
126 NI_NAMEREQD Return an error if the node's name cannot be located in
127 the database.
128
129 NI_NUMERICSERV
130 The numeric form of the service address is returned
131 instead of its name.
132
133 NI_NUMERICSCOPE
134 For IPv6 addresses, the numeric form of the scope identi‐
135 fier is returned instead of its name.
136
137 NI_DGRAM Indicates that the service is a datagram service
138 (SOCK_DGRAM).
139
140 Address Information Errors
141 The <netdb.h> header shall define the following symbolic constants for
142 use as error values for getaddrinfo() and getnameinfo(). The values
143 shall be suitable for use in #if preprocessing directives.
144
145 EAI_AGAIN The name could not be resolved at this time. Future
146 attempts may succeed.
147
148 EAI_BADFLAGS The flags had an invalid value.
149
150 EAI_FAIL A non-recoverable error occurred.
151
152 EAI_FAMILY The address family was not recognized or the address
153 length was invalid for the specified family.
154
155 EAI_MEMORY There was a memory allocation failure.
156
157 EAI_NONAME The name does not resolve for the supplied parameters.
158
159 NI_NAMEREQD is set and the host's name cannot be located,
160 or both nodename and servname were null.
161
162 EAI_SERVICE The service passed was not recognized for the specified
163 socket type.
164
165 EAI_SOCKTYPE The intended socket type was not recognized.
166
167 EAI_SYSTEM A system error occurred. The error code can be found in
168 errno.
169
170 EAI_OVERFLOW An argument buffer overflowed.
171
172 The following shall be declared as functions and may also be defined as
173 macros. Function prototypes shall be provided.
174
175
176 void endhostent(void);
177 void endnetent(void);
178 void endprotoent(void);
179 void endservent(void);
180 void freeaddrinfo(struct addrinfo *);
181 const char *gai_strerror(int);
182 int getaddrinfo(const char *restrict, const char *restrict,
183 const struct addrinfo *restrict,
184 struct addrinfo **restrict);
185 struct hostent *gethostent(void);
186 int getnameinfo(const struct sockaddr *restrict, socklen_t,
187 char *restrict, socklen_t, char *restrict,
188 socklen_t, int);
189 struct netent *getnetbyaddr(uint32_t, int);
190 struct netent *getnetbyname(const char *);
191 struct netent *getnetent(void);
192 struct protoent *getprotobyname(const char *);
193 struct protoent *getprotobynumber(int);
194 struct protoent *getprotoent(void);
195 struct servent *getservbyname(const char *, const char *);
196 struct servent *getservbyport(int, const char *);
197 struct servent *getservent(void);
198 void sethostent(int);
199 void setnetent(int);
200 void setprotoent(int);
201 void setservent(int);
202
203 The <netdb.h> header shall define the socklen_t type through typedef,
204 as described in <sys/socket.h>.
205
206 Inclusion of the <netdb.h> header may also make visible all symbols
207 from <netinet/in.h>, <sys/socket.h>, and <inttypes.h>.
208
209 The following sections are informative.
210
212 None.
213
215 None.
216
218 None.
219
221 <inttypes.h>, <netinet_in.h>, <sys_socket.h>
222
223 The System Interfaces volume of POSIX.1‐2017, bind(), endhostent(),
224 endnetent(), endprotoent(), endservent(), freeaddrinfo(), gai_str‐
225 error(), getnameinfo()
226
228 Portions of this text are reprinted and reproduced in electronic form
229 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
230 table Operating System Interface (POSIX), The Open Group Base Specifi‐
231 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
232 Electrical and Electronics Engineers, Inc and The Open Group. In the
233 event of any discrepancy between this version and the original IEEE and
234 The Open Group Standard, the original IEEE and The Open Group Standard
235 is the referee document. The original Standard can be obtained online
236 at http://www.opengroup.org/unix/online.html .
237
238 Any typographical or formatting errors that appear in this page are
239 most likely to have been introduced during the conversion of the source
240 files to man page format. To report such errors, see https://www.ker‐
241 nel.org/doc/man-pages/reporting_bugs.html .
242
243
244
245IEEE/The Open Group 2017 netdb.h(0P)