summaryrefslogtreecommitdiff
path: root/libc-top-half
diff options
context:
space:
mode:
authorwayne warren <wayne.warren.s@gmail.com>2023-05-22 11:23:37 -0600
committerwayne warren <wayne.warren.s@gmail.com>2023-05-24 11:14:23 -0600
commit168d335fa38cc667c176312e9573d4c79f12fd95 (patch)
tree294b0b7e9624f480cbde23ef9df41aebf801b4e6 /libc-top-half
parenteca199882427eb212be44a5a178ff132bffbf85e (diff)
lookup_name: implement using wasi
Diffstat (limited to 'libc-top-half')
-rw-r--r--libc-top-half/musl/src/network/lookup_name.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/libc-top-half/musl/src/network/lookup_name.c b/libc-top-half/musl/src/network/lookup_name.c
index 291b6b1..b20ebe2 100644
--- a/libc-top-half/musl/src/network/lookup_name.c
+++ b/libc-top-half/musl/src/network/lookup_name.c
@@ -108,6 +108,43 @@ struct dpc_ctx {
#define RR_CNAME 5
#define RR_AAAA 28
+#ifndef __wasilibc_unmodified_upstream
+
+#include <wasi/api.h>
+static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family) {
+ __wasi_size_t naddrs = 0;
+ __wasi_addr_t *addrs;
+ int rv = 0;
+
+ addrs = calloc((MAXADDRS + 1), sizeof(__wasi_addr_t));
+ if (!addrs) {
+ rv = EAI_MEMORY;
+ goto done;
+ }
+
+ __wasi_errno_t error = __wasi_resolve(name, 0, addrs, MAXADDRS, &naddrs);
+ if (error != 0) {
+ errno = error;
+ rv = EAI_NONAME;
+ goto cleanup;
+ }
+
+ for (int i = 0; (i < (int) naddrs) && (i < MAXADDRS); i++) {
+ buf[i] = (struct address){
+ .family = addrs[i].tag,
+ .scopeid = 0,
+ .sortkey = 0,
+ };
+ memcpy(buf[i].addr, &addrs[i].u, 16);
+ rv++;
+ }
+
+ cleanup:
+ free(addrs);
+ done:
+ return rv;
+}
+#else
static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet)
{
char tmp[256];
@@ -135,11 +172,6 @@ static int dns_parse_callback(void *c, int rr, const void *data, int len, const
return 0;
}
-#ifndef __wasilibc_unmodified_upstream
-static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family) {
- return 0;
-}
-#else
static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, const struct resolvconf *conf)
{
unsigned char qbuf[2][280], abuf[2][512];