2 * Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
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.
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.
17 /* $Id: gai_strerror.c,v 1.5 2009/09/02 23:48:02 tbox Exp $ */
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.
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)
43 * The message invalid error code is returned if ecode is out of range.
45 * ai_flags, ai_family and ai_socktype are elements of the struct
46 * addrinfo used by lwres_getaddrinfo().
48 * \section gai_strerror_see See Also
50 * strerror(), getaddrinfo(), getnameinfo(), RFC3493.
54 #include <irs/netdb.h>
56 /*% Text of error messages. */
57 static const char *gai_messages[] = {
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",
72 "argument buffer overflow",
73 "insecure data provided"
77 * Returns an error message corresponding to an error code returned by
78 * getaddrinfo() and getnameinfo()
80 IRS_GAISTRERROR_RETURN_T
81 gai_strerror(int ecode) {
83 const char *const_ptr;
88 (ecode >= (int)(sizeof(gai_messages)/sizeof(*gai_messages))))
89 ptr.const_ptr = "invalid error code";
91 ptr.const_ptr = gai_messages[ecode];
92 return (ptr.deconst_ptr);