Skip to content

Commit

Permalink
LibC: Add herror() and hstrerror()
Browse files Browse the repository at this point in the history
  • Loading branch information
cocateh authored and awesomekling committed May 12, 2022
1 parent bc18fa7 commit 6a7d300
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Userland/Libraries/LibC/netdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
}
}
4 changes: 4 additions & 0 deletions Userland/Libraries/LibC/netdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 6a7d300

Please sign in to comment.