1 /* Provide a netdb.h header file for systems lacking it (read: MinGW).
2 Copyright (C) 2008-2024 Free Software Foundation, Inc.
3 Written by Simon Josefsson.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
10 This file 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.
15 You should have received a copy of the GNU Lesser 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 /* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
40 #if !_GL_CONFIG_H_INCLUDED
41 #error "Please include config.h first."
44 /* Get <netdb.h> definitions such as 'socklen_t' on IRIX 6.5 and OSF/1 4.0 and
45 'struct hostent' on MinGW. */
46 #include <sys/socket.h>
48 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
50 /* The definition of _GL_ARG_NONNULL is copied here. */
52 /* The definition of _GL_WARN_ON_USE is copied here. */
54 /* Declarations for a platform that lacks <netdb.h>, or where it is
57 /* Maximum length of a fully-qualified domain name. */
59 #define NI_MAXHOST 1025
61 /* Maximum length of a service. */
65 #if @GNULIB_GETADDRINFO@
67 # if !@HAVE_STRUCT_ADDRINFO@
73 # if !GNULIB_defined_struct_addrinfo
74 /* Structure to contain information about address of a service provider. */
77 int ai_flags
; /* Input flags. */
78 int ai_family
; /* Protocol family for socket. */
79 int ai_socktype
; /* Socket type. */
80 int ai_protocol
; /* Protocol for socket. */
81 socklen_t ai_addrlen
; /* Length of socket address. */
82 struct sockaddr
*ai_addr
; /* Socket address for socket. */
83 char *ai_canonname
; /* Canonical name for service location. */
84 struct addrinfo
*ai_next
; /* Pointer to next in list. */
86 # define GNULIB_defined_struct_addrinfo 1
95 /* Possible values for 'ai_flags' field in 'addrinfo' structure. */
97 # define AI_PASSIVE 0x0001 /* Socket address is intended for 'bind'. */
100 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
102 # ifndef AI_NUMERICSERV
103 # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
107 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
110 /* These symbolic constants are required to be present by POSIX, but
111 our getaddrinfo replacement doesn't use them (yet). Setting them
112 to 0 on systems that doesn't have them avoids causing problems for
113 system getaddrinfo implementations that would be confused by
116 # define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */
119 # define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
121 # ifndef AI_ADDRCONFIG
122 # define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose
123 returned address type. */
126 /* Error values for 'getaddrinfo' function. */
127 # ifndef EAI_BADFLAGS
128 # define EAI_BADFLAGS -1 /* Invalid value for 'ai_flags' field. */
129 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
130 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
131 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
132 # define EAI_NODATA -5 /* No address associated with NAME. */
133 # define EAI_FAMILY -6 /* 'ai_family' not supported. */
134 # define EAI_SOCKTYPE -7 /* 'ai_socktype' not supported. */
135 # define EAI_SERVICE -8 /* SERVICE not supported for 'ai_socktype'. */
136 # define EAI_MEMORY -10 /* Memory allocation failure. */
139 /* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
140 FreeBSD, which does define EAI_BADFLAGS) have removed the definition
141 in favor of EAI_NONAME. */
142 # if !defined EAI_NODATA && defined EAI_NONAME
143 # define EAI_NODATA EAI_NONAME
146 # ifndef EAI_OVERFLOW
147 /* Not defined on mingw32 and Haiku. */
148 # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
150 # ifndef EAI_ADDRFAMILY
151 /* Not defined on mingw32. */
152 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
155 /* Not defined on mingw32. */
156 # define EAI_SYSTEM -11 /* System error returned in 'errno'. */
160 /* The commented out definitions below are not yet implemented in the
161 GNULIB getaddrinfo() replacement, so are not yet needed.
163 If they are restored, be sure to protect the definitions with #ifndef. */
164 # ifndef EAI_INPROGRESS
165 # define EAI_INPROGRESS -100 /* Processing request in progress. */
166 # define EAI_CANCELED -101 /* Request canceled. */
167 # define EAI_NOTCANCELED -102 /* Request not canceled. */
168 # define EAI_ALLDONE -103 /* All requests done. */
169 # define EAI_INTR -104 /* Interrupted by a signal. */
170 # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
174 /* Translate name of a service location and/or a service name to set of
176 For more details, see the POSIX:2008 specification
177 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>. */
178 # if @REPLACE_GETADDRINFO@
179 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
181 # define getaddrinfo rpl_getaddrinfo
183 _GL_FUNCDECL_RPL (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)));
189 _GL_CXXALIAS_RPL (getaddrinfo
, int,
190 (const char *restrict nodename
,
191 const char *restrict servname
,
192 const struct addrinfo
*restrict hints
,
193 struct addrinfo
**restrict res
));
195 # if !@HAVE_DECL_GETADDRINFO@
196 _GL_FUNCDECL_SYS (getaddrinfo
, int,
197 (const char *restrict nodename
,
198 const char *restrict servname
,
199 const struct addrinfo
*restrict hints
,
200 struct addrinfo
**restrict res
),
201 _GL_ARG_NONNULL ((4)));
203 _GL_CXXALIAS_SYS (getaddrinfo
, int,
204 (const char *restrict nodename
,
205 const char *restrict servname
,
206 const struct addrinfo
*restrict hints
,
207 struct addrinfo
**restrict res
));
209 _GL_CXXALIASWARN (getaddrinfo
);
211 /* Free 'addrinfo' structure AI including associated storage.
212 For more details, see the POSIX:2008 specification
213 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>. */
214 # if @REPLACE_GETADDRINFO@
215 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
217 # define freeaddrinfo rpl_freeaddrinfo
219 _GL_FUNCDECL_RPL (freeaddrinfo
, void, (struct addrinfo
*ai
),
220 _GL_ARG_NONNULL ((1)));
221 _GL_CXXALIAS_RPL (freeaddrinfo
, void, (struct addrinfo
*ai
));
223 # if !@HAVE_DECL_FREEADDRINFO@
224 _GL_FUNCDECL_SYS (freeaddrinfo
, void, (struct addrinfo
*ai
),
225 _GL_ARG_NONNULL ((1)));
227 _GL_CXXALIAS_SYS (freeaddrinfo
, void, (struct addrinfo
*ai
));
229 _GL_CXXALIASWARN (freeaddrinfo
);
231 # if @REPLACE_GAI_STRERROR@
232 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
234 # define gai_strerror rpl_gai_strerror
236 _GL_FUNCDECL_RPL (gai_strerror
, const char *, (int ecode
), );
237 _GL_CXXALIAS_RPL (gai_strerror
, const char *, (int ecode
));
239 # if !@HAVE_DECL_GAI_STRERROR@
240 /* Convert error return from getaddrinfo() to a string.
241 For more details, see the POSIX:2008 specification
242 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gai_strerror.html>. */
243 _GL_FUNCDECL_SYS (gai_strerror
, const char *, (int ecode
), );
245 _GL_CXXALIAS_SYS (gai_strerror
, const char *, (int ecode
));
248 _GL_CXXALIASWARN (gai_strerror
);
251 # if !@HAVE_DECL_GETNAMEINFO@
252 /* Convert socket address to printable node and service names.
253 For more details, see the POSIX:2008 specification
254 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getnameinfo.html>. */
255 _GL_FUNCDECL_SYS (getnameinfo
, int,
256 (const struct sockaddr
*restrict sa
, socklen_t salen
,
257 char *restrict node
, socklen_t nodelen
,
258 char *restrict service
, socklen_t servicelen
,
260 _GL_ARG_NONNULL ((1)));
262 /* Need to cast, because on glibc systems, the seventh parameter is
263 unsigned int flags. */
264 _GL_CXXALIAS_SYS_CAST (getnameinfo
, int,
265 (const struct sockaddr
*restrict sa
, socklen_t salen
,
266 char *restrict node
, socklen_t nodelen
,
267 char *restrict service
, socklen_t servicelen
,
269 _GL_CXXALIASWARN (getnameinfo
);
271 /* Possible flags for getnameinfo. */
272 # ifndef NI_NUMERICHOST
273 # define NI_NUMERICHOST 1
275 # ifndef NI_NUMERICSERV
276 # define NI_NUMERICSERV 2
279 #elif defined GNULIB_POSIXCHECK
282 # if HAVE_RAW_DECL_GETADDRINFO
283 _GL_WARN_ON_USE (getaddrinfo
, "getaddrinfo is unportable - "
284 "use gnulib module getaddrinfo for portability");
288 # if HAVE_RAW_DECL_FREEADDRINFO
289 _GL_WARN_ON_USE (freeaddrinfo
, "freeaddrinfo is unportable - "
290 "use gnulib module getaddrinfo for portability");
294 # if HAVE_RAW_DECL_GAI_STRERROR
295 _GL_WARN_ON_USE (gai_strerror
, "gai_strerror is unportable - "
296 "use gnulib module getaddrinfo for portability");
300 # if HAVE_RAW_DECL_GETNAMEINFO
301 _GL_WARN_ON_USE (getnameinfo
, "getnameinfo is unportable - "
302 "use gnulib module getaddrinfo for portability");
307 #endif /* _@GUARD_PREFIX@_NETDB_H */
308 #endif /* _@GUARD_PREFIX@_NETDB_H */