cosmopolitan/third_party/musl/lookup.internal.h
Justine Tunney 43fe5956ad
Use DNS implementation from Musl Libc
Now that our socket system call polyfills are good enough to support
Musl's DNS library we should be using that rather than the barebones
domain name system implementation we rolled on our own. There's many
benefits to making this change. So many, that I myself wouldn't feel
qualified to enumerate them all. The Musl DNS code had to be changed
in order to support Windows of course, which looks very solid so far
2023-12-28 23:04:35 -08:00

52 lines
1.6 KiB
C

#ifndef COSMOPOLITAN_THIRD_PARTY_MUSL_LOOKUP_INTERNAL_H_
#define COSMOPOLITAN_THIRD_PARTY_MUSL_LOOKUP_INTERNAL_H_
#include "libc/sock/struct/sockaddr6.h"
#include "third_party/musl/netdb.h"
#include "libc/sock/struct/sockaddr.h"
COSMOPOLITAN_C_START_
struct aibuf {
struct addrinfo ai;
union sa {
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
} sa;
int slot;
_Atomic(int) ref;
};
struct address {
int family;
unsigned scopeid;
uint8_t addr[16];
int sortkey;
};
struct service {
uint16_t port;
unsigned char proto, socktype;
};
#define MAXNS 3
struct resolvconf {
struct address ns[MAXNS];
unsigned nns, attempts, ndots;
unsigned timeout;
};
/* The limit of 48 results is a non-sharp bound on the number of addresses
* that can fit in one 512-byte DNS packet full of v4 results and a second
* packet full of v6 results. Due to headers, the actual limit is lower. */
#define MAXADDRS 48
#define MAXSERVS 2
int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags);
int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags);
int __lookup_ipliteral(struct address buf[static 1], const char *name, int family);
int __get_resolv_conf(struct resolvconf *, char *, size_t);
int __res_msend_rc(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int, const struct resolvconf *);
int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *, int), void *);
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_THIRD_PARTY_MUSL_LOOKUP_INTERNAL_H_ */