1 /* Provide a netdb.h header file for systems lacking it (read: MinGW).
2 Copyright (C) 2008-2011 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, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
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
23 #ifndef _@GUARD_PREFIX@_NETDB_H
26 @PRAGMA_SYSTEM_HEADER@
32 /* The include_next requires a split double-inclusion guard. */
33 # @INCLUDE_NEXT@ @NEXT_NETDB_H@
37 #ifndef _@GUARD_PREFIX@_NETDB_H
38 #define _@GUARD_PREFIX@_NETDB_H
40 /* Get <netdb.h> definitions such as 'socklen_t' on IRIX 6.5 and OSF/1 4.0 and
41 'struct hostent' on MinGW. */
42 #include <sys/socket.h>
44 /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
46 /* The definition of _GL_ARG_NONNULL is copied here. */
48 /* The definition of _GL_WARN_ON_USE is copied here. */
50 /* Declarations for a platform that lacks <netdb.h>, or where it is
53 #if @GNULIB_GETADDRINFO@
55 # if !@HAVE_STRUCT_ADDRINFO@
61 # if !GNULIB_defined_struct_addrinfo
62 /* Structure to contain information about address of a service provider. */
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. */
74 # define GNULIB_defined_struct_addrinfo 1
83 /* Possible values for `ai_flags' field in `addrinfo' structure. */
85 # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
88 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
90 # ifndef AI_NUMERICSERV
91 # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
95 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
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
104 # define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */
107 # define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
109 # ifndef AI_ADDRCONFIG
110 # define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose
111 returned address type. */
114 /* Error values for `getaddrinfo' function. */
115 # ifndef EAI_BADFLAGS
116 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
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. */
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'. */
124 # define EAI_MEMORY -10 /* Memory allocation failure. */
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
134 # ifndef EAI_OVERFLOW
135 /* Not defined on mingw32 and Haiku. */
136 # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
138 # ifndef EAI_ADDRFAMILY
139 /* Not defined on mingw32. */
140 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
143 /* Not defined on mingw32. */
144 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
148 /* The commented out definitions below are not yet implemented in the
149 GNULIB getaddrinfo() replacement, so are not yet needed.
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. */
162 # if !@HAVE_DECL_GETADDRINFO@
163 /* Translate name of a service location and/or a service name to set of
165 For more details, see the POSIX:2001 specification
166 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
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)));
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);
181 # if !@HAVE_DECL_FREEADDRINFO@
182 /* Free `addrinfo' structure AI including associated storage.
183 For more details, see the POSIX:2001 specification
184 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
185 _GL_FUNCDECL_SYS (freeaddrinfo, void, (struct addrinfo *ai)
186 _GL_ARG_NONNULL ((1)));
188 _GL_CXXALIAS_SYS (freeaddrinfo, void, (struct addrinfo *ai));
189 _GL_CXXALIASWARN (freeaddrinfo);
191 # if @REPLACE_GAI_STRERROR@
192 # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
194 # define gai_strerror rpl_gai_strerror
196 _GL_FUNCDECL_RPL (gai_strerror, const char *, (int ecode));
197 _GL_CXXALIAS_RPL (gai_strerror, const char *, (int ecode));
199 # if !@HAVE_DECL_GAI_STRERROR@
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>. */
203 _GL_FUNCDECL_SYS (gai_strerror, const char *, (int ecode));
205 _GL_CXXALIAS_SYS (gai_strerror, const char *, (int ecode));
207 _GL_CXXALIASWARN (gai_strerror);
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>. */
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,
218 _GL_ARG_NONNULL ((1)));
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,
224 char *restrict node, socklen_t nodelen,
225 char *restrict service, socklen_t servicelen,
227 _GL_CXXALIASWARN (getnameinfo);
229 /* Possible flags for getnameinfo. */
230 # ifndef NI_NUMERICHOST
231 # define NI_NUMERICHOST 1
233 # ifndef NI_NUMERICSERV
234 # define NI_NUMERICSERV 2
237 #elif defined GNULIB_POSIXCHECK
240 # if HAVE_RAW_DECL_GETADDRINFO
241 _GL_WARN_ON_USE (getaddrinfo, "getaddrinfo is unportable - "
242 "use gnulib module getaddrinfo for portability");
246 # if HAVE_RAW_DECL_FREEADDRINFO
247 _GL_WARN_ON_USE (freeaddrinfo, "freeaddrinfo is unportable - "
248 "use gnulib module getaddrinfo for portability");
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");
258 # if HAVE_RAW_DECL_GETNAMEINFO
259 _GL_WARN_ON_USE (getnameinfo, "getnameinfo is unportable - "
260 "use gnulib module getaddrinfo for portability");
265 #endif /* _@GUARD_PREFIX@_NETDB_H */
266 #endif /* _@GUARD_PREFIX@_NETDB_H */