Commit | Line | Data |
---|---|---|
40ff484d | 1 | /* Provide a netdb.h header file for systems lacking it (read: MinGW). |
f0007cad | 2 | Copyright (C) 2008-2012 Free Software Foundation, Inc. |
40ff484d LC |
3 | Written by Simon Josefsson. |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU Lesser General Public License as published by | |
7 | the Free Software Foundation; either version 2, or (at your option) | |
8 | any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public License | |
16 | along with this program; if not, write to the Free Software Foundation, | |
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | |
18 | ||
19 | /* This file is supposed to be used on platforms that lack <netdb.h>. | |
20 | It is intended to provide definitions and prototypes needed by an | |
21 | application. */ | |
22 | ||
3d458a81 | 23 | #ifndef _@GUARD_PREFIX@_NETDB_H |
40ff484d | 24 | |
a927b6c1 | 25 | #if __GNUC__ >= 3 |
40ff484d | 26 | @PRAGMA_SYSTEM_HEADER@ |
a927b6c1 | 27 | #endif |
0f00f2c3 | 28 | @PRAGMA_COLUMNS@ |
a927b6c1 LC |
29 | |
30 | #if @HAVE_NETDB_H@ | |
40ff484d LC |
31 | |
32 | /* The include_next requires a split double-inclusion guard. */ | |
33 | # @INCLUDE_NEXT@ @NEXT_NETDB_H@ | |
34 | ||
35 | #endif | |
36 | ||
3d458a81 AW |
37 | #ifndef _@GUARD_PREFIX@_NETDB_H |
38 | #define _@GUARD_PREFIX@_NETDB_H | |
40ff484d | 39 | |
dd7d0148 LC |
40 | /* Get <netdb.h> definitions such as 'socklen_t' on IRIX 6.5 and OSF/1 4.0 and |
41 | 'struct hostent' on MinGW. */ | |
40ff484d LC |
42 | #include <sys/socket.h> |
43 | ||
3d458a81 AW |
44 | /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ |
45 | ||
40ff484d LC |
46 | /* The definition of _GL_ARG_NONNULL is copied here. */ |
47 | ||
a927b6c1 LC |
48 | /* The definition of _GL_WARN_ON_USE is copied here. */ |
49 | ||
40ff484d LC |
50 | /* Declarations for a platform that lacks <netdb.h>, or where it is |
51 | incomplete. */ | |
52 | ||
53 | #if @GNULIB_GETADDRINFO@ | |
54 | ||
55 | # if !@HAVE_STRUCT_ADDRINFO@ | |
56 | ||
3d458a81 AW |
57 | # ifdef __cplusplus |
58 | extern "C" { | |
59 | # endif | |
60 | ||
49114fd4 | 61 | # if !GNULIB_defined_struct_addrinfo |
40ff484d LC |
62 | /* Structure to contain information about address of a service provider. */ |
63 | struct addrinfo | |
64 | { | |
65 | int ai_flags; /* Input flags. */ | |
66 | int ai_family; /* Protocol family for socket. */ | |
67 | int ai_socktype; /* Socket type. */ | |
68 | int ai_protocol; /* Protocol for socket. */ | |
69 | socklen_t ai_addrlen; /* Length of socket address. */ | |
70 | struct sockaddr *ai_addr; /* Socket address for socket. */ | |
71 | char *ai_canonname; /* Canonical name for service location. */ | |
72 | struct addrinfo *ai_next; /* Pointer to next in list. */ | |
73 | }; | |
49114fd4 LC |
74 | # define GNULIB_defined_struct_addrinfo 1 |
75 | # endif | |
3d458a81 AW |
76 | |
77 | # ifdef __cplusplus | |
78 | } | |
79 | # endif | |
80 | ||
40ff484d LC |
81 | # endif |
82 | ||
f0007cad | 83 | /* Possible values for 'ai_flags' field in 'addrinfo' structure. */ |
40ff484d | 84 | # ifndef AI_PASSIVE |
f0007cad | 85 | # define AI_PASSIVE 0x0001 /* Socket address is intended for 'bind'. */ |
40ff484d LC |
86 | # endif |
87 | # ifndef AI_CANONNAME | |
88 | # define AI_CANONNAME 0x0002 /* Request for canonical name. */ | |
89 | # endif | |
90 | # ifndef AI_NUMERICSERV | |
91 | # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */ | |
92 | # endif | |
93 | ||
94 | # if 0 | |
40ff484d | 95 | # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */ |
dde9c5a4 LC |
96 | # endif |
97 | ||
98 | /* These symbolic constants are required to be present by POSIX, but | |
99 | our getaddrinfo replacement doesn't use them (yet). Setting them | |
100 | to 0 on systems that doesn't have them avoids causing problems for | |
101 | system getaddrinfo implementations that would be confused by | |
102 | unknown values. */ | |
103 | # ifndef AI_V4MAPPED | |
104 | # define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */ | |
105 | # endif | |
106 | # ifndef AI_ALL | |
107 | # define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */ | |
108 | # endif | |
109 | # ifndef AI_ADDRCONFIG | |
110 | # define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose | |
111 | returned address type. */ | |
112 | # endif | |
40ff484d | 113 | |
f0007cad | 114 | /* Error values for 'getaddrinfo' function. */ |
40ff484d | 115 | # ifndef EAI_BADFLAGS |
f0007cad | 116 | # define EAI_BADFLAGS -1 /* Invalid value for 'ai_flags' field. */ |
40ff484d LC |
117 | # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */ |
118 | # define EAI_AGAIN -3 /* Temporary failure in name resolution. */ | |
119 | # define EAI_FAIL -4 /* Non-recoverable failure in name res. */ | |
120 | # define EAI_NODATA -5 /* No address associated with NAME. */ | |
f0007cad LC |
121 | # define EAI_FAMILY -6 /* 'ai_family' not supported. */ |
122 | # define EAI_SOCKTYPE -7 /* 'ai_socktype' not supported. */ | |
123 | # define EAI_SERVICE -8 /* SERVICE not supported for 'ai_socktype'. */ | |
40ff484d LC |
124 | # define EAI_MEMORY -10 /* Memory allocation failure. */ |
125 | # endif | |
126 | ||
127 | /* Since EAI_NODATA is deprecated by RFC3493, some systems (at least | |
128 | FreeBSD, which does define EAI_BADFLAGS) have removed the definition | |
129 | in favor of EAI_NONAME. */ | |
130 | # if !defined EAI_NODATA && defined EAI_NONAME | |
131 | # define EAI_NODATA EAI_NONAME | |
132 | # endif | |
133 | ||
134 | # ifndef EAI_OVERFLOW | |
135 | /* Not defined on mingw32 and Haiku. */ | |
136 | # define EAI_OVERFLOW -12 /* Argument buffer overflow. */ | |
137 | # endif | |
138 | # ifndef EAI_ADDRFAMILY | |
139 | /* Not defined on mingw32. */ | |
140 | # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */ | |
141 | # endif | |
142 | # ifndef EAI_SYSTEM | |
143 | /* Not defined on mingw32. */ | |
f0007cad | 144 | # define EAI_SYSTEM -11 /* System error returned in 'errno'. */ |
40ff484d LC |
145 | # endif |
146 | ||
147 | # if 0 | |
148 | /* The commented out definitions below are not yet implemented in the | |
149 | GNULIB getaddrinfo() replacement, so are not yet needed. | |
150 | ||
151 | If they are restored, be sure to protect the definitions with #ifndef. */ | |
152 | # ifndef EAI_INPROGRESS | |
153 | # define EAI_INPROGRESS -100 /* Processing request in progress. */ | |
154 | # define EAI_CANCELED -101 /* Request canceled. */ | |
155 | # define EAI_NOTCANCELED -102 /* Request not canceled. */ | |
156 | # define EAI_ALLDONE -103 /* All requests done. */ | |
157 | # define EAI_INTR -104 /* Interrupted by a signal. */ | |
158 | # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */ | |
159 | # endif | |
160 | # endif | |
161 | ||
162 | # if !@HAVE_DECL_GETADDRINFO@ | |
163 | /* Translate name of a service location and/or a service name to set of | |
164 | socket addresses. | |
165 | For more details, see the POSIX:2001 specification | |
166 | <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */ | |
3d458a81 AW |
167 | _GL_FUNCDECL_SYS (getaddrinfo, int, |
168 | (const char *restrict nodename, | |
169 | const char *restrict servname, | |
170 | const struct addrinfo *restrict hints, | |
171 | struct addrinfo **restrict res) | |
172 | _GL_ARG_NONNULL ((4))); | |
40ff484d | 173 | # endif |
3d458a81 AW |
174 | _GL_CXXALIAS_SYS (getaddrinfo, int, |
175 | (const char *restrict nodename, | |
176 | const char *restrict servname, | |
177 | const struct addrinfo *restrict hints, | |
178 | struct addrinfo **restrict res)); | |
179 | _GL_CXXALIASWARN (getaddrinfo); | |
40ff484d LC |
180 | |
181 | # if !@HAVE_DECL_FREEADDRINFO@ | |
f0007cad | 182 | /* Free 'addrinfo' structure AI including associated storage. |
40ff484d LC |
183 | For more details, see the POSIX:2001 specification |
184 | <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */ | |
3d458a81 AW |
185 | _GL_FUNCDECL_SYS (freeaddrinfo, void, (struct addrinfo *ai) |
186 | _GL_ARG_NONNULL ((1))); | |
40ff484d | 187 | # endif |
3d458a81 AW |
188 | _GL_CXXALIAS_SYS (freeaddrinfo, void, (struct addrinfo *ai)); |
189 | _GL_CXXALIASWARN (freeaddrinfo); | |
40ff484d | 190 | |
3d458a81 AW |
191 | # if @REPLACE_GAI_STRERROR@ |
192 | # if !(defined __cplusplus && defined GNULIB_NAMESPACE) | |
193 | # undef gai_strerror | |
194 | # define gai_strerror rpl_gai_strerror | |
195 | # endif | |
196 | _GL_FUNCDECL_RPL (gai_strerror, const char *, (int ecode)); | |
197 | _GL_CXXALIAS_RPL (gai_strerror, const char *, (int ecode)); | |
198 | # else | |
199 | # if !@HAVE_DECL_GAI_STRERROR@ | |
40ff484d LC |
200 | /* Convert error return from getaddrinfo() to a string. |
201 | For more details, see the POSIX:2001 specification | |
202 | <http://www.opengroup.org/susv3xsh/gai_strerror.html>. */ | |
3d458a81 AW |
203 | _GL_FUNCDECL_SYS (gai_strerror, const char *, (int ecode)); |
204 | # endif | |
205 | _GL_CXXALIAS_SYS (gai_strerror, const char *, (int ecode)); | |
40ff484d | 206 | # endif |
3d458a81 | 207 | _GL_CXXALIASWARN (gai_strerror); |
40ff484d LC |
208 | |
209 | # if !@HAVE_DECL_GETNAMEINFO@ | |
210 | /* Convert socket address to printable node and service names. | |
211 | For more details, see the POSIX:2001 specification | |
212 | <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */ | |
3d458a81 AW |
213 | _GL_FUNCDECL_SYS (getnameinfo, int, |
214 | (const struct sockaddr *restrict sa, socklen_t salen, | |
215 | char *restrict node, socklen_t nodelen, | |
216 | char *restrict service, socklen_t servicelen, | |
217 | int flags) | |
218 | _GL_ARG_NONNULL ((1))); | |
219 | # endif | |
220 | /* Need to cast, because on glibc systems, the seventh parameter is | |
221 | unsigned int flags. */ | |
222 | _GL_CXXALIAS_SYS_CAST (getnameinfo, int, | |
223 | (const struct sockaddr *restrict sa, socklen_t salen, | |
a927b6c1 LC |
224 | char *restrict node, socklen_t nodelen, |
225 | char *restrict service, socklen_t servicelen, | |
3d458a81 AW |
226 | int flags)); |
227 | _GL_CXXALIASWARN (getnameinfo); | |
40ff484d LC |
228 | |
229 | /* Possible flags for getnameinfo. */ | |
230 | # ifndef NI_NUMERICHOST | |
231 | # define NI_NUMERICHOST 1 | |
232 | # endif | |
233 | # ifndef NI_NUMERICSERV | |
234 | # define NI_NUMERICSERV 2 | |
235 | # endif | |
236 | ||
a927b6c1 LC |
237 | #elif defined GNULIB_POSIXCHECK |
238 | ||
239 | # undef getaddrinfo | |
240 | # if HAVE_RAW_DECL_GETADDRINFO | |
241 | _GL_WARN_ON_USE (getaddrinfo, "getaddrinfo is unportable - " | |
242 | "use gnulib module getaddrinfo for portability"); | |
243 | # endif | |
244 | ||
245 | # undef freeaddrinfo | |
246 | # if HAVE_RAW_DECL_FREEADDRINFO | |
247 | _GL_WARN_ON_USE (freeaddrinfo, "freeaddrinfo is unportable - " | |
248 | "use gnulib module getaddrinfo for portability"); | |
249 | # endif | |
250 | ||
251 | # undef gai_strerror | |
252 | # if HAVE_RAW_DECL_GAI_STRERROR | |
253 | _GL_WARN_ON_USE (gai_strerror, "gai_strerror is unportable - " | |
254 | "use gnulib module getaddrinfo for portability"); | |
255 | # endif | |
256 | ||
257 | # undef getnameinfo | |
258 | # if HAVE_RAW_DECL_GETNAMEINFO | |
259 | _GL_WARN_ON_USE (getnameinfo, "getnameinfo is unportable - " | |
260 | "use gnulib module getaddrinfo for portability"); | |
261 | # endif | |
262 | ||
263 | #endif | |
40ff484d | 264 | |
3d458a81 AW |
265 | #endif /* _@GUARD_PREFIX@_NETDB_H */ |
266 | #endif /* _@GUARD_PREFIX@_NETDB_H */ |