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