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
This commit is contained in:
Justine Tunney 2023-12-28 22:58:17 -08:00
parent 1a28e35c62
commit 43fe5956ad
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
146 changed files with 2646 additions and 7190 deletions

View file

@ -28,15 +28,12 @@
#include "third_party/musl/resolv.h"
#include "libc/str/str.h"
asm(".ident\t\"\\n\\n\
Musl libc (MIT License)\\n\
Copyright 2005-2014 Rich Felker, et. al.\"");
asm(".include \"libc/disclaimer.inc\"");
/* RFC 1035 message compression */
/* label start offsets of a compressed domain name s */
static int getoffs(short *offs, const unsigned char *base, const unsigned char *s)
static int getoffs(short *offs,
const unsigned char *base,
const unsigned char *s)
{
int i=0;
for (;;) {
@ -65,8 +62,12 @@ static int getlens(unsigned char *lens, const char *s, int l)
}
/* longest suffix match of an ascii domain with a compressed domain name dn */
static int match(int *offset, const unsigned char *base, const unsigned char *dn,
const char *end, const unsigned char *lens, int nlen)
static int match(int *offset,
const unsigned char *base,
const unsigned char *dn,
const char *end,
const unsigned char *lens,
int nlen)
{
int l, o, m=0;
short offs[128];
@ -86,7 +87,11 @@ static int match(int *offset, const unsigned char *base, const unsigned char *dn
}
}
int dn_comp(const char *src, unsigned char *dst, int space, unsigned char **dnptrs, unsigned char **lastdnptr)
int dn_comp(const char *src,
unsigned char *dst,
int space,
unsigned char **dnptrs,
unsigned char **lastdnptr)
{
int i, j, n, m=0, offset, bestlen=0, bestoff;
unsigned char lens[127];