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