]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/bind9/lib/irs/gai_strerror.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / bind9 / lib / irs / gai_strerror.c
1 /*
2  * Copyright (C) 2009  Internet Systems Consortium, Inc. ("ISC")
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
9  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
11  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
13  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14  * PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 /* $Id: gai_strerror.c,v 1.5 2009/09/02 23:48:02 tbox Exp $ */
18
19 /*! \file gai_strerror.c
20  * gai_strerror() returns an error message corresponding to an
21  * error code returned by getaddrinfo() and getnameinfo(). The following error
22  * codes and their meaning are defined in
23  * \link netdb.h include/irs/netdb.h.\endlink
24  * This implementation is almost an exact copy of lwres/gai_sterror.c except
25  * that it catches up the latest API standard, RFC3493.
26  *
27  * \li #EAI_ADDRFAMILY address family for hostname not supported
28  * \li #EAI_AGAIN temporary failure in name resolution
29  * \li #EAI_BADFLAGS invalid value for ai_flags
30  * \li #EAI_FAIL non-recoverable failure in name resolution
31  * \li #EAI_FAMILY ai_family not supported
32  * \li #EAI_MEMORY memory allocation failure
33  * \li #EAI_NODATA no address associated with hostname (obsoleted in RFC3493)
34  * \li #EAI_NONAME hostname nor servname provided, or not known
35  * \li #EAI_SERVICE servname not supported for ai_socktype
36  * \li #EAI_SOCKTYPE ai_socktype not supported
37  * \li #EAI_SYSTEM system error returned in errno
38  * \li #EAI_BADHINTS Invalid value for hints (non-standard)
39  * \li #EAI_PROTOCOL Resolved protocol is unknown (non-standard)
40  * \li #EAI_OVERFLOW Argument buffer overflow
41  * \li #EAI_INSECUREDATA Insecure Data (experimental)
42  *
43  * The message invalid error code is returned if ecode is out of range.
44  *
45  * ai_flags, ai_family and ai_socktype are elements of the struct
46  * addrinfo used by lwres_getaddrinfo().
47  *
48  * \section gai_strerror_see See Also
49  *
50  * strerror(), getaddrinfo(), getnameinfo(), RFC3493.
51  */
52 #include <config.h>
53
54 #include <irs/netdb.h>
55
56 /*% Text of error messages. */
57 static const char *gai_messages[] = {
58         "no error",
59         "address family for hostname not supported",
60         "temporary failure in name resolution",
61         "invalid value for ai_flags",
62         "non-recoverable failure in name resolution",
63         "ai_family not supported",
64         "memory allocation failure",
65         "no address associated with hostname",
66         "hostname nor servname provided, or not known",
67         "servname not supported for ai_socktype",
68         "ai_socktype not supported",
69         "system error returned in errno",
70         "bad hints",
71         "bad protocol",
72         "argument buffer overflow",
73         "insecure data provided"
74 };
75
76 /*%
77  * Returns an error message corresponding to an error code returned by
78  * getaddrinfo() and getnameinfo()
79  */
80 IRS_GAISTRERROR_RETURN_T
81 gai_strerror(int ecode) {
82         union {
83                 const char *const_ptr;
84                 char *deconst_ptr;
85         } ptr;
86
87         if ((ecode < 0) ||
88             (ecode >= (int)(sizeof(gai_messages)/sizeof(*gai_messages))))
89                 ptr.const_ptr = "invalid error code";
90         else
91                 ptr.const_ptr = gai_messages[ecode];
92         return (ptr.deconst_ptr);
93 }