xref: /netbsd-src/external/gpl3/gdb/dist/gnulib/import/netdb.in.h (revision 4b169a6ba595ae283ca507b26b15fdff40495b1c)
1*4b169a6bSchristos /* Provide a netdb.h header file for systems lacking it (read: MinGW).
2*4b169a6bSchristos    Copyright (C) 2008-2022 Free Software Foundation, Inc.
3*4b169a6bSchristos    Written by Simon Josefsson.
4*4b169a6bSchristos 
5*4b169a6bSchristos    This file is free software: you can redistribute it and/or modify
6*4b169a6bSchristos    it under the terms of the GNU Lesser General Public License as
7*4b169a6bSchristos    published by the Free Software Foundation; either version 2.1 of the
8*4b169a6bSchristos    License, or (at your option) any later version.
9*4b169a6bSchristos 
10*4b169a6bSchristos    This file is distributed in the hope that it will be useful,
11*4b169a6bSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*4b169a6bSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*4b169a6bSchristos    GNU Lesser General Public License for more details.
14*4b169a6bSchristos 
15*4b169a6bSchristos    You should have received a copy of the GNU Lesser General Public License
16*4b169a6bSchristos    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
17*4b169a6bSchristos 
18*4b169a6bSchristos /* This file is supposed to be used on platforms that lack <netdb.h>.
19*4b169a6bSchristos    It is intended to provide definitions and prototypes needed by an
20*4b169a6bSchristos    application.  */
21*4b169a6bSchristos 
22*4b169a6bSchristos #ifndef _@GUARD_PREFIX@_NETDB_H
23*4b169a6bSchristos 
24*4b169a6bSchristos #if __GNUC__ >= 3
25*4b169a6bSchristos @PRAGMA_SYSTEM_HEADER@
26*4b169a6bSchristos #endif
27*4b169a6bSchristos @PRAGMA_COLUMNS@
28*4b169a6bSchristos 
29*4b169a6bSchristos #if @HAVE_NETDB_H@
30*4b169a6bSchristos 
31*4b169a6bSchristos /* The include_next requires a split double-inclusion guard.  */
32*4b169a6bSchristos # @INCLUDE_NEXT@ @NEXT_NETDB_H@
33*4b169a6bSchristos 
34*4b169a6bSchristos #endif
35*4b169a6bSchristos 
36*4b169a6bSchristos #ifndef _@GUARD_PREFIX@_NETDB_H
37*4b169a6bSchristos #define _@GUARD_PREFIX@_NETDB_H
38*4b169a6bSchristos 
39*4b169a6bSchristos /* Get <netdb.h> definitions such as 'socklen_t' on IRIX 6.5 and OSF/1 4.0 and
40*4b169a6bSchristos    'struct hostent' on MinGW.  */
41*4b169a6bSchristos #include <sys/socket.h>
42*4b169a6bSchristos 
43*4b169a6bSchristos /* The definitions of _GL_FUNCDECL_RPL etc. are copied here.  */
44*4b169a6bSchristos 
45*4b169a6bSchristos /* The definition of _GL_ARG_NONNULL is copied here.  */
46*4b169a6bSchristos 
47*4b169a6bSchristos /* The definition of _GL_WARN_ON_USE is copied here.  */
48*4b169a6bSchristos 
49*4b169a6bSchristos /* Declarations for a platform that lacks <netdb.h>, or where it is
50*4b169a6bSchristos    incomplete.  */
51*4b169a6bSchristos 
52*4b169a6bSchristos #if @GNULIB_GETADDRINFO@
53*4b169a6bSchristos 
54*4b169a6bSchristos # if !@HAVE_STRUCT_ADDRINFO@
55*4b169a6bSchristos 
56*4b169a6bSchristos #  ifdef __cplusplus
57*4b169a6bSchristos extern "C" {
58*4b169a6bSchristos #  endif
59*4b169a6bSchristos 
60*4b169a6bSchristos #  if !GNULIB_defined_struct_addrinfo
61*4b169a6bSchristos /* Structure to contain information about address of a service provider.  */
62*4b169a6bSchristos struct addrinfo
63*4b169a6bSchristos {
64*4b169a6bSchristos   int ai_flags;                 /* Input flags.  */
65*4b169a6bSchristos   int ai_family;                /* Protocol family for socket.  */
66*4b169a6bSchristos   int ai_socktype;              /* Socket type.  */
67*4b169a6bSchristos   int ai_protocol;              /* Protocol for socket.  */
68*4b169a6bSchristos   socklen_t ai_addrlen;         /* Length of socket address.  */
69*4b169a6bSchristos   struct sockaddr *ai_addr;     /* Socket address for socket.  */
70*4b169a6bSchristos   char *ai_canonname;           /* Canonical name for service location.  */
71*4b169a6bSchristos   struct addrinfo *ai_next;     /* Pointer to next in list.  */
72*4b169a6bSchristos };
73*4b169a6bSchristos #   define GNULIB_defined_struct_addrinfo 1
74*4b169a6bSchristos #  endif
75*4b169a6bSchristos 
76*4b169a6bSchristos #  ifdef __cplusplus
77*4b169a6bSchristos }
78*4b169a6bSchristos #  endif
79*4b169a6bSchristos 
80*4b169a6bSchristos # endif
81*4b169a6bSchristos 
82*4b169a6bSchristos /* Possible values for 'ai_flags' field in 'addrinfo' structure.  */
83*4b169a6bSchristos # ifndef AI_PASSIVE
84*4b169a6bSchristos #  define AI_PASSIVE    0x0001  /* Socket address is intended for 'bind'.  */
85*4b169a6bSchristos # endif
86*4b169a6bSchristos # ifndef AI_CANONNAME
87*4b169a6bSchristos #  define AI_CANONNAME  0x0002  /* Request for canonical name.  */
88*4b169a6bSchristos # endif
89*4b169a6bSchristos # ifndef AI_NUMERICSERV
90*4b169a6bSchristos #  define AI_NUMERICSERV        0x0400  /* Don't use name resolution.  */
91*4b169a6bSchristos # endif
92*4b169a6bSchristos 
93*4b169a6bSchristos # if 0
94*4b169a6bSchristos #  define AI_NUMERICHOST        0x0004  /* Don't use name resolution.  */
95*4b169a6bSchristos # endif
96*4b169a6bSchristos 
97*4b169a6bSchristos /* These symbolic constants are required to be present by POSIX, but
98*4b169a6bSchristos    our getaddrinfo replacement doesn't use them (yet).  Setting them
99*4b169a6bSchristos    to 0 on systems that doesn't have them avoids causing problems for
100*4b169a6bSchristos    system getaddrinfo implementations that would be confused by
101*4b169a6bSchristos    unknown values.  */
102*4b169a6bSchristos # ifndef AI_V4MAPPED
103*4b169a6bSchristos #  define AI_V4MAPPED    0 /* 0x0008: IPv4 mapped addresses are acceptable.  */
104*4b169a6bSchristos # endif
105*4b169a6bSchristos # ifndef AI_ALL
106*4b169a6bSchristos #  define AI_ALL         0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
107*4b169a6bSchristos # endif
108*4b169a6bSchristos # ifndef AI_ADDRCONFIG
109*4b169a6bSchristos #  define AI_ADDRCONFIG  0 /* 0x0020: Use configuration of this host to choose
110*4b169a6bSchristos                                       returned address type.  */
111*4b169a6bSchristos # endif
112*4b169a6bSchristos 
113*4b169a6bSchristos /* Error values for 'getaddrinfo' function.  */
114*4b169a6bSchristos # ifndef EAI_BADFLAGS
115*4b169a6bSchristos #  define EAI_BADFLAGS    -1    /* Invalid value for 'ai_flags' field.  */
116*4b169a6bSchristos #  define EAI_NONAME      -2    /* NAME or SERVICE is unknown.  */
117*4b169a6bSchristos #  define EAI_AGAIN       -3    /* Temporary failure in name resolution.  */
118*4b169a6bSchristos #  define EAI_FAIL        -4    /* Non-recoverable failure in name res.  */
119*4b169a6bSchristos #  define EAI_NODATA      -5    /* No address associated with NAME.  */
120*4b169a6bSchristos #  define EAI_FAMILY      -6    /* 'ai_family' not supported.  */
121*4b169a6bSchristos #  define EAI_SOCKTYPE    -7    /* 'ai_socktype' not supported.  */
122*4b169a6bSchristos #  define EAI_SERVICE     -8    /* SERVICE not supported for 'ai_socktype'.  */
123*4b169a6bSchristos #  define EAI_MEMORY      -10   /* Memory allocation failure.  */
124*4b169a6bSchristos # endif
125*4b169a6bSchristos 
126*4b169a6bSchristos /* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
127*4b169a6bSchristos    FreeBSD, which does define EAI_BADFLAGS) have removed the definition
128*4b169a6bSchristos    in favor of EAI_NONAME.  */
129*4b169a6bSchristos # if !defined EAI_NODATA && defined EAI_NONAME
130*4b169a6bSchristos #  define EAI_NODATA EAI_NONAME
131*4b169a6bSchristos # endif
132*4b169a6bSchristos 
133*4b169a6bSchristos # ifndef EAI_OVERFLOW
134*4b169a6bSchristos /* Not defined on mingw32 and Haiku. */
135*4b169a6bSchristos #  define EAI_OVERFLOW    -12   /* Argument buffer overflow.  */
136*4b169a6bSchristos # endif
137*4b169a6bSchristos # ifndef EAI_ADDRFAMILY
138*4b169a6bSchristos /* Not defined on mingw32. */
139*4b169a6bSchristos #  define EAI_ADDRFAMILY  -9    /* Address family for NAME not supported.  */
140*4b169a6bSchristos # endif
141*4b169a6bSchristos # ifndef EAI_SYSTEM
142*4b169a6bSchristos /* Not defined on mingw32. */
143*4b169a6bSchristos #  define EAI_SYSTEM      -11   /* System error returned in 'errno'.  */
144*4b169a6bSchristos # endif
145*4b169a6bSchristos 
146*4b169a6bSchristos # if 0
147*4b169a6bSchristos /* The commented out definitions below are not yet implemented in the
148*4b169a6bSchristos    GNULIB getaddrinfo() replacement, so are not yet needed.
149*4b169a6bSchristos 
150*4b169a6bSchristos    If they are restored, be sure to protect the definitions with #ifndef.  */
151*4b169a6bSchristos #  ifndef EAI_INPROGRESS
152*4b169a6bSchristos #   define EAI_INPROGRESS       -100    /* Processing request in progress.  */
153*4b169a6bSchristos #   define EAI_CANCELED         -101    /* Request canceled.  */
154*4b169a6bSchristos #   define EAI_NOTCANCELED      -102    /* Request not canceled.  */
155*4b169a6bSchristos #   define EAI_ALLDONE          -103    /* All requests done.  */
156*4b169a6bSchristos #   define EAI_INTR             -104    /* Interrupted by a signal.  */
157*4b169a6bSchristos #   define EAI_IDN_ENCODE       -105    /* IDN encoding failed.  */
158*4b169a6bSchristos #  endif
159*4b169a6bSchristos # endif
160*4b169a6bSchristos 
161*4b169a6bSchristos /* Translate name of a service location and/or a service name to set of
162*4b169a6bSchristos    socket addresses.
163*4b169a6bSchristos    For more details, see the POSIX:2008 specification
164*4b169a6bSchristos    <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>.  */
165*4b169a6bSchristos # if @REPLACE_GETADDRINFO@
166*4b169a6bSchristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
167*4b169a6bSchristos #   undef getaddrinfo
168*4b169a6bSchristos #   define getaddrinfo rpl_getaddrinfo
169*4b169a6bSchristos #  endif
170*4b169a6bSchristos _GL_FUNCDECL_RPL (getaddrinfo, int,
171*4b169a6bSchristos                   (const char *restrict nodename,
172*4b169a6bSchristos                    const char *restrict servname,
173*4b169a6bSchristos                    const struct addrinfo *restrict hints,
174*4b169a6bSchristos                    struct addrinfo **restrict res)
175*4b169a6bSchristos                   _GL_ARG_NONNULL ((4)));
176*4b169a6bSchristos _GL_CXXALIAS_RPL (getaddrinfo, int,
177*4b169a6bSchristos                   (const char *restrict nodename,
178*4b169a6bSchristos                    const char *restrict servname,
179*4b169a6bSchristos                    const struct addrinfo *restrict hints,
180*4b169a6bSchristos                    struct addrinfo **restrict res));
181*4b169a6bSchristos # else
182*4b169a6bSchristos #  if !@HAVE_DECL_GETADDRINFO@
183*4b169a6bSchristos _GL_FUNCDECL_SYS (getaddrinfo, int,
184*4b169a6bSchristos                   (const char *restrict nodename,
185*4b169a6bSchristos                    const char *restrict servname,
186*4b169a6bSchristos                    const struct addrinfo *restrict hints,
187*4b169a6bSchristos                    struct addrinfo **restrict res)
188*4b169a6bSchristos                   _GL_ARG_NONNULL ((4)));
189*4b169a6bSchristos #  endif
190*4b169a6bSchristos _GL_CXXALIAS_SYS (getaddrinfo, int,
191*4b169a6bSchristos                   (const char *restrict nodename,
192*4b169a6bSchristos                    const char *restrict servname,
193*4b169a6bSchristos                    const struct addrinfo *restrict hints,
194*4b169a6bSchristos                    struct addrinfo **restrict res));
195*4b169a6bSchristos # endif
196*4b169a6bSchristos _GL_CXXALIASWARN (getaddrinfo);
197*4b169a6bSchristos 
198*4b169a6bSchristos /* Free 'addrinfo' structure AI including associated storage.
199*4b169a6bSchristos    For more details, see the POSIX:2008 specification
200*4b169a6bSchristos    <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getaddrinfo.html>.  */
201*4b169a6bSchristos # if @REPLACE_GETADDRINFO@
202*4b169a6bSchristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
203*4b169a6bSchristos #   undef freeaddrinfo
204*4b169a6bSchristos #   define freeaddrinfo rpl_freeaddrinfo
205*4b169a6bSchristos #  endif
206*4b169a6bSchristos _GL_FUNCDECL_RPL (freeaddrinfo, void, (struct addrinfo *ai)
207*4b169a6bSchristos                                       _GL_ARG_NONNULL ((1)));
208*4b169a6bSchristos _GL_CXXALIAS_RPL (freeaddrinfo, void, (struct addrinfo *ai));
209*4b169a6bSchristos # else
210*4b169a6bSchristos #  if !@HAVE_DECL_FREEADDRINFO@
211*4b169a6bSchristos _GL_FUNCDECL_SYS (freeaddrinfo, void, (struct addrinfo *ai)
212*4b169a6bSchristos                                       _GL_ARG_NONNULL ((1)));
213*4b169a6bSchristos #  endif
214*4b169a6bSchristos _GL_CXXALIAS_SYS (freeaddrinfo, void, (struct addrinfo *ai));
215*4b169a6bSchristos # endif
216*4b169a6bSchristos _GL_CXXALIASWARN (freeaddrinfo);
217*4b169a6bSchristos 
218*4b169a6bSchristos # if @REPLACE_GAI_STRERROR@
219*4b169a6bSchristos #  if !(defined __cplusplus && defined GNULIB_NAMESPACE)
220*4b169a6bSchristos #   undef gai_strerror
221*4b169a6bSchristos #   define gai_strerror rpl_gai_strerror
222*4b169a6bSchristos #  endif
223*4b169a6bSchristos _GL_FUNCDECL_RPL (gai_strerror, const char *, (int ecode));
224*4b169a6bSchristos _GL_CXXALIAS_RPL (gai_strerror, const char *, (int ecode));
225*4b169a6bSchristos # else
226*4b169a6bSchristos #  if !@HAVE_DECL_GAI_STRERROR@
227*4b169a6bSchristos /* Convert error return from getaddrinfo() to a string.
228*4b169a6bSchristos    For more details, see the POSIX:2008 specification
229*4b169a6bSchristos    <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gai_strerror.html>.  */
230*4b169a6bSchristos _GL_FUNCDECL_SYS (gai_strerror, const char *, (int ecode));
231*4b169a6bSchristos #  endif
232*4b169a6bSchristos _GL_CXXALIAS_SYS (gai_strerror, const char *, (int ecode));
233*4b169a6bSchristos # endif
234*4b169a6bSchristos # if __GLIBC__ >= 2
235*4b169a6bSchristos _GL_CXXALIASWARN (gai_strerror);
236*4b169a6bSchristos # endif
237*4b169a6bSchristos 
238*4b169a6bSchristos # if !@HAVE_DECL_GETNAMEINFO@
239*4b169a6bSchristos /* Convert socket address to printable node and service names.
240*4b169a6bSchristos    For more details, see the POSIX:2008 specification
241*4b169a6bSchristos    <https://pubs.opengroup.org/onlinepubs/9699919799/functions/getnameinfo.html>.  */
242*4b169a6bSchristos _GL_FUNCDECL_SYS (getnameinfo, int,
243*4b169a6bSchristos                   (const struct sockaddr *restrict sa, socklen_t salen,
244*4b169a6bSchristos                    char *restrict node, socklen_t nodelen,
245*4b169a6bSchristos                    char *restrict service, socklen_t servicelen,
246*4b169a6bSchristos                    int flags)
247*4b169a6bSchristos                   _GL_ARG_NONNULL ((1)));
248*4b169a6bSchristos # endif
249*4b169a6bSchristos /* Need to cast, because on glibc systems, the seventh parameter is
250*4b169a6bSchristos                         unsigned int flags.  */
251*4b169a6bSchristos _GL_CXXALIAS_SYS_CAST (getnameinfo, int,
252*4b169a6bSchristos                        (const struct sockaddr *restrict sa, socklen_t salen,
253*4b169a6bSchristos                         char *restrict node, socklen_t nodelen,
254*4b169a6bSchristos                         char *restrict service, socklen_t servicelen,
255*4b169a6bSchristos                         int flags));
256*4b169a6bSchristos _GL_CXXALIASWARN (getnameinfo);
257*4b169a6bSchristos 
258*4b169a6bSchristos /* Possible flags for getnameinfo.  */
259*4b169a6bSchristos # ifndef NI_NUMERICHOST
260*4b169a6bSchristos #  define NI_NUMERICHOST 1
261*4b169a6bSchristos # endif
262*4b169a6bSchristos # ifndef NI_NUMERICSERV
263*4b169a6bSchristos #  define NI_NUMERICSERV 2
264*4b169a6bSchristos # endif
265*4b169a6bSchristos 
266*4b169a6bSchristos #elif defined GNULIB_POSIXCHECK
267*4b169a6bSchristos 
268*4b169a6bSchristos # undef getaddrinfo
269*4b169a6bSchristos # if HAVE_RAW_DECL_GETADDRINFO
270*4b169a6bSchristos _GL_WARN_ON_USE (getaddrinfo, "getaddrinfo is unportable - "
271*4b169a6bSchristos                  "use gnulib module getaddrinfo for portability");
272*4b169a6bSchristos # endif
273*4b169a6bSchristos 
274*4b169a6bSchristos # undef freeaddrinfo
275*4b169a6bSchristos # if HAVE_RAW_DECL_FREEADDRINFO
276*4b169a6bSchristos _GL_WARN_ON_USE (freeaddrinfo, "freeaddrinfo is unportable - "
277*4b169a6bSchristos                  "use gnulib module getaddrinfo for portability");
278*4b169a6bSchristos # endif
279*4b169a6bSchristos 
280*4b169a6bSchristos # undef gai_strerror
281*4b169a6bSchristos # if HAVE_RAW_DECL_GAI_STRERROR
282*4b169a6bSchristos _GL_WARN_ON_USE (gai_strerror, "gai_strerror is unportable - "
283*4b169a6bSchristos                  "use gnulib module getaddrinfo for portability");
284*4b169a6bSchristos # endif
285*4b169a6bSchristos 
286*4b169a6bSchristos # undef getnameinfo
287*4b169a6bSchristos # if HAVE_RAW_DECL_GETNAMEINFO
288*4b169a6bSchristos _GL_WARN_ON_USE (getnameinfo, "getnameinfo is unportable - "
289*4b169a6bSchristos                  "use gnulib module getaddrinfo for portability");
290*4b169a6bSchristos # endif
291*4b169a6bSchristos 
292*4b169a6bSchristos #endif
293*4b169a6bSchristos 
294*4b169a6bSchristos #endif /* _@GUARD_PREFIX@_NETDB_H */
295*4b169a6bSchristos #endif /* _@GUARD_PREFIX@_NETDB_H */
296