Debian Codegraph @

lib/netdb.in.h

raw
1 /* Provide a netdb.h header file for systems lacking it (read: MinGW).
2 Copyright (C) 2008-2026 Free Software Foundation, Inc.
3 Written by Simon Josefsson.
4
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.
9
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.
14
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/>. */
17
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
20 application. */
21
22 #ifndef _@GUARD_PREFIX@_NETDB_H
23
24 #if __GNUC__ >= 3
25 @PRAGMA_SYSTEM_HEADER@
26 #endif
27 @PRAGMA_COLUMNS@
28
29 #if @HAVE_NETDB_H@
30
31 /* The include_next requires a split double-inclusion guard. */
32 # @INCLUDE_NEXT@ @NEXT_NETDB_H@
33
34 #endif
35
36 #ifndef _@GUARD_PREFIX@_NETDB_H
37 #define _@GUARD_PREFIX@_NETDB_H
38
39 /* This file uses GNULIB_POSIXCHECK, HAVE_RAW_DECL_*. */
40 #if !_GL_CONFIG_H_INCLUDED
41 #error "Please include config.h first."
42 #endif
43
44 /* Get <netdb.h> definitions such as 'socklen_t' and 'struct hostent'
45 on MinGW. */
46 #include <sys/socket.h>
47
48 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
49
50 /* The definition of _GL_ARG_NONNULL is copied here. */
51
52 /* The definition of _GL_WARN_ON_USE is copied here. */
53
54 /* Declarations for a platform that lacks <netdb.h>, or where it is
55 incomplete. */
56
57 /* Maximum length of a fully-qualified domain name. */
58 #undef NI_MAXHOST
59 #define NI_MAXHOST 1025
60
61 /* Maximum length of a service. */
62 #undef NI_MAXSERV
63 #define NI_MAXSERV 32
64
65 #if @GNULIB_GETADDRINFO@
66
67 # if !@HAVE_STRUCT_ADDRINFO@
68
69 # ifdef __cplusplus
70 extern "C" {
71 # endif
72
73 # if !GNULIB_defined_struct_addrinfo
74 /* Structure to contain information about address of a service provider. */
75 struct addrinfo
76 {
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. */
85 };
86 # define GNULIB_defined_struct_addrinfo 1
87 # endif
88
89 # ifdef __cplusplus
90 }
91 # endif
92
93 # endif
94
95 /* Possible values for 'ai_flags' field in 'addrinfo' structure. */
96 # ifndef AI_PASSIVE
97 # define AI_PASSIVE 0x0001 /* Socket address is intended for 'bind'. */
98 # endif
99 # ifndef AI_CANONNAME
100 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
101 # endif
102 # ifndef AI_NUMERICHOST
103 # define AI_NUMERICHOST 0x0004 /* Return numeric host address as name. */
104 # endif
105 # ifndef AI_NUMERICSERV
106 # define AI_NUMERICSERV 0x0400 /* Return service number as service name. */
107 # endif
108
109 /* These symbolic constants are required to be present by POSIX, but
110 our getaddrinfo replacement doesn't use them (yet). Setting them
111 to 0 on systems that doesn't have them avoids causing problems for
112 system getaddrinfo implementations that would be confused by
113 unknown values. */
114 # ifndef AI_V4MAPPED
115 # define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */
116 # endif
117 # ifndef AI_ALL
118 # define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
119 # endif
120 # ifndef AI_ADDRCONFIG
121 # define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose
122 returned address type. */
123 # endif
124
125 /* Error values for 'getaddrinfo' function. */
126 # ifndef EAI_BADFLAGS
127 # define EAI_BADFLAGS -1 /* Invalid value for 'ai_flags' field. */
128 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
129 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
130 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
131 # define EAI_NODATA -5 /* No address associated with NAME. */
132 # define EAI_FAMILY -6 /* 'ai_family' not supported. */
133 # define EAI_SOCKTYPE -7 /* 'ai_socktype' not supported. */
134 # define EAI_SERVICE -8 /* SERVICE not supported for 'ai_socktype'. */
135 # define EAI_MEMORY -10 /* Memory allocation failure. */
136 # endif
137
138 /* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
139 FreeBSD, which does define EAI_BADFLAGS) have removed the definition
140 in favor of EAI_NONAME. */
141 # if !defined EAI_NODATA && defined EAI_NONAME
142 # define EAI_NODATA EAI_NONAME
143 # endif
144
145 # ifndef EAI_OVERFLOW
146 /* Not defined on mingw32 and Haiku. */
147 # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
148 # endif
149 # ifndef EAI_ADDRFAMILY
150 /* Not defined on mingw32. */
151 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
152 # endif
153 # ifndef EAI_SYSTEM
154 /* Not defined on mingw32. */
155 # define EAI_SYSTEM -11 /* System error returned in 'errno'. */
156 # endif
157
158 # if 0
159 /* The commented out definitions below are not yet implemented in the
160 GNULIB getaddrinfo() replacement, so are not yet needed.
161
162 If they are restored, be sure to protect the definitions with #ifndef. */
163 # ifndef EAI_INPROGRESS
164 # define EAI_INPROGRESS -100 /* Processing request in progress. */
165 # define EAI_CANCELED -101 /* Request canceled. */
166 # define EAI_NOTCANCELED -102 /* Request not canceled. */
167 # define EAI_ALLDONE -103 /* All requests done. */
168 # define EAI_INTR -104 /* Interrupted by a signal. */
169 # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
170 # endif
171 # endif
172
173 /* Translate name of a service location and/or a service name to set of
174 socket addresses.
175 For more details, see the POSIX:2008 specification
176 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>. */
177 # if @REPLACE_GETADDRINFO@
178 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
179 # undef getaddrinfo
180 # define getaddrinfo rpl_getaddrinfo
181 # endif
182 _GL_FUNCDECL_RPL (getaddrinfo, int,
183 (const char *restrict nodename,
184 const char *restrict servname,
185 const struct addrinfo *restrict hints,
186 struct addrinfo **restrict res),
187 _GL_ARG_NONNULL ((4)));
188 _GL_CXXALIAS_RPL (getaddrinfo, int,
189 (const char *restrict nodename,
190 const char *restrict servname,
191 const struct addrinfo *restrict hints,
192 struct addrinfo **restrict res));
193 # else
194 # if !@HAVE_DECL_GETADDRINFO@
195 _GL_FUNCDECL_SYS (getaddrinfo, int,
196 (const char *restrict nodename,
197 const char *restrict servname,
198 const struct addrinfo *restrict hints,
199 struct addrinfo **restrict res),
200 _GL_ARG_NONNULL ((4)));
201 # endif
202 _GL_CXXALIAS_SYS (getaddrinfo, int,
203 (const char *restrict nodename,
204 const char *restrict servname,
205 const struct addrinfo *restrict hints,
206 struct addrinfo **restrict res));
207 # endif
208 _GL_CXXALIASWARN (getaddrinfo);
209
210 /* Free 'addrinfo' structure AI including associated storage.
211 For more details, see the POSIX:2008 specification
212 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>. */
213 # if @REPLACE_GETADDRINFO@
214 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
215 # undef freeaddrinfo
216 # define freeaddrinfo rpl_freeaddrinfo
217 # endif
218 _GL_FUNCDECL_RPL (freeaddrinfo, void, (struct addrinfo *ai),
219 _GL_ARG_NONNULL ((1)));
220 _GL_CXXALIAS_RPL (freeaddrinfo, void, (struct addrinfo *ai));
221 # else
222 # if !@HAVE_DECL_FREEADDRINFO@
223 _GL_FUNCDECL_SYS (freeaddrinfo, void, (struct addrinfo *ai),
224 _GL_ARG_NONNULL ((1)));
225 # endif
226 _GL_CXXALIAS_SYS (freeaddrinfo, void, (struct addrinfo *ai));
227 # endif
228 _GL_CXXALIASWARN (freeaddrinfo);
229
230 # if @REPLACE_GAI_STRERROR@
231 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
232 # undef gai_strerror
233 # define gai_strerror rpl_gai_strerror
234 # endif
235 _GL_FUNCDECL_RPL (gai_strerror, const char *, (int ecode), );
236 _GL_CXXALIAS_RPL (gai_strerror, const char *, (int ecode));
237 # else
238 # if !@HAVE_DECL_GAI_STRERROR@
239 /* Convert error return from getaddrinfo() to a string.
240 For more details, see the POSIX:2008 specification
241 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gai_strerror.html>. */
242 _GL_FUNCDECL_SYS (gai_strerror, const char *, (int ecode), );
243 # endif
244 _GL_CXXALIAS_SYS (gai_strerror, const char *, (int ecode));
245 # endif
246 # if __GLIBC__ >= 2
247 _GL_CXXALIASWARN (gai_strerror);
248 # endif
249
250 # if !@HAVE_DECL_GETNAMEINFO@
251 /* Convert socket address to printable node and service names.
252 For more details, see the POSIX:2008 specification
253 <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getnameinfo.html>. */
254 _GL_FUNCDECL_SYS (getnameinfo, int,
255 (const struct sockaddr *restrict sa, socklen_t salen,
256 char *restrict node, socklen_t nodelen,
257 char *restrict service, socklen_t servicelen,
258 int flags),
259 _GL_ARG_NONNULL ((1)));
260 # endif
261 /* Need to cast, because on glibc systems, the seventh parameter is
262 unsigned int flags. */
263 _GL_CXXALIAS_SYS_CAST (getnameinfo, int,
264 (const struct sockaddr *restrict sa, socklen_t salen,
265 char *restrict node, socklen_t nodelen,
266 char *restrict service, socklen_t servicelen,
267 int flags));
268 _GL_CXXALIASWARN (getnameinfo);
269
270 /* Possible flags for getnameinfo. */
271 # ifndef NI_NUMERICHOST
272 # define NI_NUMERICHOST 1
273 # endif
274 # ifndef NI_NUMERICSERV
275 # define NI_NUMERICSERV 2
276 # endif
277
278 #elif defined GNULIB_POSIXCHECK
279
280 # if HAVE_RAW_DECL_GETADDRINFO
281 _GL_WARN_ON_USE (getaddrinfo, "getaddrinfo is unportable - "
282 "use gnulib module getaddrinfo for portability");
283 # endif
284
285 # if HAVE_RAW_DECL_FREEADDRINFO
286 _GL_WARN_ON_USE (freeaddrinfo, "freeaddrinfo is unportable - "
287 "use gnulib module getaddrinfo for portability");
288 # endif
289
290 # if HAVE_RAW_DECL_GAI_STRERROR
291 _GL_WARN_ON_USE (gai_strerror, "gai_strerror is unportable - "
292 "use gnulib module getaddrinfo for portability");
293 # endif
294
295 # if HAVE_RAW_DECL_GETNAMEINFO
296 _GL_WARN_ON_USE (getnameinfo, "getnameinfo is unportable - "
297 "use gnulib module getaddrinfo for portability");
298 # endif
299
300 #endif
301
302 #endif /* _@GUARD_PREFIX@_NETDB_H */
303 #endif /* _@GUARD_PREFIX@_NETDB_H */