1 /* Copyright (C) 1997,2001,02 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Philip Blundell <pjb27@cam.ac.uk>, 1997.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA
18 02110-1335, USA. */
19
20 #include <netdb.h>
21
22 /* It's possible that <netdb.h> doesn't define EAI_ values. */
23
24 #ifndef EAI_BADFLAGS
25 # define EAI_BADFLAGS -1 /* Invalid value for `ai_flags' field. */
26 #endif
27
28 #ifndef EAI_NONAME
29 # define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
30 #endif
31
32 #ifndef EAI_AGAIN
33 # define EAI_AGAIN -3 /* Temporary failure in name resolution. */
34 #endif
35
36 #ifndef EAI_FAIL
37 # define EAI_FAIL -4 /* Non-recoverable failure in name res. */
38 #endif
39
40 #ifndef EAI_NODATA
41 # define EAI_NODATA -5 /* No address associated with NAME. */
42 #endif
43
44 #ifndef EAI_FAMILY
45 # define EAI_FAMILY -6 /* `ai_family' not supported. */
46 #endif
47
48 #ifndef EAI_SOCKTYPE
49 # define EAI_SOCKTYPE -7 /* `ai_socktype' not supported. */
50 #endif
51
52 #ifndef EAI_SERVICE
53 # define EAI_SERVICE -8 /* SERVICE not supported for `ai_socktype'. */
54 #endif
55
56 #ifndef EAI_ADDRFAMILY
57 # define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
58 #endif
59
60 #ifndef EAI_MEMORY
61 # define EAI_MEMORY -10 /* Memory allocation failure. */
62 #endif
63
64 #ifndef EAI_SYSTEM
65 # define EAI_SYSTEM -11 /* System error returned in `errno'. */
66 #endif
67
68 /* GNU-specific EAI values. */
69
70 #ifndef EAI_INPROGRESS
71 # define EAI_INPROGRESS -100 /* Processing request in progress. */
72 #endif
73
74 #ifndef EAI_CANCELED
75 # define EAI_CANCELED -101 /* Request canceled. */
76 #endif
77
78 #ifndef EAI_NOTCANCELED
79 # define EAI_NOTCANCELED -102 /* Request not canceled. */
80 #endif
81
82 #ifndef EAI_ALLDONE
83 # define EAI_ALLDONE -103 /* All requests done. */
84 #endif
85
86 #ifndef EAI_INTR
87 # define EAI_INTR -104 /* Interrupted by a signal. */
88 #endif
89
90 static struct {
91 int code;
92 const char *msg;
93
94 } values[] = {
95
96 { EAI_ADDRFAMILY, "Address family for hostname not supported" },
97 { EAI_AGAIN, "Temporary failure in name resolution" },
98 { EAI_BADFLAGS, "Bad value for ai_flags" },
99 { EAI_FAIL, "Non-recoverable failure in name resolution" },
100 { EAI_FAMILY, "ai_family not supported" },
101 { EAI_MEMORY, "Memory allocation failure" },
102 { EAI_NODATA, "No address associated with hostname" },
103 { EAI_NONAME, "Name or service not known" },
104 { EAI_SERVICE, "Servname not supported for ai_socktype" },
105 { EAI_SOCKTYPE, "ai_socktype not supported" },
106 { EAI_SYSTEM, "System error" },
107 { EAI_INPROGRESS, "Processing request in progress" },
108 { EAI_CANCELED, "Request canceled" },
109 { EAI_NOTCANCELED, "Request not canceled" },
110 { EAI_ALLDONE, "All requests done" },
111 { EAI_INTR, "Interrupted by a signal" }
112 };
113
pr_gai_strerror(int code)114 const char *pr_gai_strerror(int code) {
115 register unsigned int i;
116 for (i = 0; i < sizeof(values) / sizeof(values[0]); ++i)
117 if (values[i].code == code)
118 return values[i].msg;
119
120 return "Unknown error";
121 }
122