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