From 1db6e1a51d24d5a102d051c6617b6c4f088ff867 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 19 Dec 2023 13:42:47 -0700 Subject: [PATCH] return `getaddrinfo` results in order Also, stub out other netdb functions so they return errors instead of aborting. Signed-off-by: Joel Dice --- .../cloudlibc/src/libc/sys/socket/netdb.c | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c index 5e9ada012..6453585cc 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/socket/netdb.c @@ -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; @@ -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; } @@ -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