Skip to content

Commit

Permalink
return getaddrinfo results in order
Browse files Browse the repository at this point in the history
Also, stub out other netdb functions so they return errors instead of aborting.

Signed-off-by: Joel Dice <[email protected]>
  • Loading branch information
dicej committed Dec 19, 2023
1 parent 0b50784 commit 1db6e1a
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ static int map_error(ip_name_lookup_error_code_t error)

int getaddrinfo(const char* restrict host, const char* restrict serv, const struct addrinfo* restrict hint, struct addrinfo** restrict res)
{
if (host == NULL) {
host = "localhost";
}

*res = NULL;
struct addrinfo* current = NULL;
imports_string_t name = { .ptr = (uint8_t*) host, .len = strlen(host) };
ip_name_lookup_own_resolve_address_stream_t stream;
ip_name_lookup_error_code_t error;
Expand Down Expand Up @@ -116,9 +121,16 @@ int getaddrinfo(const char* restrict host, const char* restrict serv, const stru
.ai_addrlen = addrlen,
.ai_addr = addr,
.ai_canonname = NULL,
.ai_next = *res
.ai_next = NULL,
};
*res = result;

if (current) {
current->ai_next = result;
current = result;
} else {
current = result;
*res = result;
}
} else {
return 0;
}
Expand Down Expand Up @@ -156,36 +168,36 @@ int getnameinfo(const struct sockaddr* restrict sa, socklen_t salen, char* restr
struct hostent* gethostbyname(const char* name)
{
// TODO
abort();
return NULL;
}

struct hostent* gethostbyaddr(const void* addr, socklen_t len, int type)
{
// TODO
abort();
return NULL;
}

const char* hstrerror(int err)
{
// TODO
abort();
return "hstrerror: TODO";
}

struct servent* getservbyname(const char* name, const char* proto)
{
// TODO
abort();
return NULL;
}

struct servent* getservbyport(int port, const char* proto)
{
// TODO
abort();
return NULL;
}

struct protoent* getprotobyname(const char* name)
{
// TODO
abort();
return NULL;
}
#endif // __wasilibc_use_preview2

0 comments on commit 1db6e1a

Please sign in to comment.