1 /* Provide a netdb.h header file for systems lacking it (read: MinGW).
2 Copyright (C) 2008-2009 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
28 @PRAGMA_SYSTEM_HEADER@
31 /* The include_next requires a split double-inclusion guard. */
32 # @INCLUDE_NEXT@ @NEXT_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 /* Declarations for a platform that lacks <netdb.h>, or where it is
47 #if @GNULIB_GETADDRINFO@
49 # if !@HAVE_STRUCT_ADDRINFO@
51 /* Structure to contain information about address of a service provider. */
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. */
65 /* Possible values for `ai_flags' field in `addrinfo' structure. */
67 # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
70 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
72 # ifndef AI_NUMERICSERV
73 # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
77 /* The commented out definitions below are not yet implemented in the
78 GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact,
79 cause conflicts on systems with a getaddrinfo() function which does not
82 If they are restored, be sure to protect the definitions with #ifndef. */
83 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
84 # define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
85 # define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */
86 # define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose
87 returned address type.. */
90 /* Error values for `getaddrinfo' function. */
92 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
93 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
94 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
95 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
96 # define EAI_NODATA -5 /* No address associated with NAME. */
97 # define EAI_FAMILY -6 /* `ai_family' not supported. */
98 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
99 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
100 # define EAI_MEMORY -10 /* Memory allocation failure. */
103 /* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
104 FreeBSD, which does define EAI_BADFLAGS) have removed the definition
105 in favor of EAI_NONAME. */
106 # if !defined EAI_NODATA && defined EAI_NONAME
107 # define EAI_NODATA EAI_NONAME
110 # ifndef EAI_OVERFLOW
111 /* Not defined on mingw32 and Haiku. */
112 # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
114 # ifndef EAI_ADDRFAMILY
115 /* Not defined on mingw32. */
116 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
119 /* Not defined on mingw32. */
120 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
124 /* The commented out definitions below are not yet implemented in the
125 GNULIB getaddrinfo() replacement, so are not yet needed.
127 If they are restored, be sure to protect the definitions with #ifndef. */
128 # ifndef EAI_INPROGRESS
129 # define EAI_INPROGRESS -100 /* Processing request in progress. */
130 # define EAI_CANCELED -101 /* Request canceled. */
131 # define EAI_NOTCANCELED -102 /* Request not canceled. */
132 # define EAI_ALLDONE -103 /* All requests done. */
133 # define EAI_INTR -104 /* Interrupted by a signal. */
134 # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
138 # if !@HAVE_DECL_GETADDRINFO@
139 /* Translate name of a service location and/or a service name to set of
141 For more details, see the POSIX:2001 specification
142 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
143 extern int getaddrinfo (const char *restrict nodename,
144 const char *restrict servname,
145 const struct addrinfo *restrict hints,
146 struct addrinfo **restrict res)
147 _GL_ARG_NONNULL ((4));
150 # if !@HAVE_DECL_FREEADDRINFO@
151 /* Free `addrinfo' structure AI including associated storage.
152 For more details, see the POSIX:2001 specification
153 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
154 extern void freeaddrinfo (struct addrinfo *ai) _GL_ARG_NONNULL ((1));
157 # if !@HAVE_DECL_GAI_STRERROR@
158 /* Convert error return from getaddrinfo() to a string.
159 For more details, see the POSIX:2001 specification
160 <http://www.opengroup.org/susv3xsh/gai_strerror.html>. */
161 extern const char *gai_strerror (int ecode);
164 # if !@HAVE_DECL_GETNAMEINFO@
165 /* Convert socket address to printable node and service names.
166 For more details, see the POSIX:2001 specification
167 <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */
168 extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
169 char *restrict node, socklen_t nodelen,
170 char *restrict service, socklen_t servicelen,
172 _GL_ARG_NONNULL ((1));
175 /* Possible flags for getnameinfo. */
176 # ifndef NI_NUMERICHOST
177 # define NI_NUMERICHOST 1
179 # ifndef NI_NUMERICSERV
180 # define NI_NUMERICSERV 2
183 #endif /* @GNULIB_GETADDRINFO@ */
185 #endif /* _GL_NETDB_H */
186 #endif /* _GL_NETDB_H */