xref: /minix3/external/bsd/bind/dist/lib/lwres/gai_strerror.c (revision 00b67f09dd46474d133c95011a48590a8e8f94c7)
1 /*	$NetBSD: gai_strerror.c,v 1.4 2014/12/10 04:38:02 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004-2007, 2014  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 2000, 2001  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Id: gai_strerror.c,v 1.22 2007/06/19 23:47:22 tbox Exp  */
21 
22 /*! \file gai_strerror.c
23  * lwres_gai_strerror() returns an error message corresponding to an
24  * error code returned by getaddrinfo(). The following error codes and
25  * their meaning are defined in \link netdb.h include/lwres/netdb.h.\endlink
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
34  * \li #EAI_NONAME hostname or servname not 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  *
39  * The message invalid error code is returned if ecode is out of range.
40  *
41  * ai_flags, ai_family and ai_socktype are elements of the struct
42  * addrinfo used by lwres_getaddrinfo().
43  *
44  * \section gai_strerror_see See Also
45  *
46  * strerror, lwres_getaddrinfo(), getaddrinfo(), RFC2133.
47  */
48 
49 #include <config.h>
50 
51 #include <lwres/netdb.h>
52 
53 /*% Text of error messages. */
54 static const char *gai_messages[] = {
55 	"no error",
56 	"address family for hostname not supported",
57 	"temporary failure in name resolution",
58 	"invalid value for ai_flags",
59 	"non-recoverable failure in name resolution",
60 	"ai_family not supported",
61 	"memory allocation failure",
62 	"no address associated with hostname",
63 	"hostname nor servname provided, or not known",
64 	"servname not supported for ai_socktype",
65 	"ai_socktype not supported",
66 	"system error returned in errno",
67 	"bad hints",
68 	"bad protocol",
69 	"overflow"
70 };
71 
72 /*% Returns an error message corresponding to an error code returned by getaddrinfo() */
73 char *
lwres_gai_strerror(int ecode)74 lwres_gai_strerror(int ecode) {
75 	union {
76 		const char *const_ptr;
77 		char *deconst_ptr;
78 	} ptr;
79 
80 	if ((ecode < 0) ||
81 	    (ecode >= (int)(sizeof(gai_messages)/sizeof(*gai_messages))))
82 		ptr.const_ptr = "invalid error code";
83 	else
84 		ptr.const_ptr = gai_messages[ecode];
85 	return (ptr.deconst_ptr);
86 }
87