1 /* Provide a netdb.h header file for systems lacking it (read: MinGW).
2 Copyright (C) 2008-2019 Free Software Foundation, Inc.
3 Written by Simon Josefsson.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <https://www.gnu.org/licenses/>. */
18 /* This file is supposed to be used on platforms that lack <netdb.h>.
19 It is intended to provide definitions and prototypes needed by an
22 #ifndef _@GUARD_PREFIX@_NETDB_H
25 @PRAGMA_SYSTEM_HEADER@
31 /* The include_next requires a split double-inclusion guard. */
32 # @INCLUDE_NEXT@ @NEXT_NETDB_H@
36 #ifndef _@GUARD_PREFIX@_NETDB_H
37 #define _@GUARD_PREFIX@_NETDB_H
39 /* Get <netdb.h> definitions such as 'socklen_t' on IRIX 6.5 and OSF/1 4.0 and
40 'struct hostent' on MinGW. */
41 #include <sys/socket.h>
43 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
45 /* The definition of _GL_ARG_NONNULL is copied here. */
47 /* The definition of _GL_WARN_ON_USE is copied here. */
49 /* Declarations for a platform that lacks <netdb.h>, or where it is
52 #if @GNULIB_GETADDRINFO@
54 # if !@HAVE_STRUCT_ADDRINFO@
60 # if !GNULIB_defined_struct_addrinfo
61 /* Structure to contain information about address of a service provider. */
64 int ai_flags
; /* Input flags. */
65 int ai_family
; /* Protocol family for socket. */
66 int ai_socktype
; /* Socket type. */
67 int ai_protocol
; /* Protocol for socket. */
68 socklen_t ai_addrlen
; /* Length of socket address. */
69 struct sockaddr
*ai_addr
; /* Socket address for socket. */
70 char *ai_canonname
; /* Canonical name for service location. */
71 struct addrinfo
*ai_next
; /* Pointer to next in list. */
73 # define GNULIB_defined_struct_addrinfo 1
82 /* Possible values for 'ai_flags' field in 'addrinfo' structure. */
84 # define AI_PASSIVE 0x0001 /* Socket address is intended for 'bind'. */
87 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
89 # ifndef AI_NUMERICSERV
90 # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
94 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
97 /* These symbolic constants are required to be present by POSIX, but
98 our getaddrinfo replacement doesn't use them (yet). Setting them
99 to 0 on systems that doesn't have them avoids causing problems for
100 system getaddrinfo implementations that would be confused by
103 # define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */
106 # define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
108 # ifndef AI_ADDRCONFIG
109 # define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose
110 returned address type. */
113 /* Error values for 'getaddrinfo' function. */
114 # ifndef EAI_BADFLAGS
115 # define EAI_BADFLAGS -1 /* Invalid value for 'ai_flags' field. */
116 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
117 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
118 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
119 # define EAI_NODATA -5 /* No address associated with NAME. */
120 # define EAI_FAMILY -6 /* 'ai_family' not supported. */
121 # define EAI_SOCKTYPE -7 /* 'ai_socktype' not supported. */
122 # define EAI_SERVICE -8 /* SERVICE not supported for 'ai_socktype'. */
123 # define EAI_MEMORY -10 /* Memory allocation failure. */
126 /* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
127 FreeBSD, which does define EAI_BADFLAGS) have removed the definition
128 in favor of EAI_NONAME. */
129 # if !defined EAI_NODATA && defined EAI_NONAME
130 # define EAI_NODATA EAI_NONAME
133 # ifndef EAI_OVERFLOW
134 /* Not defined on mingw32 and Haiku. */
135 # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
137 # ifndef EAI_ADDRFAMILY
138 /* Not defined on mingw32. */
139 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
142 /* Not defined on mingw32. */
143 # define EAI_SYSTEM -11 /* System error returned in 'errno'. */
147 /* The commented out definitions below are not yet implemented in the
148 GNULIB getaddrinfo() replacement, so are not yet needed.
150 If they are restored, be sure to protect the definitions with #ifndef. */
151 # ifndef EAI_INPROGRESS
152 # define EAI_INPROGRESS -100 /* Processing request in progress. */
153 # define EAI_CANCELED -101 /* Request canceled. */
154 # define EAI_NOTCANCELED -102 /* Request not canceled. */
155 # define EAI_ALLDONE -103 /* All requests done. */
156 # define EAI_INTR -104 /* Interrupted by a signal. */
157 # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
161 /* Translate name of a service location and/or a service name to set of
163 For more details, see the POSIX:2008 specification
164 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>. */
165 # if @REPLACE_GETADDRINFO@
166 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
168 # define getaddrinfo rpl_getaddrinfo
170 _GL_FUNCDECL_RPL (getaddrinfo
, int,
171 (const char *restrict nodename
,
172 const char *restrict servname
,
173 const struct addrinfo
*restrict hints
,
174 struct addrinfo
**restrict res
)
175 _GL_ARG_NONNULL ((4)));
176 _GL_CXXALIAS_RPL (getaddrinfo
, int,
177 (const char *restrict nodename
,
178 const char *restrict servname
,
179 const struct addrinfo
*restrict hints
,
180 struct addrinfo
**restrict res
));
182 # if !@HAVE_DECL_GETADDRINFO@
183 _GL_FUNCDECL_SYS (getaddrinfo
, int,
184 (const char *restrict nodename
,
185 const char *restrict servname
,
186 const struct addrinfo
*restrict hints
,
187 struct addrinfo
**restrict res
)
188 _GL_ARG_NONNULL ((4)));
190 _GL_CXXALIAS_SYS (getaddrinfo
, int,
191 (const char *restrict nodename
,
192 const char *restrict servname
,
193 const struct addrinfo
*restrict hints
,
194 struct addrinfo
**restrict res
));
196 _GL_CXXALIASWARN (getaddrinfo
);
198 /* Free 'addrinfo' structure AI including associated storage.
199 For more details, see the POSIX:2008 specification
200 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>. */
201 # if @REPLACE_GETADDRINFO@
202 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
204 # define freeaddrinfo rpl_freeaddrinfo
206 _GL_FUNCDECL_RPL (freeaddrinfo
, void, (struct addrinfo
*ai
)
207 _GL_ARG_NONNULL ((1)));
208 _GL_CXXALIAS_RPL (freeaddrinfo
, void, (struct addrinfo
*ai
));
210 # if !@HAVE_DECL_FREEADDRINFO@
211 _GL_FUNCDECL_SYS (freeaddrinfo
, void, (struct addrinfo
*ai
)
212 _GL_ARG_NONNULL ((1)));
214 _GL_CXXALIAS_SYS (freeaddrinfo
, void, (struct addrinfo
*ai
));
216 _GL_CXXALIASWARN (freeaddrinfo
);
218 # if @REPLACE_GAI_STRERROR@
219 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
221 # define gai_strerror rpl_gai_strerror
223 _GL_FUNCDECL_RPL (gai_strerror
, const char *, (int ecode
));
224 _GL_CXXALIAS_RPL (gai_strerror
, const char *, (int ecode
));
226 # if !@HAVE_DECL_GAI_STRERROR@
227 /* Convert error return from getaddrinfo() to a string.
228 For more details, see the POSIX:2008 specification
229 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gai_strerror.html>. */
230 _GL_FUNCDECL_SYS (gai_strerror
, const char *, (int ecode
));
232 _GL_CXXALIAS_SYS (gai_strerror
, const char *, (int ecode
));
234 _GL_CXXALIASWARN (gai_strerror
);
236 # if !@HAVE_DECL_GETNAMEINFO@
237 /* Convert socket address to printable node and service names.
238 For more details, see the POSIX:2008 specification
239 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getnameinfo.html>. */
240 _GL_FUNCDECL_SYS (getnameinfo
, int,
241 (const struct sockaddr
*restrict sa
, socklen_t salen
,
242 char *restrict node
, socklen_t nodelen
,
243 char *restrict service
, socklen_t servicelen
,
245 _GL_ARG_NONNULL ((1)));
247 /* Need to cast, because on glibc systems, the seventh parameter is
248 unsigned int flags. */
249 _GL_CXXALIAS_SYS_CAST (getnameinfo
, int,
250 (const struct sockaddr
*restrict sa
, socklen_t salen
,
251 char *restrict node
, socklen_t nodelen
,
252 char *restrict service
, socklen_t servicelen
,
254 _GL_CXXALIASWARN (getnameinfo
);
256 /* Possible flags for getnameinfo. */
257 # ifndef NI_NUMERICHOST
258 # define NI_NUMERICHOST 1
260 # ifndef NI_NUMERICSERV
261 # define NI_NUMERICSERV 2
264 #elif defined GNULIB_POSIXCHECK
267 # if HAVE_RAW_DECL_GETADDRINFO
268 _GL_WARN_ON_USE (getaddrinfo
, "getaddrinfo is unportable - "
269 "use gnulib module getaddrinfo for portability");
273 # if HAVE_RAW_DECL_FREEADDRINFO
274 _GL_WARN_ON_USE (freeaddrinfo
, "freeaddrinfo is unportable - "
275 "use gnulib module getaddrinfo for portability");
279 # if HAVE_RAW_DECL_GAI_STRERROR
280 _GL_WARN_ON_USE (gai_strerror
, "gai_strerror is unportable - "
281 "use gnulib module getaddrinfo for portability");
285 # if HAVE_RAW_DECL_GETNAMEINFO
286 _GL_WARN_ON_USE (getnameinfo
, "getnameinfo is unportable - "
287 "use gnulib module getaddrinfo for portability");
292 #endif /* _@GUARD_PREFIX@_NETDB_H */
293 #endif /* _@GUARD_PREFIX@_NETDB_H */