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