Skip to content

Commit c5c371e

Browse files
committed
implement gai_strerror
1 parent 4e6349c commit c5c371e

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <netdb.h>
2+
3+
static const struct
4+
{
5+
const int code;
6+
const char *error_string;
7+
}
8+
gai_errors[] =
9+
{
10+
{ EAI_ADDRFAMILY, "address family for hostname not supported" },
11+
{ EAI_AGAIN, "temporary failure in name resolution" },
12+
{ EAI_BADFLAGS, "invalid value for ai_flags" },
13+
{ EAI_FAIL, "non-recoverable failure in name resolution" },
14+
{ EAI_FAMILY, "ai_family not supported" },
15+
{ EAI_MEMORY, "memory allocation failure" },
16+
{ EAI_NODATA, "no address associated with hostname" },
17+
{ EAI_NONAME, "hostname nor servname provided, or not known" },
18+
{ EAI_SERVICE, "servname not supported for ai_socktype" },
19+
{ EAI_SOCKTYPE, "ai_socktype not supported" },
20+
{ EAI_SYSTEM, "system error returned in errno" },
21+
{ EAI_BADHINTS, "invalid value for hints" },
22+
{ EAI_PROTOCOL, "resolved protocol is unknown" },
23+
{ EAI_OVERFLOW, "argument buffer overflow" },
24+
};
25+
26+
const char *gai_strerror (int code)
27+
{
28+
const char *result = "unknown error";
29+
for (size_t i = 0; i < sizeof (gai_errors) / sizeof (gai_errors[0]); ++i)
30+
if (gai_errors[i].code == code)
31+
{
32+
result = gai_errors[i].error_string;
33+
break;
34+
}
35+
36+
return result;
37+
}

0 commit comments

Comments
 (0)