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