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