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