2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "namespace.h"
43 #include "reentrant.h"
45 #include "un-namespace.h"
48 * Entries EAI_ADDRFAMILY (1) and EAI_NODATA (7) were omitted from RFC 3493,
49 * but are or may be used as extensions or in old code.
51 static const char *ai_errlist[] = {
53 "Address family for hostname not supported", /* EAI_ADDRFAMILY */
54 "Name could not be resolved at this time", /* EAI_AGAIN */
55 "Flags parameter had an invalid value", /* EAI_BADFLAGS */
56 "Non-recoverable failure in name resolution", /* EAI_FAIL */
57 "Address family not recognized", /* EAI_FAMILY */
58 "Memory allocation failure", /* EAI_MEMORY */
59 "No address associated with hostname", /* EAI_NODATA*/
60 "Name does not resolve", /* EAI_NONAME */
61 "Service was not recognized for socket type", /* EAI_SERVICE */
62 "Intended socket type was not recognized", /* EAI_SOCKTYPE */
63 "System error returned in errno", /* EAI_SYSTEM */
64 "Invalid value for hints", /* EAI_BADHINTS */
65 "Resolved protocol is unknown", /* EAI_PROTOCOL */
66 "Argument buffer overflow" /* EAI_OVERFLOW */
70 static char gai_buf[NL_TEXTMAX];
71 static once_t gai_init_once = ONCE_INITIALIZER;
72 static thread_key_t gai_key;
73 static int gai_keycreated = 0;
78 gai_keycreated = (thr_keycreate(&gai_key, free) == 0);
83 gai_strerror(int ecode)
92 if (thr_once(&gai_init_once, gai_keycreate) != 0 ||
95 if ((buf = thr_getspecific(gai_key)) == NULL) {
96 if ((buf = malloc(sizeof(gai_buf))) == NULL)
98 if (thr_setspecific(gai_key, buf) != 0) {
105 catd = catopen("libc", NL_CAT_LOCALE);
106 if (ecode > 0 && ecode < EAI_MAX)
107 strlcpy(buf, catgets(catd, 3, ecode, ai_errlist[ecode]),
110 strlcpy(buf, catgets(catd, 3, NL_MSGMAX - 1, "Success"),
113 strlcpy(buf, catgets(catd, 3, NL_MSGMAX, "Unknown error"),
120 if (ecode >= 0 && ecode < EAI_MAX)
121 return ai_errlist[ecode];
122 return "Unknown error";