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