"Fossies" - the Fresh Open Source Software Archive

Member "bind-9.16.7/lib/irs/gai_strerror.c" (4 Sep 2020, 3236 Bytes) of package /linux/misc/dns/bind9/9.16.7/bind-9.16.7.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "gai_strerror.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
    3  *
    4  * This Source Code Form is subject to the terms of the Mozilla Public
    5  * License, v. 2.0. If a copy of the MPL was not distributed with this
    6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
    7  *
    8  * See the COPYRIGHT file distributed with this work for additional
    9  * information regarding copyright ownership.
   10  */
   11 
   12 /*! \file gai_strerror.c
   13  * gai_strerror() returns an error message corresponding to an
   14  * error code returned by getaddrinfo() and getnameinfo(). The following error
   15  * codes and their meaning are defined in
   16  * \link netdb.h include/irs/netdb.h.\endlink
   17  * This implementation is almost an exact copy of lwres/gai_sterror.c except
   18  * that it catches up the latest API standard, RFC3493.
   19  *
   20  * \li #EAI_ADDRFAMILY address family for hostname not supported
   21  * \li #EAI_AGAIN temporary failure in name resolution
   22  * \li #EAI_BADFLAGS invalid value for ai_flags
   23  * \li #EAI_FAIL non-recoverable failure in name resolution
   24  * \li #EAI_FAMILY ai_family not supported
   25  * \li #EAI_MEMORY memory allocation failure
   26  * \li #EAI_NODATA no address associated with hostname (obsoleted in RFC3493)
   27  * \li #EAI_NONAME hostname nor servname provided, or not known
   28  * \li #EAI_SERVICE servname not supported for ai_socktype
   29  * \li #EAI_SOCKTYPE ai_socktype not supported
   30  * \li #EAI_SYSTEM system error returned in errno
   31  * \li #EAI_BADHINTS Invalid value for hints (non-standard)
   32  * \li #EAI_PROTOCOL Resolved protocol is unknown (non-standard)
   33  * \li #EAI_OVERFLOW Argument buffer overflow
   34  * \li #EAI_INSECUREDATA Insecure Data (experimental)
   35  *
   36  * The message invalid error code is returned if ecode is out of range.
   37  *
   38  * ai_flags, ai_family and ai_socktype are elements of the struct
   39  * addrinfo used by lwres_getaddrinfo().
   40  *
   41  * \section gai_strerror_see See Also
   42  *
   43  * strerror(), getaddrinfo(), getnameinfo(), RFC3493.
   44  */
   45 
   46 #include <isc/net.h>
   47 
   48 #include <irs/netdb.h>
   49 
   50 /*% Text of error messages. */
   51 static const char *gai_messages[] = { "no error",
   52                       "address family for hostname not "
   53                       "supported",
   54                       "temporary failure in name resolution",
   55                       "invalid value for ai_flags",
   56                       "non-recoverable failure in name "
   57                       "resolution",
   58                       "ai_family not supported",
   59                       "memory allocation failure",
   60                       "no address associated with hostname",
   61                       "hostname nor servname provided, or not "
   62                       "known",
   63                       "servname not supported for ai_socktype",
   64                       "ai_socktype not supported",
   65                       "system error returned in errno",
   66                       "bad hints",
   67                       "bad protocol",
   68                       "argument buffer overflow",
   69                       "insecure data provided" };
   70 
   71 /*%
   72  * Returns an error message corresponding to an error code returned by
   73  * getaddrinfo() and getnameinfo()
   74  */
   75 #if defined _WIN32
   76 char *
   77 #else  /* if defined _WIN32 */
   78 const char *
   79 #endif /* if defined _WIN32 */
   80 gai_strerror(int ecode) {
   81     union {
   82         const char *const_ptr;
   83         char *deconst_ptr;
   84     } ptr;
   85 
   86     if ((ecode < 0) ||
   87         (ecode >= (int)(sizeof(gai_messages) / sizeof(*gai_messages))))
   88     {
   89         ptr.const_ptr = "invalid error code";
   90     } else {
   91         ptr.const_ptr = gai_messages[ecode];
   92     }
   93     return (ptr.deconst_ptr);
   94 }