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