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 https://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 * lwres_gai_strerror() returns an error message corresponding to an
14 * error code returned by getaddrinfo(). The following error codes and
15 * their meaning are defined in \link netdb.h include/lwres/netdb.h.\endlink
16 *
17 * \li #EAI_ADDRFAMILY address family for hostname not supported
18 * \li #EAI_AGAIN temporary failure in name resolution
19 * \li #EAI_BADFLAGS invalid value for #ai_flags
20 * \li #EAI_FAIL non-recoverable failure in name resolution
21 * \li #EAI_FAMILY ai_family not supported
22 * \li #EAI_MEMORY memory allocation failure
23 * \li #EAI_NODATA no address associated with hostname
24 * \li #EAI_NONAME hostname or servname not provided, or not known
25 * \li #EAI_SERVICE servname not supported for ai_socktype
26 * \li #EAI_SOCKTYPE ai_socktype not supported
27 * \li #EAI_SYSTEM system error returned in errno
28 *
29 * The message invalid error code is returned if ecode is out of range.
30 *
31 * ai_flags, ai_family and ai_socktype are elements of the struct
32 * addrinfo used by lwres_getaddrinfo().
33 *
34 * \section gai_strerror_see See Also
35 *
36 * strerror, lwres_getaddrinfo(), getaddrinfo(), RFC2133.
37 */
38
39 #include <config.h>
40
41 #include <lwres/netdb.h>
42
43 /*% Text of error messages. */
44 static const char *gai_messages[] = {
45 "no error",
46 "address family for hostname not supported",
47 "temporary failure in name resolution",
48 "invalid value for ai_flags",
49 "non-recoverable failure in name resolution",
50 "ai_family not supported",
51 "memory allocation failure",
52 "no address associated with hostname",
53 "hostname nor servname provided, or not known",
54 "servname not supported for ai_socktype",
55 "ai_socktype not supported",
56 "system error returned in errno",
57 "bad hints",
58 "bad protocol",
59 "overflow"
60 };
61
62 /*% Returns an error message corresponding to an error code returned by getaddrinfo() */
63 char *
lwres_gai_strerror(int ecode)64 lwres_gai_strerror(int ecode) {
65 union {
66 const char *const_ptr;
67 char *deconst_ptr;
68 } ptr;
69
70 if ((ecode < 0) ||
71 (ecode >= (int)(sizeof(gai_messages)/sizeof(*gai_messages))))
72 ptr.const_ptr = "invalid error code";
73 else
74 ptr.const_ptr = gai_messages[ecode];
75 return (ptr.deconst_ptr);
76 }
77