1 /* Provide a netdb.h header file for systems lacking it (read: MinGW).
2 Copyright (C) 2008-2010 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 3, or (at your option)
8 any later version.
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
21 application. */
23 #ifndef _GL_NETDB_H
25 #if __GNUC__ >= 3
26 @PRAGMA_SYSTEM_HEADER@
27 #endif
29 #if @HAVE_NETDB_H@
31 /* The include_next requires a split double-inclusion guard. */
32 # @INCLUDE_NEXT@ @NEXT_NETDB_H@
34 #endif
36 #ifndef _GL_NETDB_H
37 #define _GL_NETDB_H
39 /* Get netdb.h definitions such as struct hostent for MinGW. */
40 #include <sys/socket.h>
42 /* The definition of _GL_ARG_NONNULL is copied here. */
44 /* The definition of _GL_WARN_ON_USE is copied here. */
46 /* Declarations for a platform that lacks <netdb.h>, or where it is
47 incomplete. */
49 #if @GNULIB_GETADDRINFO@
51 # if !@HAVE_STRUCT_ADDRINFO@
53 /* Structure to contain information about address of a service provider. */
54 struct addrinfo
55 {
56 int ai_flags; /* Input flags. */
57 int ai_family; /* Protocol family for socket. */
58 int ai_socktype; /* Socket type. */
59 int ai_protocol; /* Protocol for socket. */
60 socklen_t ai_addrlen; /* Length of socket address. */
61 struct sockaddr *ai_addr; /* Socket address for socket. */
62 char *ai_canonname; /* Canonical name for service location. */
63 struct addrinfo *ai_next; /* Pointer to next in list. */
64 };
65 # endif
67 /* Possible values for `ai_flags' field in `addrinfo' structure. */
68 # ifndef AI_PASSIVE
69 # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
70 # endif
71 # ifndef AI_CANONNAME
72 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
73 # endif
74 # ifndef AI_NUMERICSERV
75 # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
76 # endif
78 # if 0
79 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
80 # endif
82 /* These symbolic constants are required to be present by POSIX, but
83 our getaddrinfo replacement doesn't use them (yet). Setting them
84 to 0 on systems that doesn't have them avoids causing problems for
85 system getaddrinfo implementations that would be confused by
86 unknown values. */
87 # ifndef AI_V4MAPPED
88 # define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */
89 # endif
90 # ifndef AI_ALL
91 # define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
92 # endif
93 # ifndef AI_ADDRCONFIG
94 # define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose
95 returned address type. */
96 # endif
98 /* Error values for `getaddrinfo' function. */
99 # ifndef EAI_BADFLAGS
100 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
101 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
102 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
103 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
104 # define EAI_NODATA -5 /* No address associated with NAME. */
105 # define EAI_FAMILY -6 /* `ai_family' not supported. */
106 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
107 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
108 # define EAI_MEMORY -10 /* Memory allocation failure. */
109 # endif
111 /* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
112 FreeBSD, which does define EAI_BADFLAGS) have removed the definition
113 in favor of EAI_NONAME. */
114 # if !defined EAI_NODATA && defined EAI_NONAME
115 # define EAI_NODATA EAI_NONAME
116 # endif
118 # ifndef EAI_OVERFLOW
119 /* Not defined on mingw32 and Haiku. */
120 # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
121 # endif
122 # ifndef EAI_ADDRFAMILY
123 /* Not defined on mingw32. */
124 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
125 # endif
126 # ifndef EAI_SYSTEM
127 /* Not defined on mingw32. */
128 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
129 # endif
131 # if 0
132 /* The commented out definitions below are not yet implemented in the
133 GNULIB getaddrinfo() replacement, so are not yet needed.
135 If they are restored, be sure to protect the definitions with #ifndef. */
136 # ifndef EAI_INPROGRESS
137 # define EAI_INPROGRESS -100 /* Processing request in progress. */
138 # define EAI_CANCELED -101 /* Request canceled. */
139 # define EAI_NOTCANCELED -102 /* Request not canceled. */
140 # define EAI_ALLDONE -103 /* All requests done. */
141 # define EAI_INTR -104 /* Interrupted by a signal. */
142 # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
143 # endif
144 # endif
146 # if !@HAVE_DECL_GETADDRINFO@
147 /* Translate name of a service location and/or a service name to set of
148 socket addresses.
149 For more details, see the POSIX:2001 specification
150 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
151 extern int getaddrinfo (const char *restrict nodename,
152 const char *restrict servname,
153 const struct addrinfo *restrict hints,
154 struct addrinfo **restrict res)
155 _GL_ARG_NONNULL ((4));
156 # endif
158 # if !@HAVE_DECL_FREEADDRINFO@
159 /* Free `addrinfo' structure AI including associated storage.
160 For more details, see the POSIX:2001 specification
161 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
162 extern void freeaddrinfo (struct addrinfo *ai) _GL_ARG_NONNULL ((1));
163 # endif
165 # if !@HAVE_DECL_GAI_STRERROR@
166 /* Convert error return from getaddrinfo() to a string.
167 For more details, see the POSIX:2001 specification
168 <http://www.opengroup.org/susv3xsh/gai_strerror.html>. */
169 extern const char *gai_strerror (int ecode);
170 # endif
172 # if !@HAVE_DECL_GETNAMEINFO@
173 /* Convert socket address to printable node and service names.
174 For more details, see the POSIX:2001 specification
175 <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */
176 extern int getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
177 char *restrict node, socklen_t nodelen,
178 char *restrict service, socklen_t servicelen,
179 int flags)
180 _GL_ARG_NONNULL ((1));
181 # endif
183 /* Possible flags for getnameinfo. */
184 # ifndef NI_NUMERICHOST
185 # define NI_NUMERICHOST 1
186 # endif
187 # ifndef NI_NUMERICSERV
188 # define NI_NUMERICSERV 2
189 # endif
191 #elif defined GNULIB_POSIXCHECK
193 # undef getaddrinfo
194 # if HAVE_RAW_DECL_GETADDRINFO
195 _GL_WARN_ON_USE (getaddrinfo, "getaddrinfo is unportable - "
196 "use gnulib module getaddrinfo for portability");
197 # endif
199 # undef freeaddrinfo
200 # if HAVE_RAW_DECL_FREEADDRINFO
201 _GL_WARN_ON_USE (freeaddrinfo, "freeaddrinfo is unportable - "
202 "use gnulib module getaddrinfo for portability");
203 # endif
205 # undef gai_strerror
206 # if HAVE_RAW_DECL_GAI_STRERROR
207 _GL_WARN_ON_USE (gai_strerror, "gai_strerror is unportable - "
208 "use gnulib module getaddrinfo for portability");
209 # endif
211 # undef getnameinfo
212 # if HAVE_RAW_DECL_GETNAMEINFO
213 _GL_WARN_ON_USE (getnameinfo, "getnameinfo is unportable - "
214 "use gnulib module getaddrinfo for portability");
215 # endif
217 #endif
219 #endif /* _GL_NETDB_H */
220 #endif /* _GL_NETDB_H */