diff options
author | Michaล Lach <m.lach2003@gmail.com> | 2022-05-10 13:01:40 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-05-12 15:01:32 +0200 |
commit | 6a7d3006d74b9c47207c94a1b0d3e5035a57b6a8 (patch) | |
tree | 35afd600917e61e4c52866a63408fab5c2309b6d /Userland | |
parent | bc18fa75ecf000e9771ec6b4835d9241122fdd31 (diff) | |
download | serenity-6a7d3006d74b9c47207c94a1b0d3e5035a57b6a8.zip |
LibC: Add herror() and hstrerror()
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibC/netdb.cpp | 22 | ||||
-rw-r--r-- | Userland/Libraries/LibC/netdb.h | 4 |
2 files changed, 26 insertions, 0 deletions
diff --git a/Userland/Libraries/LibC/netdb.cpp b/Userland/Libraries/LibC/netdb.cpp index 96b934a662..69e9e3e992 100644 --- a/Userland/Libraries/LibC/netdb.cpp +++ b/Userland/Libraries/LibC/netdb.cpp @@ -829,4 +829,26 @@ int getnameinfo(const struct sockaddr* __restrict addr, socklen_t addrlen, char* return 0; } + +void herror(char const* s) +{ + dbgln("herror(): {}: {}", s, hstrerror(h_errno)); + warnln("{}: {}", s, hstrerror(h_errno)); +} + +char const* hstrerror(int err) +{ + switch (err) { + case HOST_NOT_FOUND: + return "The specified host is unknown."; + case NO_DATA: + return "The requested name is valid but does not have an IP address."; + case NO_RECOVERY: + return "A nonrecoverable name server error occurred."; + case TRY_AGAIN: + return "A temporary error occurred on an authoritative name server. Try again later."; + default: + return "Unknown error."; + } +} } diff --git a/Userland/Libraries/LibC/netdb.h b/Userland/Libraries/LibC/netdb.h index 8fff8cc471..b825f63182 100644 --- a/Userland/Libraries/LibC/netdb.h +++ b/Userland/Libraries/LibC/netdb.h @@ -56,6 +56,7 @@ extern __thread int h_errno; #define HOST_NOT_FOUND 101 #define NO_DATA 102 +#define NO_ADDRESS NO_DATA #define NO_RECOVERY 103 #define TRY_AGAIN 104 @@ -105,4 +106,7 @@ void freeaddrinfo(struct addrinfo* res); char const* gai_strerror(int errcode); int getnameinfo(const struct sockaddr* __restrict addr, socklen_t addrlen, char* __restrict host, socklen_t hostlen, char* __restrict serv, socklen_t servlen, int flags); +void herror(char const* s); +char const* hstrerror(int err); + __END_DECLS |