4 * Copyright (C) 2004-2007 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000, 2001 Internet Software Consortium.
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.
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.
20 /* Id: gai_strerror.c,v 1.22 2007/06/19 23:47:22 tbox Exp */
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
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
39 * The message invalid error code is returned if ecode is out of range.
41 * ai_flags, ai_family and ai_socktype are elements of the struct
42 * addrinfo used by lwres_getaddrinfo().
44 * \section gai_strerror_see See Also
46 * strerror, lwres_getaddrinfo(), getaddrinfo(), RFC2133.
51 #include <lwres/netdb.h>
53 /*% Text of error messages. */
54 static const char *gai_messages
[] = {
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",
71 /*% Returns an error message corresponding to an error code returned by getaddrinfo() */
73 lwres_gai_strerror(int ecode
) {
75 const char *const_ptr
;
80 (ecode
>= (int)(sizeof(gai_messages
)/sizeof(*gai_messages
))))
81 ptr
.const_ptr
= "invalid error code";
83 ptr
.const_ptr
= gai_messages
[ecode
];
84 return (ptr
.deconst_ptr
);