1 /* Provide a netdb.h header file for systems lacking it (read: MinGW).
2 Copyright (C) 2008 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@
41 /* Declarations for a platform that has <netdb.h>. */
45 /* Get netdb.h definitions such as struct hostent for MinGW. */
46 #include <sys/socket.h>
48 /* Declarations for a platform that lacks <netdb.h>. */
50 #if @GNULIB_GETADDRINFO@
52 # ifndef HAVE_STRUCT_ADDRINFO
54 /* Structure to contain information about address of a service provider. */
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. */
68 /* Possible values for `ai_flags' field in `addrinfo' structure. */
70 # define AI_PASSIVE 0x0001 /* Socket address is intended for `bind'. */
73 # define AI_CANONNAME 0x0002 /* Request for canonical name. */
75 # ifndef AI_NUMERICSERV
76 # define AI_NUMERICSERV 0x0400 /* Don't use name resolution. */
80 /* The commented out definitions below are not yet implemented in the
81 GNULIB getaddrinfo() replacement, so are not yet needed and may, in fact,
82 cause conflicts on systems with a getaddrinfo() function which does not
85 If they are restored, be sure to protect the definitions with #ifndef. */
86 # define AI_NUMERICHOST 0x0004 /* Don't use name resolution. */
87 # define AI_V4MAPPED 0x0008 /* IPv4 mapped addresses are acceptable. */
88 # define AI_ALL 0x0010 /* Return IPv4 mapped and IPv6 addresses. */
89 # define AI_ADDRCONFIG 0x0020 /* Use configuration of this host to choose
90 returned address type.. */
93 /* Error values for `getaddrinfo' function. */
95 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
96 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
97 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
98 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
99 # define EAI_NODATA -5 /* No address associated with NAME. */
100 # define EAI_FAMILY -6 /* `ai_family' not supported. */
101 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
102 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
103 # define EAI_MEMORY -10 /* Memory allocation failure. */
106 /* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
107 FreeBSD, which does define EAI_BADFLAGS) have removed the definition
108 in favor of EAI_NONAME. */
109 # if !defined EAI_NODATA && defined EAI_NONAME
110 # define EAI_NODATA EAI_NONAME
113 # ifndef EAI_OVERFLOW
114 /* Not defined on mingw32. */
115 # define EAI_OVERFLOW -12 /* Argument buffer overflow. */
117 # ifndef EAI_ADDRFAMILY
118 /* Not defined on mingw32. */
119 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
122 /* Not defined on mingw32. */
123 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
127 # ifndef EAI_INPROGRESS
128 # define EAI_INPROGRESS -100 /* Processing request in progress. */
129 # define EAI_CANCELED -101 /* Request canceled. */
130 # define EAI_NOTCANCELED -102 /* Request not canceled. */
131 # define EAI_ALLDONE -103 /* All requests done. */
132 # define EAI_INTR -104 /* Interrupted by a signal. */
133 # define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
137 # if !HAVE_DECL_GETADDRINFO
138 /* Translate name of a service location and/or a service name to set of
140 For more details, see the POSIX:2001 specification
141 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
142 extern int getaddrinfo (const char *restrict nodename,
143 const char *restrict servname,
144 const struct addrinfo *restrict hints,
145 struct addrinfo **restrict res);
148 # if !HAVE_DECL_FREEADDRINFO
149 /* Free `addrinfo' structure AI including associated storage.
150 For more details, see the POSIX:2001 specification
151 <http://www.opengroup.org/susv3xsh/getaddrinfo.html>. */
152 extern void freeaddrinfo (struct addrinfo *ai);
155 # if !HAVE_DECL_GAI_STRERROR
156 /* Convert error return from getaddrinfo() to a string.
157 For more details, see the POSIX:2001 specification
158 <http://www.opengroup.org/susv3xsh/gai_strerror.html>. */
159 extern const char *gai_strerror (int ecode);
162 # if !HAVE_DECL_GETNAMEINFO
163 /* Convert socket address to printable node and service names.
164 For more details, see the POSIX:2001 specification
165 <http://www.opengroup.org/susv3xsh/getnameinfo.html>. */
166 extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
167 char *restrict node, socklen_t nodelen,
168 char *restrict service, socklen_t servicelen,
172 /* Possible flags for getnameinfo. */
173 # ifndef NI_NUMERICHOST
174 # define NI_NUMERICHOST 1
176 # ifndef NI_NUMERICSERV
177 # define NI_NUMERICSERV 2
180 #endif /* @GNULIB_GETADDRINFO@ */
182 #endif /* HAVE_NETDB_H */
184 #endif /* _GL_NETDB_H */
185 #endif /* _GL_NETDB_H */