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