lib/netdb.in.h: Don't define GNU specific constants.
[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@
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>.  */
49
50 #if @GNULIB_GETADDRINFO@
51
52 # ifndef HAVE_STRUCT_ADDRINFO
53
54 /* Structure to contain information about address of a service provider.  */
55 struct addrinfo
56 {
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.  */
65 };
66 # endif
67
68 /* Possible values for `ai_flags' field in `addrinfo' structure.  */
69 # ifndef AI_PASSIVE
70 #  define AI_PASSIVE    0x0001  /* Socket address is intended for `bind'.  */
71 # endif
72 # ifndef AI_CANONNAME
73 #  define AI_CANONNAME  0x0002  /* Request for canonical name.  */
74 # endif
75 # ifndef AI_NUMERICSERV
76 #  define AI_NUMERICSERV        0x0400  /* Don't use name resolution.  */
77 # endif
78
79 # if 0
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
83    define them.
84
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..  */
91 # endif /* 0 */
92
93 /* Error values for `getaddrinfo' function.  */
94 # ifndef EAI_BADFLAGS
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.  */
104 # endif
105
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
111 # endif
112
113 # ifndef EAI_OVERFLOW
114 /* Not defined on mingw32. */
115 #  define EAI_OVERFLOW    -12   /* Argument buffer overflow.  */
116 # endif
117 # ifndef EAI_ADDRFAMILY
118 /* Not defined on mingw32. */
119 #  define EAI_ADDRFAMILY  -9    /* Address family for NAME not supported.  */
120 # endif
121 # ifndef EAI_SYSTEM
122 /* Not defined on mingw32. */
123 #  define EAI_SYSTEM      -11   /* System error returned in `errno'.  */
124 # endif
125
126 # if 0
127 /* The commented out definitions below are not yet implemented in the
128    GNULIB getaddrinfo() replacement, so are not yet needed.
129
130    If they are restored, be sure to protect the definitions with #ifndef.  */
131 #  ifndef EAI_INPROGRESS
132 #   define EAI_INPROGRESS       -100    /* Processing request in progress.  */
133 #   define EAI_CANCELED         -101    /* Request canceled.  */
134 #   define EAI_NOTCANCELED      -102    /* Request not canceled.  */
135 #   define EAI_ALLDONE          -103    /* All requests done.  */
136 #   define EAI_INTR             -104    /* Interrupted by a signal.  */
137 #   define EAI_IDN_ENCODE       -105    /* IDN encoding failed.  */
138 #  endif
139 # endif
140
141 # if !HAVE_DECL_GETADDRINFO
142 /* Translate name of a service location and/or a service name to set of
143    socket addresses.
144    For more details, see the POSIX:2001 specification
145    <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
146 extern int getaddrinfo (const char *restrict nodename,
147                         const char *restrict servname,
148                         const struct addrinfo *restrict hints,
149                         struct addrinfo **restrict res);
150 # endif
151
152 # if !HAVE_DECL_FREEADDRINFO
153 /* Free `addrinfo' structure AI including associated storage.
154    For more details, see the POSIX:2001 specification
155    <http://www.opengroup.org/susv3xsh/getaddrinfo.html>.  */
156 extern void freeaddrinfo (struct addrinfo *ai);
157 # endif
158
159 # if !HAVE_DECL_GAI_STRERROR
160 /* Convert error return from getaddrinfo() to a string.
161    For more details, see the POSIX:2001 specification
162    <http://www.opengroup.org/susv3xsh/gai_strerror.html>.  */
163 extern const char *gai_strerror (int ecode);
164 # endif
165
166 # if !HAVE_DECL_GETNAMEINFO
167 /* Convert socket address to printable node and service names.
168    For more details, see the POSIX:2001 specification
169    <http://www.opengroup.org/susv3xsh/getnameinfo.html>.  */
170 extern int getnameinfo(const struct sockaddr *restrict sa, socklen_t salen,
171                        char *restrict node, socklen_t nodelen,
172                        char *restrict service, socklen_t servicelen,
173                        int flags);
174 # endif
175
176 /* Possible flags for getnameinfo.  */
177 # ifndef NI_NUMERICHOST
178 #  define NI_NUMERICHOST 1
179 # endif
180 # ifndef NI_NUMERICSERV
181 #  define NI_NUMERICSERV 2
182 # endif
183
184 #endif /* @GNULIB_GETADDRINFO@ */
185
186 #endif /* HAVE_NETDB_H */
187
188 #endif /* _GL_NETDB_H */
189 #endif /* _GL_NETDB_H */