mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-08 12:18:31 +00:00
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:
parent
1a28e35c62
commit
43fe5956ad
146 changed files with 2646 additions and 7190 deletions
1
third_party/bash/BUILD.mk
vendored
1
third_party/bash/BUILD.mk
vendored
|
@ -18,7 +18,6 @@ THIRD_PARTY_BASH_BINS = \
|
|||
|
||||
THIRD_PARTY_BASH_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_DNS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_MEM \
|
||||
|
|
1
third_party/finger/BUILD.mk
vendored
1
third_party/finger/BUILD.mk
vendored
|
@ -22,7 +22,6 @@ THIRD_PARTY_FINGER_A_DIRECTDEPS = \
|
|||
LIBC_STDIO \
|
||||
LIBC_STR \
|
||||
LIBC_SYSV \
|
||||
LIBC_DNS \
|
||||
LIBC_SOCK \
|
||||
LIBC_TIME \
|
||||
THIRD_PARTY_MUSL \
|
||||
|
|
3
third_party/finger/net.c
vendored
3
third_party/finger/net.c
vendored
|
@ -34,13 +34,14 @@
|
|||
* SUCH DAMAGE.
|
||||
*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/dns/ent.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/sock/struct/sockaddr.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
#include "third_party/finger/finger.h"
|
||||
|
||||
#ifndef lint
|
||||
|
|
4
third_party/hiredis/BUILD.mk
vendored
4
third_party/hiredis/BUILD.mk
vendored
|
@ -16,7 +16,6 @@ THIRD_PARTY_HIREDIS_A_OBJS = \
|
|||
|
||||
THIRD_PARTY_HIREDIS_A_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_DNS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_MEM \
|
||||
|
@ -28,7 +27,8 @@ THIRD_PARTY_HIREDIS_A_DIRECTDEPS = \
|
|||
LIBC_SYSV \
|
||||
LIBC_TIME \
|
||||
LIBC_X \
|
||||
THIRD_PARTY_GDTOA
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_MUSL
|
||||
|
||||
THIRD_PARTY_HIREDIS_A_DEPS := \
|
||||
$(call uniq,$(foreach x,$(THIRD_PARTY_HIREDIS_A_DIRECTDEPS),$($(x))))
|
||||
|
|
3
third_party/hiredis/net.c
vendored
3
third_party/hiredis/net.c
vendored
|
@ -40,7 +40,6 @@
|
|||
#include "libc/intrin/newbie.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sock/select.h"
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/sysv/consts/endian.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/flock.h"
|
||||
|
@ -62,6 +61,8 @@
|
|||
#include "libc/sysv/consts/tcp.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sock/struct/sockaddr.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
#include "libc/errno.h"
|
||||
|
||||
#include "libc/calls/calls.h"
|
||||
|
|
3
third_party/lua/lunix.c
vendored
3
third_party/lua/lunix.c
vendored
|
@ -40,7 +40,6 @@
|
|||
#include "libc/calls/ucontext.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/fmt/itoa.h"
|
||||
|
@ -115,6 +114,8 @@
|
|||
#include "third_party/nsync/futex.internal.h"
|
||||
#include "tool/net/luacheck.h"
|
||||
|
||||
#define DNS_NAME_MAX 253
|
||||
|
||||
/**
|
||||
* @fileoverview UNIX system calls thinly wrapped for Lua
|
||||
* @support Linux, Mac, Windows, FreeBSD, NetBSD, OpenBSD
|
||||
|
|
2
third_party/mbedtls/BUILD.mk
vendored
2
third_party/mbedtls/BUILD.mk
vendored
|
@ -18,7 +18,6 @@ THIRD_PARTY_MBEDTLS_A_CHECKS = \
|
|||
|
||||
THIRD_PARTY_MBEDTLS_A_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_DNS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_MEM \
|
||||
|
@ -31,6 +30,7 @@ THIRD_PARTY_MBEDTLS_A_DIRECTDEPS = \
|
|||
LIBC_TIME \
|
||||
NET_HTTP \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_MUSL \
|
||||
THIRD_PARTY_ZLIB
|
||||
|
||||
THIRD_PARTY_MBEDTLS_A_DEPS := \
|
||||
|
|
3
third_party/mbedtls/net_sockets.c
vendored
3
third_party/mbedtls/net_sockets.c
vendored
|
@ -19,7 +19,6 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/sock/select.h"
|
||||
#include "libc/sock/struct/sockaddr6.h"
|
||||
|
@ -33,6 +32,8 @@
|
|||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/sysv/consts/sol.h"
|
||||
#include "third_party/mbedtls/error.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "third_party/mbedtls/ssl.h"
|
||||
|
||||
#define IS_EINTR(ret) ((ret) == EINTR)
|
||||
|
|
4
third_party/mbedtls/test/BUILD.mk
vendored
4
third_party/mbedtls/test/BUILD.mk
vendored
|
@ -96,7 +96,6 @@ THIRD_PARTY_MBEDTLS_TEST_CHECKS = \
|
|||
|
||||
THIRD_PARTY_MBEDTLS_TEST_DIRECTDEPS = \
|
||||
LIBC_CALLS \
|
||||
LIBC_DNS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_LOG \
|
||||
|
@ -112,7 +111,8 @@ THIRD_PARTY_MBEDTLS_TEST_DIRECTDEPS = \
|
|||
LIBC_X \
|
||||
THIRD_PARTY_COMPILER_RT \
|
||||
THIRD_PARTY_GDTOA \
|
||||
THIRD_PARTY_MBEDTLS
|
||||
THIRD_PARTY_MBEDTLS \
|
||||
THIRD_PARTY_MUSL
|
||||
|
||||
THIRD_PARTY_MBEDTLS_TEST_DEPS := \
|
||||
$(call uniq,$(foreach x,$(THIRD_PARTY_MBEDTLS_TEST_DIRECTDEPS),$($(x))))
|
||||
|
|
6
third_party/musl/BUILD.mk
vendored
6
third_party/musl/BUILD.mk
vendored
|
@ -48,6 +48,12 @@ $(THIRD_PARTY_MUSL_A).pkg: \
|
|||
$(THIRD_PARTY_MUSL_A_OBJS) \
|
||||
$(foreach x,$(THIRD_PARTY_MUSL_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/third_party/musl/getnameinfo.o \
|
||||
o/$(MODE)/third_party/musl/lookup_name.o \
|
||||
o/$(MODE)/third_party/musl/lookup_serv.o: \
|
||||
private CFLAGS += \
|
||||
-fportcosmo
|
||||
|
||||
# offer assurances about the stack safety of cosmo libc
|
||||
$(THIRD_PARTY_MUSL_A_OBJS): private COPTS += -Wframe-larger-than=4096 -Walloca-larger-than=4096
|
||||
|
||||
|
|
23
third_party/musl/dn_comp.c
vendored
23
third_party/musl/dn_comp.c
vendored
|
@ -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];
|
||||
|
|
11
third_party/musl/dn_expand.c
vendored
11
third_party/musl/dn_expand.c
vendored
|
@ -27,12 +27,11 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/musl/resolv.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
int __dn_expand(const unsigned char *base, const unsigned char *end, const unsigned char *src, char *dest, int space)
|
||||
int __dn_expand(const unsigned char *base,
|
||||
const unsigned char *end,
|
||||
const unsigned char *src,
|
||||
char *dest,
|
||||
int space)
|
||||
{
|
||||
const unsigned char *p = src;
|
||||
char *dend, *dbegin = dest;
|
||||
|
|
5
third_party/musl/dn_skipname.c
vendored
5
third_party/musl/dn_skipname.c
vendored
|
@ -27,11 +27,6 @@
|
|||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/musl/resolv.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
int dn_skipname(const unsigned char *s, const unsigned char *end)
|
||||
{
|
||||
const unsigned char *p = s;
|
||||
|
|
BIN
third_party/musl/dns.png
vendored
Normal file
BIN
third_party/musl/dns.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 474 KiB |
61
third_party/musl/dns_parse.c
vendored
Normal file
61
third_party/musl/dns_parse.c
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/musl/lookup.internal.h"
|
||||
|
||||
int __dns_parse(const unsigned char *r, int rlen,
|
||||
int callback(void *, int, const void *, int, const void *, int),
|
||||
void *ctx)
|
||||
{
|
||||
int qdcount, ancount;
|
||||
const unsigned char *p;
|
||||
int len;
|
||||
|
||||
if (rlen<12) return -1;
|
||||
if ((r[3]&15)) return 0;
|
||||
p = r+12;
|
||||
qdcount = r[4]*256 + r[5];
|
||||
ancount = r[6]*256 + r[7];
|
||||
if (qdcount+ancount > 64) return -1;
|
||||
while (qdcount--) {
|
||||
while (p-r < rlen && *p-1U < 127) p++;
|
||||
if (p>r+rlen-6)
|
||||
return -1;
|
||||
p += 5 + !!*p;
|
||||
}
|
||||
while (ancount--) {
|
||||
while (p-r < rlen && *p-1U < 127) p++;
|
||||
if (p>r+rlen-12)
|
||||
return -1;
|
||||
p += 1 + !!*p;
|
||||
len = p[8]*256 + p[9];
|
||||
if (len+10 > r+rlen-p) return -1;
|
||||
if (callback(ctx, p[1], p+10, len, r, rlen) < 0) return -1;
|
||||
p += 10 + len;
|
||||
}
|
||||
return 0;
|
||||
}
|
49
third_party/musl/ent.c
vendored
Normal file
49
third_party/musl/ent.c
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
void sethostent(int x)
|
||||
{
|
||||
}
|
||||
|
||||
struct hostent *gethostent()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct netent *getnetent()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void endhostent(void)
|
||||
{
|
||||
}
|
||||
|
||||
__weak_reference(sethostent, setnetent);
|
||||
__weak_reference(endhostent, endnetent);
|
29
third_party/musl/fgetspent.c
vendored
29
third_party/musl/fgetspent.c
vendored
|
@ -1,5 +1,32 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set et ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/thread/thread.h"
|
||||
#include "pwf.internal.h"
|
||||
#include <pthread.h>
|
||||
|
||||
struct spwd *fgetspent(FILE *f)
|
||||
{
|
||||
|
|
47
third_party/musl/freeaddrinfo.c
vendored
Normal file
47
third_party/musl/freeaddrinfo.c
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "third_party/musl/lookup.internal.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
void freeaddrinfo(struct addrinfo *p)
|
||||
{
|
||||
size_t cnt;
|
||||
for (cnt=1; p->ai_next; cnt++, p=p->ai_next);
|
||||
struct aibuf *b = (void *)((char *)p - offsetof(struct aibuf, ai));
|
||||
b -= b->slot;
|
||||
if (atomic_fetch_sub(&b->ref, cnt) == cnt) {
|
||||
free(b);
|
||||
}
|
||||
}
|
56
third_party/musl/gai_strerror.c
vendored
Normal file
56
third_party/musl/gai_strerror.c
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
static const char msgs[] =
|
||||
"Invalid flags\0"
|
||||
"Name does not resolve\0"
|
||||
"Try again\0"
|
||||
"Non-recoverable error\0"
|
||||
"Name has no usable address\0"
|
||||
"Unrecognized address family or invalid length\0"
|
||||
"Unrecognized socket type\0"
|
||||
"Unrecognized service\0"
|
||||
"Unknown error\0"
|
||||
"Out of memory\0"
|
||||
"System error\0"
|
||||
"Overflow\0"
|
||||
"\0Unknown error";
|
||||
|
||||
const char *gai_strerror(int ecode)
|
||||
{
|
||||
const char *s;
|
||||
for (s=msgs, ecode++; ecode && *s; ecode++, s++) for (; *s; s++);
|
||||
if (!*s) s++;
|
||||
return s;
|
||||
}
|
171
third_party/musl/getaddrinfo.c
vendored
Normal file
171
third_party/musl/getaddrinfo.c
vendored
Normal file
|
@ -0,0 +1,171 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/inaddr.h"
|
||||
#include "libc/sysv/consts/ipproto.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "third_party/musl/lookup.internal.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
int getaddrinfo(const char *host,
|
||||
const char *serv,
|
||||
const struct addrinfo *hint,
|
||||
struct addrinfo **res)
|
||||
{
|
||||
struct service ports[MAXSERVS];
|
||||
struct address addrs[MAXADDRS];
|
||||
char canon[256], *outcanon;
|
||||
int nservs, naddrs, nais, canon_len, i, j, k;
|
||||
int family = AF_UNSPEC, flags = 0, proto = 0, socktype = 0;
|
||||
int no_family = 0;
|
||||
struct aibuf *out;
|
||||
|
||||
if (!host && !serv) return EAI_NONAME;
|
||||
|
||||
if (hint) {
|
||||
family = hint->ai_family;
|
||||
flags = hint->ai_flags;
|
||||
proto = hint->ai_protocol;
|
||||
socktype = hint->ai_socktype;
|
||||
|
||||
const int mask = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST |
|
||||
AI_V4MAPPED | AI_ALL | AI_ADDRCONFIG | AI_NUMERICSERV;
|
||||
if ((flags & mask) != flags)
|
||||
return EAI_BADFLAGS;
|
||||
|
||||
if (family != AF_INET &&
|
||||
family != AF_INET6 &&
|
||||
family != AF_UNSPEC) {
|
||||
return EAI_FAMILY;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & AI_ADDRCONFIG) {
|
||||
/* Define the "an address is configured" condition for address
|
||||
* families via ability to create a socket for the family plus
|
||||
* routability of the loopback address for the family. */
|
||||
const struct sockaddr_in lo4 = {
|
||||
.sin_family = AF_INET, .sin_port = 65535,
|
||||
.sin_addr.s_addr = __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
? 0x7f000001 : 0x0100007f
|
||||
};
|
||||
const struct sockaddr_in6 lo6 = {
|
||||
.sin6_family = AF_INET6, .sin6_port = 65535,
|
||||
.sin6_addr = IN6ADDR_LOOPBACK_INIT
|
||||
};
|
||||
int tf[2] = { AF_INET, AF_INET6 };
|
||||
const void *ta[2] = { &lo4, &lo6 };
|
||||
socklen_t tl[2] = { sizeof lo4, sizeof lo6 };
|
||||
for (i=0; i<2; i++) {
|
||||
if (family==tf[1-i]) continue;
|
||||
int s = socket(tf[i], SOCK_CLOEXEC|SOCK_DGRAM,
|
||||
IPPROTO_UDP);
|
||||
if (s>=0) {
|
||||
int cs;
|
||||
pthread_setcancelstate(
|
||||
PTHREAD_CANCEL_DISABLE, &cs);
|
||||
int r = connect(s, ta[i], tl[i]);
|
||||
int saved_errno = errno;
|
||||
pthread_setcancelstate(cs, 0);
|
||||
close(s);
|
||||
if (!r) continue;
|
||||
errno = saved_errno;
|
||||
}
|
||||
if (errno != EADDRNOTAVAIL &&
|
||||
errno != EAFNOSUPPORT &&
|
||||
errno != EHOSTUNREACH &&
|
||||
errno != ENETDOWN &&
|
||||
errno != ENETUNREACH) {
|
||||
return EAI_SYSTEM;
|
||||
}
|
||||
if (family == tf[i]) no_family = 1;
|
||||
family = tf[1-i];
|
||||
}
|
||||
}
|
||||
|
||||
nservs = __lookup_serv(ports, serv, proto, socktype, flags);
|
||||
if (nservs < 0) return nservs;
|
||||
|
||||
naddrs = __lookup_name(addrs, canon, host, family, flags);
|
||||
if (naddrs < 0) return naddrs;
|
||||
|
||||
if (no_family) return EAI_NODATA;
|
||||
|
||||
nais = nservs * naddrs;
|
||||
canon_len = strlen(canon);
|
||||
out = calloc(1, nais * sizeof(*out) + canon_len + 1);
|
||||
if (!out) return EAI_MEMORY;
|
||||
|
||||
if (canon_len) {
|
||||
outcanon = (void *)&out[nais];
|
||||
memcpy(outcanon, canon, canon_len+1);
|
||||
} else {
|
||||
outcanon = 0;
|
||||
}
|
||||
|
||||
for (k=i=0; i<naddrs; i++) for (j=0; j<nservs; j++, k++) {
|
||||
out[k].slot = k;
|
||||
out[k].ai = (struct addrinfo){
|
||||
.ai_family = addrs[i].family,
|
||||
.ai_socktype = ports[j].socktype,
|
||||
.ai_protocol = ports[j].proto,
|
||||
.ai_addrlen = addrs[i].family == AF_INET
|
||||
? sizeof(struct sockaddr_in)
|
||||
: sizeof(struct sockaddr_in6),
|
||||
.ai_addr = (void *)&out[k].sa,
|
||||
.ai_canonname = outcanon };
|
||||
if (k) out[k-1].ai.ai_next = &out[k].ai;
|
||||
if (addrs[i].family == AF_INET) {
|
||||
out[k].sa.sin.sin_family = AF_INET;
|
||||
out[k].sa.sin.sin_port = htons(ports[j].port);
|
||||
memcpy(&out[k].sa.sin.sin_addr, &addrs[i].addr, 4);
|
||||
} else if (addrs[i].family == AF_INET6) {
|
||||
out[k].sa.sin6.sin6_family = AF_INET6;
|
||||
out[k].sa.sin6.sin6_port = htons(ports[j].port);
|
||||
out[k].sa.sin6.sin6_scope_id = addrs[i].scopeid;
|
||||
memcpy(&out[k].sa.sin6.sin6_addr, &addrs[i].addr, 16);
|
||||
}
|
||||
}
|
||||
atomic_store_explicit(&out[0].ref, nais, memory_order_relaxed);
|
||||
*res = &out->ai;
|
||||
return 0;
|
||||
}
|
50
third_party/musl/gethostbyaddr.c
vendored
Normal file
50
third_party/musl/gethostbyaddr.c
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
struct hostent *gethostbyaddr(const void *a, socklen_t l, int af)
|
||||
{
|
||||
static struct hostent *h;
|
||||
size_t size = 63;
|
||||
struct hostent *res;
|
||||
int err;
|
||||
do {
|
||||
free(h);
|
||||
h = malloc(size+=size+1);
|
||||
if (!h) {
|
||||
h_errno = NO_RECOVERY;
|
||||
return 0;
|
||||
}
|
||||
err = gethostbyaddr_r(a, l, af, h,
|
||||
(void *)(h+1), size-sizeof *h, &res, &h_errno);
|
||||
} while (err == ERANGE);
|
||||
return res;
|
||||
}
|
103
third_party/musl/gethostbyaddr_r.c
vendored
Normal file
103
third_party/musl/gethostbyaddr_r.c
vendored
Normal file
|
@ -0,0 +1,103 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/sock/struct/sockaddr.h"
|
||||
#include "libc/sock/struct/sockaddr6.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
errno_t gethostbyaddr_r(const void *a, socklen_t l, int af,
|
||||
struct hostent *h, char *buf, size_t buflen,
|
||||
struct hostent **res, int *err)
|
||||
{
|
||||
union {
|
||||
struct sockaddr_in sin;
|
||||
struct sockaddr_in6 sin6;
|
||||
} sa = { .sin.sin_family = af };
|
||||
socklen_t sl = af==AF_INET6 ? sizeof sa.sin6 : sizeof sa.sin;
|
||||
int i;
|
||||
|
||||
*res = 0;
|
||||
|
||||
/* Load address argument into sockaddr structure */
|
||||
if (af==AF_INET6 && l==16) memcpy(&sa.sin6.sin6_addr, a, 16);
|
||||
else if (af==AF_INET && l==4) memcpy(&sa.sin.sin_addr, a, 4);
|
||||
else {
|
||||
*err = NO_RECOVERY;
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
/* Align buffer and check for space for pointers and ip address */
|
||||
i = (uintptr_t)buf & (sizeof(char *)-1);
|
||||
if (!i) i = sizeof(char *);
|
||||
if (buflen <= 5*sizeof(char *)-i + l) return ERANGE;
|
||||
buf += sizeof(char *)-i;
|
||||
buflen -= 5*sizeof(char *)-i + l;
|
||||
|
||||
h->h_addr_list = (void *)buf;
|
||||
buf += 2*sizeof(char *);
|
||||
h->h_aliases = (void *)buf;
|
||||
buf += 2*sizeof(char *);
|
||||
|
||||
h->h_addr_list[0] = buf;
|
||||
memcpy(h->h_addr_list[0], a, l);
|
||||
buf += l;
|
||||
h->h_addr_list[1] = 0;
|
||||
h->h_aliases[0] = buf;
|
||||
h->h_aliases[1] = 0;
|
||||
|
||||
switch (getnameinfo((void *)&sa, sl, buf, buflen, 0, 0, 0)) {
|
||||
case EAI_AGAIN:
|
||||
*err = TRY_AGAIN;
|
||||
return EAGAIN;
|
||||
case EAI_OVERFLOW:
|
||||
return ERANGE;
|
||||
default:
|
||||
case EAI_FAIL:
|
||||
*err = NO_RECOVERY;
|
||||
return EBADMSG;
|
||||
case EAI_SYSTEM:
|
||||
*err = NO_RECOVERY;
|
||||
return errno;
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
|
||||
h->h_addrtype = af;
|
||||
h->h_length = l;
|
||||
h->h_name = h->h_aliases[0];
|
||||
*res = h;
|
||||
return 0;
|
||||
}
|
34
third_party/musl/gethostbyname.c
vendored
Normal file
34
third_party/musl/gethostbyname.c
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
struct hostent *gethostbyname(const char *name)
|
||||
{
|
||||
return gethostbyname2(name, AF_INET);
|
||||
}
|
49
third_party/musl/gethostbyname2.c
vendored
Normal file
49
third_party/musl/gethostbyname2.c
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
struct hostent *gethostbyname2(const char *name, int af)
|
||||
{
|
||||
static struct hostent *h;
|
||||
size_t size = 63;
|
||||
struct hostent *res;
|
||||
int err;
|
||||
do {
|
||||
free(h);
|
||||
h = malloc(size+=size+1);
|
||||
if (!h) {
|
||||
h_errno = NO_RECOVERY;
|
||||
return 0;
|
||||
}
|
||||
err = gethostbyname2_r(name, af, h,
|
||||
(void *)(h+1), size-sizeof *h, &res, &h_errno);
|
||||
} while (err == ERANGE);
|
||||
return res;
|
||||
}
|
110
third_party/musl/gethostbyname2_r.c
vendored
Normal file
110
third_party/musl/gethostbyname2_r.c
vendored
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "third_party/musl/lookup.internal.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
errno_t gethostbyname2_r(const char *name, int af,
|
||||
struct hostent *h, char *buf, size_t buflen,
|
||||
struct hostent **res, int *err)
|
||||
{
|
||||
struct address addrs[MAXADDRS];
|
||||
char canon[256];
|
||||
int i, cnt;
|
||||
size_t align, need;
|
||||
|
||||
*res = 0;
|
||||
cnt = __lookup_name(addrs, canon, name, af, AI_CANONNAME);
|
||||
if (cnt<0) switch (cnt) {
|
||||
case EAI_NONAME:
|
||||
*err = HOST_NOT_FOUND;
|
||||
return 0;
|
||||
case EAI_NODATA:
|
||||
*err = NO_DATA;
|
||||
return 0;
|
||||
case EAI_AGAIN:
|
||||
*err = TRY_AGAIN;
|
||||
return EAGAIN;
|
||||
default:
|
||||
case EAI_FAIL:
|
||||
*err = NO_RECOVERY;
|
||||
return EBADMSG;
|
||||
case EAI_SYSTEM:
|
||||
*err = NO_RECOVERY;
|
||||
return errno;
|
||||
}
|
||||
|
||||
h->h_addrtype = af;
|
||||
h->h_length = af==AF_INET6 ? 16 : 4;
|
||||
|
||||
/* Align buffer */
|
||||
align = -(uintptr_t)buf & (sizeof(char *)-1);
|
||||
|
||||
need = 4*sizeof(char *);
|
||||
need += (cnt + 1) * (sizeof(char *) + h->h_length);
|
||||
need += strlen(name)+1;
|
||||
need += strlen(canon)+1;
|
||||
need += align;
|
||||
|
||||
if (need > buflen) return ERANGE;
|
||||
|
||||
buf += align;
|
||||
h->h_aliases = (void *)buf;
|
||||
buf += 3*sizeof(char *);
|
||||
h->h_addr_list = (void *)buf;
|
||||
buf += (cnt+1)*sizeof(char *);
|
||||
|
||||
for (i=0; i<cnt; i++) {
|
||||
h->h_addr_list[i] = (void *)buf;
|
||||
buf += h->h_length;
|
||||
memcpy(h->h_addr_list[i], addrs[i].addr, h->h_length);
|
||||
}
|
||||
h->h_addr_list[i] = 0;
|
||||
|
||||
h->h_name = h->h_aliases[0] = buf;
|
||||
strcpy(h->h_name, canon);
|
||||
buf += strlen(h->h_name)+1;
|
||||
|
||||
if (strcmp(h->h_name, name)) {
|
||||
h->h_aliases[1] = buf;
|
||||
strcpy(h->h_aliases[1], name);
|
||||
buf += strlen(h->h_aliases[1])+1;
|
||||
} else h->h_aliases[1] = 0;
|
||||
|
||||
h->h_aliases[2] = 0;
|
||||
|
||||
*res = h;
|
||||
return 0;
|
||||
}
|
36
third_party/musl/gethostbyname_r.c
vendored
Normal file
36
third_party/musl/gethostbyname_r.c
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
int gethostbyname_r(const char *name,
|
||||
struct hostent *h, char *buf, size_t buflen,
|
||||
struct hostent **res, int *err)
|
||||
{
|
||||
return gethostbyname2_r(name, AF_INET, h, buf, buflen, res, err);
|
||||
}
|
254
third_party/musl/getnameinfo.c
vendored
Normal file
254
third_party/musl/getnameinfo.c
vendored
Normal file
|
@ -0,0 +1,254 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/sysdir.internal.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/sock/in.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sock/struct/ifreq.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "third_party/musl/lookup.internal.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
#include "third_party/musl/resolv.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
#define PTR_MAX (64 + sizeof ".in-addr.arpa")
|
||||
#define RR_PTR 12
|
||||
|
||||
static char *itoa(char *p, unsigned x) {
|
||||
p += 3*sizeof(int);
|
||||
*--p = 0;
|
||||
do {
|
||||
*--p = '0' + x % 10;
|
||||
x /= 10;
|
||||
} while (x);
|
||||
return p;
|
||||
}
|
||||
|
||||
static void mkptr4(char *s, const unsigned char *ip)
|
||||
{
|
||||
sprintf(s, "%d.%d.%d.%d.in-addr.arpa",
|
||||
ip[3], ip[2], ip[1], ip[0]);
|
||||
}
|
||||
|
||||
static void mkptr6(char *s, const unsigned char *ip)
|
||||
{
|
||||
static const char xdigits[] = "0123456789abcdef";
|
||||
int i;
|
||||
for (i=15; i>=0; i--) {
|
||||
*s++ = xdigits[ip[i]&15]; *s++ = '.';
|
||||
*s++ = xdigits[ip[i]>>4]; *s++ = '.';
|
||||
}
|
||||
strcpy(s, "ip6.arpa");
|
||||
}
|
||||
|
||||
static void reverse_hosts(char *buf, const unsigned char *a, unsigned scopeid, int family)
|
||||
{
|
||||
/* get path of /etc/hosts */
|
||||
char etc_hosts_buf[256];
|
||||
const char *etc_hosts_path =
|
||||
GetHostsTxtPath(etc_hosts_buf,
|
||||
sizeof(etc_hosts_buf));
|
||||
|
||||
/* open hosts definitions file */
|
||||
unsigned char atmp[16];
|
||||
FILE *f = fopen(etc_hosts_path, "rbe");
|
||||
if (!f) return;
|
||||
if (family == AF_INET) {
|
||||
memcpy(atmp+12, a, 4);
|
||||
memcpy(atmp, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
|
||||
a = atmp;
|
||||
}
|
||||
|
||||
/* read hosts definitions file */
|
||||
char line[512], *p, *z;
|
||||
struct address iplit;
|
||||
while (fgets(line, sizeof line, f)) {
|
||||
if ((p=strchr(line, '#'))) *p++='\n', *p=0;
|
||||
|
||||
for (p=line; *p && !isspace(*p); p++);
|
||||
if (!*p) continue;
|
||||
*p++ = 0;
|
||||
if (__lookup_ipliteral(&iplit, line, AF_UNSPEC)<=0)
|
||||
continue;
|
||||
|
||||
if (iplit.family == AF_INET) {
|
||||
memcpy(iplit.addr+12, iplit.addr, 4);
|
||||
memcpy(iplit.addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
|
||||
iplit.scopeid = 0;
|
||||
}
|
||||
|
||||
if (memcmp(a, iplit.addr, 16) || iplit.scopeid != scopeid)
|
||||
continue;
|
||||
|
||||
for (; *p && isspace(*p); p++);
|
||||
for (z=p; *z && !isspace(*z); z++);
|
||||
*z = 0;
|
||||
if (z-p < 256) {
|
||||
memcpy(buf, p, z-p+1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static void reverse_services(char *buf, int port, int dgram)
|
||||
{
|
||||
/* get path of /etc/services */
|
||||
char etc_services_buf[256];
|
||||
const char *etc_services_path =
|
||||
GetServicesTxtPath(etc_services_buf,
|
||||
sizeof(etc_services_buf));
|
||||
|
||||
/* open services definitions file */
|
||||
FILE *f = fopen(etc_services_path, "rbe");
|
||||
if (!f) return;
|
||||
|
||||
/* read services definitions file */
|
||||
unsigned long svport;
|
||||
char line[128], *p, *z;
|
||||
while (fgets(line, sizeof line, f)) {
|
||||
if ((p=strchr(line, '#'))) *p++='\n', *p=0;
|
||||
|
||||
for (p=line; *p && !isspace(*p); p++);
|
||||
if (!*p) continue;
|
||||
*p++ = 0;
|
||||
svport = strtoul(p, &z, 10);
|
||||
|
||||
if (svport != port || z==p) continue;
|
||||
if (dgram && strncmp(z, "/udp", 4)) continue;
|
||||
if (!dgram && strncmp(z, "/tcp", 4)) continue;
|
||||
if (p-line > 32) continue;
|
||||
|
||||
memcpy(buf, line, p-line);
|
||||
break;
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet, int plen)
|
||||
{
|
||||
if (rr != RR_PTR) return 0;
|
||||
if (__dn_expand(packet, (const unsigned char *)packet + plen,
|
||||
data, c, 256) <= 0)
|
||||
*(char *)c = 0;
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl,
|
||||
char *restrict node, socklen_t nodelen,
|
||||
char *restrict serv, socklen_t servlen,
|
||||
int flags)
|
||||
{
|
||||
char ptr[PTR_MAX];
|
||||
char buf[256], num[3*sizeof(int)+1];
|
||||
int af = sa->sa_family;
|
||||
unsigned char *a;
|
||||
unsigned scopeid;
|
||||
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
a = (void *)&((struct sockaddr_in *)sa)->sin_addr;
|
||||
if (sl < sizeof(struct sockaddr_in)) return EAI_FAMILY;
|
||||
mkptr4(ptr, a);
|
||||
scopeid = 0;
|
||||
break;
|
||||
case AF_INET6:
|
||||
a = (void *)&((struct sockaddr_in6 *)sa)->sin6_addr;
|
||||
if (sl < sizeof(struct sockaddr_in6)) return EAI_FAMILY;
|
||||
if (memcmp(a, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12))
|
||||
mkptr6(ptr, a);
|
||||
else
|
||||
mkptr4(ptr, a+12);
|
||||
scopeid = ((struct sockaddr_in6 *)sa)->sin6_scope_id;
|
||||
break;
|
||||
default:
|
||||
return EAI_FAMILY;
|
||||
}
|
||||
|
||||
if (node && nodelen) {
|
||||
buf[0] = 0;
|
||||
if (!(flags & NI_NUMERICHOST)) {
|
||||
reverse_hosts(buf, a, scopeid, af);
|
||||
}
|
||||
if (!*buf && !(flags & NI_NUMERICHOST)) {
|
||||
unsigned char query[18+PTR_MAX], reply[512];
|
||||
int qlen = __res_mkquery(0, ptr, 1, RR_PTR,
|
||||
0, 0, 0, query, sizeof query);
|
||||
query[3] = 0; /* don't need AD flag */
|
||||
int rlen = __res_send(query, qlen, reply, sizeof reply);
|
||||
buf[0] = 0;
|
||||
if (rlen > 0)
|
||||
__dns_parse(reply, rlen, dns_parse_callback, buf);
|
||||
}
|
||||
if (!*buf) {
|
||||
if (flags & NI_NAMEREQD) return EAI_NONAME;
|
||||
inet_ntop(af, a, buf, sizeof buf);
|
||||
if (scopeid) {
|
||||
#if 1
|
||||
/* TODO(jart): How do we handle this? */
|
||||
return EAI_NONAME;
|
||||
#else
|
||||
char *p = 0, tmp[IF_NAMESIZE+1];
|
||||
if (!(flags & NI_NUMERICSCOPE) &&
|
||||
(IN6_IS_ADDR_LINKLOCAL(a) ||
|
||||
IN6_IS_ADDR_MC_LINKLOCAL(a)))
|
||||
p = if_indextoname(scopeid, tmp+1);
|
||||
if (!p)
|
||||
p = itoa(num, scopeid);
|
||||
*--p = '%';
|
||||
strcat(buf, p);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if (strlen(buf) >= nodelen) return EAI_OVERFLOW;
|
||||
strcpy(node, buf);
|
||||
}
|
||||
|
||||
if (serv && servlen) {
|
||||
char *p = buf;
|
||||
int port = ntohs(((struct sockaddr_in *)sa)->sin_port);
|
||||
buf[0] = 0;
|
||||
if (!(flags & NI_NUMERICSERV))
|
||||
reverse_services(buf, port, flags & NI_DGRAM);
|
||||
if (!*p)
|
||||
p = itoa(num, port);
|
||||
if (strlen(p) >= servlen)
|
||||
return EAI_OVERFLOW;
|
||||
strcpy(serv, p);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
38
third_party/musl/getservbyname.c
vendored
Normal file
38
third_party/musl/getservbyname.c
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
struct servent *getservbyname(const char *name, const char *prots)
|
||||
{
|
||||
static struct servent se;
|
||||
static char *buf[2];
|
||||
struct servent *res;
|
||||
if (getservbyname_r(name, prots, &se, (void *)buf, sizeof buf, &res))
|
||||
return 0;
|
||||
return &se;
|
||||
}
|
85
third_party/musl/getservbyname_r.c
vendored
Normal file
85
third_party/musl/getservbyname_r.c
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/ipproto.h"
|
||||
#include "third_party/musl/lookup.internal.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
#define ALIGN (sizeof(struct { char a; char *b; }) - sizeof(char *))
|
||||
|
||||
errno_t getservbyname_r(const char *name, const char *prots,
|
||||
struct servent *se, char *buf, size_t buflen, struct servent **res)
|
||||
{
|
||||
struct service servs[MAXSERVS];
|
||||
int cnt, proto, align;
|
||||
|
||||
*res = 0;
|
||||
|
||||
/* Don't treat numeric port number strings as service records. */
|
||||
char *end = "";
|
||||
strtoul(name, &end, 10);
|
||||
if (!*end) return ENOENT;
|
||||
|
||||
/* Align buffer */
|
||||
align = -(uintptr_t)buf & (ALIGN-1);
|
||||
if (buflen < 2*sizeof(char *)+align)
|
||||
return ERANGE;
|
||||
buf += align;
|
||||
|
||||
if (!prots) proto = 0;
|
||||
else if (!strcmp(prots, "tcp")) proto = IPPROTO_TCP;
|
||||
else if (!strcmp(prots, "udp")) proto = IPPROTO_UDP;
|
||||
else return EINVAL;
|
||||
|
||||
cnt = __lookup_serv(servs, name, proto, 0, 0);
|
||||
if (cnt<0) switch (cnt) {
|
||||
case EAI_MEMORY:
|
||||
case EAI_SYSTEM:
|
||||
return ENOMEM;
|
||||
default:
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
se->s_name = (char *)name;
|
||||
se->s_aliases = (void *)buf;
|
||||
se->s_aliases[0] = se->s_name;
|
||||
se->s_aliases[1] = 0;
|
||||
se->s_port = htons(servs[0].port);
|
||||
se->s_proto = servs[0].proto == IPPROTO_TCP ? "tcp" : "udp";
|
||||
|
||||
*res = se;
|
||||
return 0;
|
||||
}
|
38
third_party/musl/getservbyport.c
vendored
Normal file
38
third_party/musl/getservbyport.c
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
struct servent *getservbyport(int port, const char *prots)
|
||||
{
|
||||
static struct servent se;
|
||||
static long buf[32/sizeof(long)];
|
||||
struct servent *res;
|
||||
if (getservbyport_r(port, prots, &se, (void *)buf, sizeof buf, &res))
|
||||
return 0;
|
||||
return &se;
|
||||
}
|
92
third_party/musl/getservbyport_r.c
vendored
Normal file
92
third_party/musl/getservbyport_r.c
vendored
Normal file
|
@ -0,0 +1,92 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
errno_t getservbyport_r(int port, const char *prots,
|
||||
struct servent *se, char *buf, size_t buflen, struct servent **res)
|
||||
{
|
||||
int i;
|
||||
struct sockaddr_in sin = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = port,
|
||||
};
|
||||
|
||||
if (!prots) {
|
||||
int r = getservbyport_r(port, "tcp", se, buf, buflen, res);
|
||||
if (r) r = getservbyport_r(port, "udp", se, buf, buflen, res);
|
||||
return r;
|
||||
}
|
||||
*res = 0;
|
||||
|
||||
/* Align buffer */
|
||||
i = (uintptr_t)buf & (sizeof(char *)-1);
|
||||
if (!i) i = sizeof(char *);
|
||||
if (buflen <= 3*sizeof(char *)-i)
|
||||
return ERANGE;
|
||||
buf += sizeof(char *)-i;
|
||||
buflen -= sizeof(char *)-i;
|
||||
|
||||
if (strcmp(prots, "tcp") && strcmp(prots, "udp")) return EINVAL;
|
||||
|
||||
se->s_port = port;
|
||||
se->s_proto = (char *)prots;
|
||||
se->s_aliases = (void *)buf;
|
||||
buf += 2*sizeof(char *);
|
||||
buflen -= 2*sizeof(char *);
|
||||
se->s_aliases[1] = 0;
|
||||
se->s_aliases[0] = se->s_name = buf;
|
||||
|
||||
switch (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen,
|
||||
strcmp(prots, "udp") ? 0 : NI_DGRAM)) {
|
||||
case EAI_MEMORY:
|
||||
case EAI_SYSTEM:
|
||||
return ENOMEM;
|
||||
case EAI_OVERFLOW:
|
||||
return ERANGE;
|
||||
default:
|
||||
return ENOENT;
|
||||
case 0:
|
||||
break;
|
||||
}
|
||||
|
||||
/* A numeric port string is not a service record. */
|
||||
if (strtol(buf, 0, 10)==ntohs(port)) return ENOENT;
|
||||
|
||||
*res = se;
|
||||
return 0;
|
||||
}
|
32
third_party/musl/getspnam_r.c
vendored
32
third_party/musl/getspnam_r.c
vendored
|
@ -1,3 +1,30 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
|
@ -5,6 +32,11 @@
|
|||
#include <pthread.h>
|
||||
#include "pwf.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
/* This implementation support Openwall-style TCB passwords in place of
|
||||
* traditional shadow, if the appropriate directories and files exist.
|
||||
* Thus, it is careful to avoid following symlinks or blocking on fifos
|
||||
|
|
36
third_party/musl/h_errno.c
vendored
Normal file
36
third_party/musl/h_errno.c
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
// error number global for gethostbyname*(), gethostbyaddr*(), etc.
|
||||
static _Thread_local int __h_errno;
|
||||
|
||||
errno_t *__h_errno_location(void)
|
||||
{
|
||||
return &__h_errno;
|
||||
}
|
34
third_party/musl/herror.c
vendored
Normal file
34
third_party/musl/herror.c
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
void herror(const char *msg)
|
||||
{
|
||||
fprintf(stderr, "%s%s%s\n", msg?msg:"", msg?": ":"", hstrerror(h_errno));
|
||||
}
|
43
third_party/musl/hstrerror.c
vendored
Normal file
43
third_party/musl/hstrerror.c
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
static const char msgs[] =
|
||||
"Host not found\0"
|
||||
"Try again\0"
|
||||
"Non-recoverable error\0"
|
||||
"Address not available\0"
|
||||
"\0Unknown error";
|
||||
|
||||
const char *hstrerror(int ecode)
|
||||
{
|
||||
const char *s;
|
||||
for (s=msgs, ecode--; ecode && *s; ecode--, s++) for (; *s; s++);
|
||||
if (!*s) s++;
|
||||
return s;
|
||||
}
|
1
third_party/musl/insque.c
vendored
1
third_party/musl/insque.c
vendored
|
@ -32,7 +32,6 @@ Musl libc (MIT License)\\n\
|
|||
Copyright 2005-2020 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
|
||||
struct node {
|
||||
struct node *next;
|
||||
struct node *prev;
|
||||
|
|
6
third_party/musl/lookup.internal.h
vendored
6
third_party/musl/lookup.internal.h
vendored
|
@ -1,8 +1,8 @@
|
|||
#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"
|
||||
#include "libc/dns/dns.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct aibuf {
|
||||
|
@ -11,8 +11,8 @@ struct aibuf {
|
|||
struct sockaddr_in sin;
|
||||
struct sockaddr_in6 sin6;
|
||||
} sa;
|
||||
volatile int lock[1];
|
||||
short slot, ref;
|
||||
int slot;
|
||||
_Atomic(int) ref;
|
||||
};
|
||||
|
||||
struct address {
|
||||
|
|
1
third_party/musl/lookup_ipliteral.c
vendored
1
third_party/musl/lookup_ipliteral.c
vendored
|
@ -30,6 +30,7 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/limits.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "third_party/musl/lookup.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
|
|
486
third_party/musl/lookup_name.c
vendored
Normal file
486
third_party/musl/lookup_name.c
vendored
Normal file
|
@ -0,0 +1,486 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/sysdir.internal.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/runtime/stack.h"
|
||||
#include "libc/sock/in.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/ipproto.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "third_party/musl/lookup.internal.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
#include "third_party/musl/resolv.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
static int is_valid_hostname(const char *host)
|
||||
{
|
||||
const unsigned char *s;
|
||||
if (strnlen(host, 255)-1 >= 254 || mbstowcs(0, host, 0) == -1) return 0;
|
||||
for (s=(void *)host; *s>=0x80 || *s=='.' || *s=='-' || isalnum(*s); s++);
|
||||
return !*s;
|
||||
}
|
||||
|
||||
static int name_from_null(struct address buf[static 2], const char *name, int family, int flags)
|
||||
{
|
||||
int cnt = 0;
|
||||
if (name) return 0;
|
||||
if (flags & AI_PASSIVE) {
|
||||
if (family != AF_INET6)
|
||||
buf[cnt++] = (struct address){ .family = AF_INET };
|
||||
if (family != AF_INET)
|
||||
buf[cnt++] = (struct address){ .family = AF_INET6 };
|
||||
} else {
|
||||
if (family != AF_INET6)
|
||||
buf[cnt++] = (struct address){ .family = AF_INET, .addr = { 127,0,0,1 } };
|
||||
if (family != AF_INET)
|
||||
buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } };
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
static int name_from_numeric(struct address buf[static 1], const char *name, int family)
|
||||
{
|
||||
return __lookup_ipliteral(buf, name, family);
|
||||
}
|
||||
|
||||
static int name_from_hosts(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
|
||||
{
|
||||
char line[512];
|
||||
size_t l = strlen(name);
|
||||
int cnt = 0, badfam = 0, have_canon = 0;
|
||||
|
||||
/* get path of /etc/hosts */
|
||||
char etc_hosts_buf[256];
|
||||
const char *etc_hosts_path =
|
||||
GetHostsTxtPath(etc_hosts_buf,
|
||||
sizeof(etc_hosts_buf));
|
||||
|
||||
/* open hosts definitions file */
|
||||
FILE *f = fopen(etc_hosts_path, "rbe");
|
||||
if (!f) switch (errno) {
|
||||
case ENOENT:
|
||||
case ENOTDIR:
|
||||
case EACCES:
|
||||
return 0;
|
||||
default:
|
||||
return EAI_SYSTEM;
|
||||
}
|
||||
|
||||
/* read hosts definitions file */
|
||||
while (fgets(line, sizeof line, f) && cnt < MAXADDRS) {
|
||||
char *p, *z;
|
||||
|
||||
if ((p=strchr(line, '#'))) *p++='\n', *p=0;
|
||||
for(p=line+1; (p=strstr(p, name)) &&
|
||||
(!isspace(p[-1]) || !isspace(p[l])); p++);
|
||||
if (!p) continue;
|
||||
|
||||
/* Isolate IP address to parse */
|
||||
for (p=line; *p && !isspace(*p); p++);
|
||||
*p++ = 0;
|
||||
switch (name_from_numeric(buf+cnt, line, family)) {
|
||||
case 1:
|
||||
cnt++;
|
||||
break;
|
||||
case 0:
|
||||
continue;
|
||||
default:
|
||||
badfam = EAI_NODATA;
|
||||
break;
|
||||
}
|
||||
|
||||
if (have_canon) continue;
|
||||
|
||||
/* Extract first name as canonical name */
|
||||
for (; *p && isspace(*p); p++);
|
||||
for (z=p; *z && !isspace(*z); z++);
|
||||
*z = 0;
|
||||
if (is_valid_hostname(p)) {
|
||||
have_canon = 1;
|
||||
memcpy(canon, p, z-p+1);
|
||||
}
|
||||
}
|
||||
|
||||
/* close hosts definitions file */
|
||||
fclose(f);
|
||||
return cnt ? cnt : badfam;
|
||||
}
|
||||
|
||||
struct dpc_ctx {
|
||||
struct address *addrs;
|
||||
char *canon;
|
||||
int cnt;
|
||||
int rrtype;
|
||||
};
|
||||
|
||||
#define RR_A 1
|
||||
#define RR_CNAME 5
|
||||
#define RR_AAAA 28
|
||||
|
||||
#define ABUF_SIZE 4800
|
||||
|
||||
static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet, int plen)
|
||||
{
|
||||
char tmp[256];
|
||||
int family;
|
||||
struct dpc_ctx *ctx = c;
|
||||
if (rr == RR_CNAME) {
|
||||
if (__dn_expand(packet, (const unsigned char *)packet + plen,
|
||||
data, tmp, sizeof tmp) > 0 && is_valid_hostname(tmp))
|
||||
strcpy(ctx->canon, tmp);
|
||||
return 0;
|
||||
}
|
||||
if (ctx->cnt >= MAXADDRS) return 0;
|
||||
if (rr != ctx->rrtype) return 0;
|
||||
switch (rr) {
|
||||
case RR_A:
|
||||
if (len != 4) return -1;
|
||||
family = AF_INET;
|
||||
break;
|
||||
case RR_AAAA:
|
||||
if (len != 16) return -1;
|
||||
family = AF_INET6;
|
||||
break;
|
||||
default:
|
||||
__builtin_unreachable();
|
||||
}
|
||||
ctx->addrs[ctx->cnt].family = family;
|
||||
ctx->addrs[ctx->cnt].scopeid = 0;
|
||||
memcpy(ctx->addrs[ctx->cnt++].addr, data, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, const struct resolvconf *conf)
|
||||
{
|
||||
#pragma GCC push_options
|
||||
#pragma GCC diagnostic ignored "-Wframe-larger-than="
|
||||
unsigned char abuf[2][ABUF_SIZE];
|
||||
CheckLargeStackAllocation(abuf, sizeof(abuf));
|
||||
#pragma GCC pop_options
|
||||
unsigned char qbuf[2][280];
|
||||
const unsigned char *qp[2] = { qbuf[0], qbuf[1] };
|
||||
unsigned char *ap[2] = { abuf[0], abuf[1] };
|
||||
int qlens[2], alens[2], qtypes[2];
|
||||
int i, nq = 0;
|
||||
struct dpc_ctx ctx = { .addrs = buf, .canon = canon };
|
||||
const struct { int af; int rr; } afrr[2] = {
|
||||
{ .af = AF_INET6, .rr = RR_A },
|
||||
{ .af = AF_INET, .rr = RR_AAAA },
|
||||
};
|
||||
|
||||
for (i=0; i<2; i++) {
|
||||
if (family != afrr[i].af) {
|
||||
qlens[nq] = __res_mkquery(0, name, 1, afrr[i].rr,
|
||||
0, 0, 0, qbuf[nq], sizeof *qbuf);
|
||||
if (qlens[nq] == -1)
|
||||
return 0;
|
||||
qtypes[nq] = afrr[i].rr;
|
||||
qbuf[nq][3] = 0; /* don't need AD flag */
|
||||
/* Ensure query IDs are distinct. */
|
||||
if (nq && qbuf[nq][0] == qbuf[0][0])
|
||||
qbuf[nq][0]++;
|
||||
nq++;
|
||||
}
|
||||
}
|
||||
|
||||
if (__res_msend_rc(nq, qp, qlens, ap, alens, sizeof *abuf, conf) < 0)
|
||||
return EAI_SYSTEM;
|
||||
|
||||
for (i=0; i<nq; i++) {
|
||||
if (alens[i] < 4 || (abuf[i][3] & 15) == 2) return EAI_AGAIN;
|
||||
if ((abuf[i][3] & 15) == 3) return 0;
|
||||
if ((abuf[i][3] & 15) != 0) return EAI_FAIL;
|
||||
}
|
||||
|
||||
for (i=nq-1; i>=0; i--) {
|
||||
ctx.rrtype = qtypes[i];
|
||||
if (alens[i] > sizeof(abuf[i])) alens[i] = sizeof abuf[i];
|
||||
__dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx);
|
||||
}
|
||||
|
||||
if (ctx.cnt) return ctx.cnt;
|
||||
return EAI_NODATA;
|
||||
}
|
||||
|
||||
static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family)
|
||||
{
|
||||
char search[256];
|
||||
struct resolvconf conf;
|
||||
size_t l, dots;
|
||||
char *p, *z;
|
||||
|
||||
if (__get_resolv_conf(&conf, search, sizeof search) < 0) return -1;
|
||||
|
||||
/* Count dots, suppress search when >=ndots or name ends in
|
||||
* a dot, which is an explicit request for global scope. */
|
||||
for (dots=l=0; name[l]; l++) if (name[l]=='.') dots++;
|
||||
if (dots >= conf.ndots || name[l-1]=='.') *search = 0;
|
||||
|
||||
/* Strip final dot for canon, fail if multiple trailing dots. */
|
||||
if (name[l-1]=='.') l--;
|
||||
if (!l || name[l-1]=='.') return EAI_NONAME;
|
||||
|
||||
/* This can never happen; the caller already checked length. */
|
||||
if (l >= 256) return EAI_NONAME;
|
||||
|
||||
/* Name with search domain appended is setup in canon[]. This both
|
||||
* provides the desired default canonical name (if the requested
|
||||
* name is not a CNAME record) and serves as a buffer for passing
|
||||
* the full requested name to name_from_dns. */
|
||||
memcpy(canon, name, l);
|
||||
canon[l] = '.';
|
||||
|
||||
for (p=search; *p; p=z) {
|
||||
for (; isspace(*p); p++);
|
||||
for (z=p; *z && !isspace(*z); z++);
|
||||
if (z==p) break;
|
||||
if (z-p < 256 - l - 1) {
|
||||
memcpy(canon+l+1, p, z-p);
|
||||
canon[z-p+1+l] = 0;
|
||||
int cnt = name_from_dns(buf, canon, canon, family, &conf);
|
||||
if (cnt) return cnt;
|
||||
}
|
||||
}
|
||||
|
||||
canon[l] = 0;
|
||||
return name_from_dns(buf, canon, name, family, &conf);
|
||||
}
|
||||
|
||||
static const struct policy {
|
||||
unsigned char addr[16];
|
||||
unsigned char len, mask;
|
||||
unsigned char prec, label;
|
||||
} defpolicy[] = {
|
||||
{ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1", 15, 0xff, 50, 0 },
|
||||
{ "\0\0\0\0\0\0\0\0\0\0\xff\xff", 11, 0xff, 35, 4 },
|
||||
{ "\x20\2", 1, 0xff, 30, 2 },
|
||||
{ "\x20\1", 3, 0xff, 5, 5 },
|
||||
{ "\xfc", 0, 0xfe, 3, 13 },
|
||||
#if 0
|
||||
/* These are deprecated and/or returned to the address
|
||||
* pool, so despite the RFC, treating them as special
|
||||
* is probably wrong. */
|
||||
{ "", 11, 0xff, 1, 3 },
|
||||
{ "\xfe\xc0", 1, 0xc0, 1, 11 },
|
||||
{ "\x3f\xfe", 1, 0xff, 1, 12 },
|
||||
#endif
|
||||
/* Last rule must match all addresses to stop loop. */
|
||||
{ "", 0, 0, 40, 1 },
|
||||
};
|
||||
|
||||
static const struct policy *policyof(const struct in6_addr *a)
|
||||
{
|
||||
int i;
|
||||
for (i=0; ; i++) {
|
||||
if (memcmp(a->s6_addr, defpolicy[i].addr, defpolicy[i].len))
|
||||
continue;
|
||||
if ((a->s6_addr[defpolicy[i].len] & defpolicy[i].mask)
|
||||
!= defpolicy[i].addr[defpolicy[i].len])
|
||||
continue;
|
||||
return defpolicy+i;
|
||||
}
|
||||
}
|
||||
|
||||
static int labelof(const struct in6_addr *a)
|
||||
{
|
||||
return policyof(a)->label;
|
||||
}
|
||||
|
||||
static int scopeof(const struct in6_addr *a)
|
||||
{
|
||||
if (IN6_IS_ADDR_MULTICAST(a)) return a->s6_addr[1] & 15;
|
||||
if (IN6_IS_ADDR_LINKLOCAL(a)) return 2;
|
||||
if (IN6_IS_ADDR_LOOPBACK(a)) return 2;
|
||||
if (IN6_IS_ADDR_SITELOCAL(a)) return 5;
|
||||
return 14;
|
||||
}
|
||||
|
||||
static int prefixmatch(const struct in6_addr *s, const struct in6_addr *d)
|
||||
{
|
||||
/* FIXME: The common prefix length should be limited to no greater
|
||||
* than the nominal length of the prefix portion of the source
|
||||
* address. However the definition of the source prefix length is
|
||||
* not clear and thus this limiting is not yet implemented. */
|
||||
unsigned i;
|
||||
for (i=0; i<128 && !((s->s6_addr[i/8]^d->s6_addr[i/8])&(128>>(i%8))); i++);
|
||||
return i;
|
||||
}
|
||||
|
||||
#define DAS_USABLE 0x40000000
|
||||
#define DAS_MATCHINGSCOPE 0x20000000
|
||||
#define DAS_MATCHINGLABEL 0x10000000
|
||||
#define DAS_PREC_SHIFT 20
|
||||
#define DAS_SCOPE_SHIFT 16
|
||||
#define DAS_PREFIX_SHIFT 8
|
||||
#define DAS_ORDER_SHIFT 0
|
||||
|
||||
static int addrcmp(const void *_a, const void *_b)
|
||||
{
|
||||
const struct address *a = _a, *b = _b;
|
||||
return b->sortkey - a->sortkey;
|
||||
}
|
||||
|
||||
int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags)
|
||||
{
|
||||
int cnt = 0, i, j;
|
||||
|
||||
*canon = 0;
|
||||
if (name) {
|
||||
/* reject empty name and check len so it fits into temp bufs */
|
||||
size_t l = strnlen(name, 255);
|
||||
if (l-1 >= 254)
|
||||
return EAI_NONAME;
|
||||
memcpy(canon, name, l+1);
|
||||
}
|
||||
|
||||
/* Procedurally, a request for v6 addresses with the v4-mapped
|
||||
* flag set is like a request for unspecified family, followed
|
||||
* by filtering of the results. */
|
||||
if (flags & AI_V4MAPPED) {
|
||||
if (family == AF_INET6) family = AF_UNSPEC;
|
||||
else flags -= AI_V4MAPPED;
|
||||
}
|
||||
|
||||
/* Try each backend until there's at least one result. */
|
||||
cnt = name_from_null(buf, name, family, flags);
|
||||
if (!cnt) cnt = name_from_numeric(buf, name, family);
|
||||
if (!cnt && !(flags & AI_NUMERICHOST)) {
|
||||
cnt = name_from_hosts(buf, canon, name, family);
|
||||
if (!cnt) cnt = name_from_dns_search(buf, canon, name, family);
|
||||
}
|
||||
if (cnt<=0) return cnt ? cnt : EAI_NONAME;
|
||||
|
||||
/* Filter/transform results for v4-mapped lookup, if requested. */
|
||||
if (flags & AI_V4MAPPED) {
|
||||
if (!(flags & AI_ALL)) {
|
||||
/* If any v6 results exist, remove v4 results. */
|
||||
for (i=0; i<cnt && buf[i].family != AF_INET6; i++);
|
||||
if (i<cnt) {
|
||||
for (j=0; i<cnt; i++) {
|
||||
if (buf[i].family == AF_INET6)
|
||||
buf[j++] = buf[i];
|
||||
}
|
||||
cnt = i = j;
|
||||
}
|
||||
}
|
||||
/* Translate any remaining v4 results to v6 */
|
||||
for (i=0; i<cnt; i++) {
|
||||
if (buf[i].family != AF_INET) continue;
|
||||
memcpy(buf[i].addr+12, buf[i].addr, 4);
|
||||
memcpy(buf[i].addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
|
||||
buf[i].family = AF_INET6;
|
||||
}
|
||||
}
|
||||
|
||||
/* No further processing is needed if there are fewer than 2
|
||||
* results or if there are only IPv4 results. */
|
||||
if (cnt<2 || family==AF_INET) return cnt;
|
||||
for (i=0; i<cnt; i++) if (buf[i].family != AF_INET) break;
|
||||
if (i==cnt) return cnt;
|
||||
|
||||
int cs;
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
|
||||
|
||||
/* The following implements a subset of RFC 3484/6724 destination
|
||||
* address selection by generating a single 31-bit sort key for
|
||||
* each address. Rules 3, 4, and 7 are omitted for having
|
||||
* excessive runtime and code size cost and dubious benefit.
|
||||
* So far the label/precedence table cannot be customized. */
|
||||
for (i=0; i<cnt; i++) {
|
||||
int family = buf[i].family;
|
||||
int key = 0;
|
||||
struct sockaddr_in6 sa6 = { 0 }, da6 = {
|
||||
.sin6_family = AF_INET6,
|
||||
.sin6_scope_id = buf[i].scopeid,
|
||||
.sin6_port = 65535
|
||||
};
|
||||
struct sockaddr_in sa4 = { 0 }, da4 = {
|
||||
.sin_family = AF_INET,
|
||||
.sin_port = 65535
|
||||
};
|
||||
void *sa, *da;
|
||||
socklen_t salen, dalen;
|
||||
if (family == AF_INET6) {
|
||||
memcpy(da6.sin6_addr.s6_addr, buf[i].addr, 16);
|
||||
da = &da6; dalen = sizeof da6;
|
||||
sa = &sa6; salen = sizeof sa6;
|
||||
} else {
|
||||
memcpy(sa6.sin6_addr.s6_addr,
|
||||
"\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
|
||||
memcpy(da6.sin6_addr.s6_addr+12, buf[i].addr, 4);
|
||||
memcpy(da6.sin6_addr.s6_addr,
|
||||
"\0\0\0\0\0\0\0\0\0\0\xff\xff", 12);
|
||||
memcpy(da6.sin6_addr.s6_addr+12, buf[i].addr, 4);
|
||||
memcpy(&da4.sin_addr, buf[i].addr, 4);
|
||||
da = &da4; dalen = sizeof da4;
|
||||
sa = &sa4; salen = sizeof sa4;
|
||||
}
|
||||
const struct policy *dpolicy = policyof(&da6.sin6_addr);
|
||||
int dscope = scopeof(&da6.sin6_addr);
|
||||
int dlabel = dpolicy->label;
|
||||
int dprec = dpolicy->prec;
|
||||
int prefixlen = 0;
|
||||
int fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP);
|
||||
if (fd >= 0) {
|
||||
if (!connect(fd, da, dalen)) {
|
||||
key |= DAS_USABLE;
|
||||
if (!getsockname(fd, sa, &salen)) {
|
||||
if (family == AF_INET) memcpy(
|
||||
sa6.sin6_addr.s6_addr+12,
|
||||
&sa4.sin_addr, 4);
|
||||
if (dscope == scopeof(&sa6.sin6_addr))
|
||||
key |= DAS_MATCHINGSCOPE;
|
||||
if (dlabel == labelof(&sa6.sin6_addr))
|
||||
key |= DAS_MATCHINGLABEL;
|
||||
prefixlen = prefixmatch(&sa6.sin6_addr,
|
||||
&da6.sin6_addr);
|
||||
}
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
key |= dprec << DAS_PREC_SHIFT;
|
||||
key |= (15-dscope) << DAS_SCOPE_SHIFT;
|
||||
key |= prefixlen << DAS_PREFIX_SHIFT;
|
||||
key |= (MAXADDRS-i) << DAS_ORDER_SHIFT;
|
||||
buf[i].sortkey = key;
|
||||
}
|
||||
qsort(buf, cnt, sizeof *buf, addrcmp);
|
||||
|
||||
pthread_setcancelstate(cs, 0);
|
||||
|
||||
return cnt;
|
||||
}
|
154
third_party/musl/lookup_serv.c
vendored
Normal file
154
third_party/musl/lookup_serv.c
vendored
Normal file
|
@ -0,0 +1,154 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/sysv/consts/ipproto.h"
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/stdio/internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/calls/sysdir.internal.h"
|
||||
#include "third_party/musl/lookup.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
int __lookup_serv(struct service buf[static MAXSERVS],
|
||||
const char *name,
|
||||
int proto,
|
||||
int socktype,
|
||||
int flags)
|
||||
{
|
||||
char line[128];
|
||||
int cnt = 0;
|
||||
char *p, *z = "";
|
||||
unsigned long port = 0;
|
||||
|
||||
switch (socktype) {
|
||||
case SOCK_STREAM:
|
||||
switch (proto) {
|
||||
case 0:
|
||||
proto = IPPROTO_TCP;
|
||||
case IPPROTO_TCP:
|
||||
break;
|
||||
default:
|
||||
return EAI_SERVICE;
|
||||
}
|
||||
break;
|
||||
case SOCK_DGRAM:
|
||||
switch (proto) {
|
||||
case 0:
|
||||
proto = IPPROTO_UDP;
|
||||
case IPPROTO_UDP:
|
||||
break;
|
||||
default:
|
||||
return EAI_SERVICE;
|
||||
}
|
||||
case 0:
|
||||
break;
|
||||
default:
|
||||
if (name) return EAI_SERVICE;
|
||||
buf[0].port = 0;
|
||||
buf[0].proto = proto;
|
||||
buf[0].socktype = socktype;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (name) {
|
||||
if (!*name) return EAI_SERVICE;
|
||||
port = strtoul(name, &z, 10);
|
||||
}
|
||||
if (!*z) {
|
||||
if (port > 65535) return EAI_SERVICE;
|
||||
if (proto != IPPROTO_UDP) {
|
||||
buf[cnt].port = port;
|
||||
buf[cnt].socktype = SOCK_STREAM;
|
||||
buf[cnt++].proto = IPPROTO_TCP;
|
||||
}
|
||||
if (proto != IPPROTO_TCP) {
|
||||
buf[cnt].port = port;
|
||||
buf[cnt].socktype = SOCK_DGRAM;
|
||||
buf[cnt++].proto = IPPROTO_UDP;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
if (flags & AI_NUMERICSERV) return EAI_NONAME;
|
||||
|
||||
size_t l = strlen(name);
|
||||
|
||||
/* get path of /etc/services */
|
||||
char etc_services_buf[256];
|
||||
const char *etc_services_path =
|
||||
GetServicesTxtPath(etc_services_buf,
|
||||
sizeof(etc_services_buf));
|
||||
|
||||
/* open services definitions file */
|
||||
FILE *f = fopen(etc_services_path, "rbe");
|
||||
if (!f) switch (errno) {
|
||||
case ENOENT:
|
||||
case ENOTDIR:
|
||||
case EACCES:
|
||||
return EAI_SERVICE;
|
||||
default:
|
||||
return EAI_SYSTEM;
|
||||
}
|
||||
|
||||
while (fgets(line, sizeof line, f) && cnt < MAXSERVS) {
|
||||
if ((p=strchr(line, '#'))) *p++='\n', *p=0;
|
||||
|
||||
/* Find service name */
|
||||
for(p=line; (p=strstr(p, name)); p++) {
|
||||
if (p>line && !isspace(p[-1])) continue;
|
||||
if (p[l] && !isspace(p[l])) continue;
|
||||
break;
|
||||
}
|
||||
if (!p) continue;
|
||||
|
||||
/* Skip past canonical name at beginning of line */
|
||||
for (p=line; *p && !isspace(*p); p++);
|
||||
|
||||
port = strtoul(p, &z, 10);
|
||||
if (port > 65535 || z==p) continue;
|
||||
if (!strncmp(z, "/udp", 4)) {
|
||||
if (proto == IPPROTO_TCP) continue;
|
||||
buf[cnt].port = port;
|
||||
buf[cnt].socktype = SOCK_DGRAM;
|
||||
buf[cnt++].proto = IPPROTO_UDP;
|
||||
}
|
||||
if (!strncmp(z, "/tcp", 4)) {
|
||||
if (proto == IPPROTO_UDP) continue;
|
||||
buf[cnt].port = port;
|
||||
buf[cnt].socktype = SOCK_STREAM;
|
||||
buf[cnt++].proto = IPPROTO_TCP;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return cnt > 0 ? cnt : EAI_SERVICE;
|
||||
}
|
138
third_party/musl/netdb.h
vendored
Normal file
138
third_party/musl/netdb.h
vendored
Normal file
|
@ -0,0 +1,138 @@
|
|||
#ifndef COSMOPOLITAN_THIRD_PARTY_MUSL_NETDB_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_MUSL_NETDB_H_
|
||||
#include "libc/sock/struct/sockaddr.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct addrinfo {
|
||||
int ai_flags;
|
||||
int ai_family;
|
||||
int ai_socktype;
|
||||
int ai_protocol;
|
||||
uint32_t ai_addrlen;
|
||||
struct sockaddr *ai_addr;
|
||||
char *ai_canonname;
|
||||
struct addrinfo *ai_next;
|
||||
};
|
||||
|
||||
#define AI_PASSIVE 0x01
|
||||
#define AI_CANONNAME 0x02
|
||||
#define AI_NUMERICHOST 0x04
|
||||
#define AI_V4MAPPED 0x08
|
||||
#define AI_ALL 0x10
|
||||
#define AI_ADDRCONFIG 0x20
|
||||
#define AI_NUMERICSERV 0x400
|
||||
|
||||
#define NI_NUMERICHOST 0x01
|
||||
#define NI_NUMERICSERV 0x02
|
||||
#define NI_NOFQDN 0x04
|
||||
#define NI_NAMEREQD 0x08
|
||||
#define NI_DGRAM 0x10
|
||||
#define NI_NUMERICSCOPE 0x100
|
||||
|
||||
#define EAI_BADFLAGS -1
|
||||
#define EAI_NONAME -2
|
||||
#define EAI_AGAIN -3
|
||||
#define EAI_FAIL -4
|
||||
#define EAI_FAMILY -6
|
||||
#define EAI_SOCKTYPE -7
|
||||
#define EAI_SERVICE -8
|
||||
#define EAI_MEMORY -10
|
||||
#define EAI_SYSTEM -11
|
||||
#define EAI_OVERFLOW -12
|
||||
|
||||
int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **);
|
||||
void freeaddrinfo (struct addrinfo *);
|
||||
int getnameinfo (const struct sockaddr *, uint32_t, char *, uint32_t, char *, uint32_t, int);
|
||||
const char *gai_strerror(int);
|
||||
|
||||
|
||||
/* Legacy functions follow (marked OBsolete in SUS) */
|
||||
|
||||
struct netent {
|
||||
char *n_name;
|
||||
char **n_aliases;
|
||||
int n_addrtype;
|
||||
uint32_t n_net;
|
||||
};
|
||||
|
||||
struct hostent {
|
||||
char *h_name;
|
||||
char **h_aliases;
|
||||
int h_addrtype;
|
||||
int h_length;
|
||||
char **h_addr_list;
|
||||
};
|
||||
#define h_addr h_addr_list[0]
|
||||
|
||||
struct servent {
|
||||
char *s_name;
|
||||
char **s_aliases;
|
||||
int s_port;
|
||||
char *s_proto;
|
||||
};
|
||||
|
||||
struct protoent {
|
||||
char *p_name;
|
||||
char **p_aliases;
|
||||
int p_proto;
|
||||
};
|
||||
|
||||
void sethostent (int);
|
||||
void endhostent (void);
|
||||
struct hostent *gethostent (void);
|
||||
|
||||
void setnetent (int);
|
||||
void endnetent (void);
|
||||
struct netent *getnetent (void);
|
||||
struct netent *getnetbyaddr (uint32_t, int);
|
||||
struct netent *getnetbyname (const char *);
|
||||
|
||||
void setservent (int);
|
||||
void endservent (void);
|
||||
struct servent *getservent (void);
|
||||
struct servent *getservbyname (const char *, const char *);
|
||||
struct servent *getservbyport (int, const char *);
|
||||
|
||||
void setprotoent (int);
|
||||
void endprotoent (void);
|
||||
struct protoent *getprotoent (void);
|
||||
struct protoent *getprotobyname (const char *);
|
||||
struct protoent *getprotobynumber (int);
|
||||
|
||||
#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
|
||||
|| (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
|
||||
|| (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
|
||||
struct hostent *gethostbyname (const char *);
|
||||
struct hostent *gethostbyaddr (const void *, uint32_t, int);
|
||||
errno_t *__h_errno_location(void) dontthrow pureconst;
|
||||
#define h_errno (*__h_errno_location())
|
||||
#define HOST_NOT_FOUND 1
|
||||
#define TRY_AGAIN 2
|
||||
#define NO_RECOVERY 3
|
||||
#define NO_DATA 4
|
||||
#define NO_ADDRESS NO_DATA
|
||||
#endif
|
||||
|
||||
#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
|
||||
void herror(const char *);
|
||||
const char *hstrerror(int);
|
||||
int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
|
||||
int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
|
||||
struct hostent *gethostbyname2(const char *, int);
|
||||
int gethostbyaddr_r(const void *, uint32_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
|
||||
int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
|
||||
int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
|
||||
#define EAI_NODATA -5
|
||||
#define EAI_ADDRFAMILY -9
|
||||
#define EAI_INPROGRESS -100
|
||||
#define EAI_CANCELED -101
|
||||
#define EAI_NOTCANCELED -102
|
||||
#define EAI_ALLDONE -103
|
||||
#define EAI_INTR -104
|
||||
#define EAI_IDN_ENCODE -105
|
||||
#define NI_MAXHOST 255
|
||||
#define NI_MAXSERV 32
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* COSMOPOLITAN_THIRD_PARTY_MUSL_NETDB_H_ */
|
38
third_party/musl/netname.c
vendored
Normal file
38
third_party/musl/netname.c
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
struct netent *getnetbyaddr(uint32_t net, int type)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct netent *getnetbyname(const char *name)
|
||||
{
|
||||
return 0;
|
||||
}
|
11
third_party/musl/passwd.h
vendored
11
third_party/musl/passwd.h
vendored
|
@ -1,10 +1,9 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_PASSWD_H_
|
||||
#define COSMOPOLITAN_LIBC_PASSWD_H_
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct FILE;
|
||||
|
||||
struct passwd {
|
||||
char *pw_name;
|
||||
char *pw_passwd;
|
||||
|
@ -22,8 +21,8 @@ struct passwd *getpwuid(uid_t);
|
|||
struct passwd *getpwnam(const char *);
|
||||
int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
|
||||
int getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
|
||||
struct passwd *fgetpwent(struct FILE *);
|
||||
int putpwent(const struct passwd *, struct FILE *);
|
||||
struct passwd *fgetpwent(FILE *);
|
||||
int putpwent(const struct passwd *, FILE *);
|
||||
|
||||
struct group {
|
||||
char *gr_name;
|
||||
|
@ -39,8 +38,8 @@ int getgrnam_r(const char *, struct group *, char *, size_t, struct group **);
|
|||
struct group *getgrent(void);
|
||||
void endgrent(void);
|
||||
void setgrent(void);
|
||||
struct group *fgetgrent(struct FILE *);
|
||||
int putgrent(const struct group *, struct FILE *);
|
||||
struct group *fgetgrent(FILE *);
|
||||
int putgrent(const struct group *, FILE *);
|
||||
int getgrouplist(const char *, gid_t, gid_t *, int *);
|
||||
int initgroups(const char *, gid_t);
|
||||
|
||||
|
|
116
third_party/musl/proto.c
vendored
Normal file
116
third_party/musl/proto.c
vendored
Normal file
|
@ -0,0 +1,116 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/str.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
Musl libc (MIT License)\\n\
|
||||
Copyright 2005-2014 Rich Felker, et. al.\"");
|
||||
asm(".include \"libc/disclaimer.inc\"");
|
||||
|
||||
/* do we really need all these?? */
|
||||
|
||||
static int idx;
|
||||
static const unsigned char protos[] = {
|
||||
"\000ip\0"
|
||||
"\001icmp\0"
|
||||
"\002igmp\0"
|
||||
"\003ggp\0"
|
||||
"\004ipencap\0"
|
||||
"\005st\0"
|
||||
"\006tcp\0"
|
||||
"\010egp\0"
|
||||
"\014pup\0"
|
||||
"\021udp\0"
|
||||
"\024hmp\0"
|
||||
"\026xns-idp\0"
|
||||
"\033rdp\0"
|
||||
"\035iso-tp4\0"
|
||||
"\044xtp\0"
|
||||
"\045ddp\0"
|
||||
"\046idpr-cmtp\0"
|
||||
"\051ipv6\0"
|
||||
"\053ipv6-route\0"
|
||||
"\054ipv6-frag\0"
|
||||
"\055idrp\0"
|
||||
"\056rsvp\0"
|
||||
"\057gre\0"
|
||||
"\062esp\0"
|
||||
"\063ah\0"
|
||||
"\071skip\0"
|
||||
"\072ipv6-icmp\0"
|
||||
"\073ipv6-nonxt\0"
|
||||
"\074ipv6-opts\0"
|
||||
"\111rspf\0"
|
||||
"\121vmtp\0"
|
||||
"\131ospf\0"
|
||||
"\136ipip\0"
|
||||
"\142encap\0"
|
||||
"\147pim\0"
|
||||
"\377raw"
|
||||
};
|
||||
|
||||
void endprotoent(void)
|
||||
{
|
||||
idx = 0;
|
||||
}
|
||||
|
||||
void setprotoent(int stayopen)
|
||||
{
|
||||
idx = 0;
|
||||
}
|
||||
|
||||
struct protoent *getprotoent(void)
|
||||
{
|
||||
static struct protoent p;
|
||||
static const char *aliases;
|
||||
if (idx >= sizeof protos) return NULL;
|
||||
p.p_proto = protos[idx];
|
||||
p.p_name = (char *)&protos[idx+1];
|
||||
p.p_aliases = (char **)&aliases;
|
||||
idx += strlen(p.p_name) + 2;
|
||||
return &p;
|
||||
}
|
||||
|
||||
struct protoent *getprotobyname(const char *name)
|
||||
{
|
||||
struct protoent *p;
|
||||
endprotoent();
|
||||
do p = getprotoent();
|
||||
while (p && strcmp(name, p->p_name));
|
||||
return p;
|
||||
}
|
||||
|
||||
struct protoent *getprotobynumber(int num)
|
||||
{
|
||||
struct protoent *p;
|
||||
endprotoent();
|
||||
do p = getprotoent();
|
||||
while (p && p->p_proto != num);
|
||||
return p;
|
||||
}
|
2
third_party/musl/pwd.c
vendored
2
third_party/musl/pwd.c
vendored
|
@ -100,7 +100,7 @@ __fopen_passwd(void)
|
|||
return f;
|
||||
if (!(s = __create_synthetic_passwd_file()))
|
||||
return 0;
|
||||
if (!(f = fmemopen(s, strlen(s), "rb")))
|
||||
if (!(f = fmemopen(s, strlen(s), "rbe")))
|
||||
free(s);
|
||||
return f;
|
||||
}
|
||||
|
|
8
third_party/musl/res_mkquery.c
vendored
8
third_party/musl/res_mkquery.c
vendored
|
@ -25,9 +25,9 @@
|
|||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "third_party/musl/resolv.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
|
@ -41,7 +41,6 @@ int __res_mkquery(int op, const char *dname, int class, int type,
|
|||
{
|
||||
int id, i, j;
|
||||
unsigned char q[280];
|
||||
struct timespec ts;
|
||||
size_t l = strnlen(dname, 255);
|
||||
int n;
|
||||
|
||||
|
@ -66,9 +65,8 @@ int __res_mkquery(int op, const char *dname, int class, int type,
|
|||
q[i+3] = class;
|
||||
|
||||
/* Make a reasonably unpredictable id */
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
id = (ts.tv_nsec + ts.tv_nsec/65536UL) & 0xffff;
|
||||
q[0] = id/256;
|
||||
id = _rand64();
|
||||
q[0] = id >> 8;
|
||||
q[1] = id;
|
||||
|
||||
memcpy(buf, q, n);
|
||||
|
|
30
third_party/musl/res_msend.c
vendored
30
third_party/musl/res_msend.c
vendored
|
@ -25,22 +25,25 @@
|
|||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/sock/struct/pollfd.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/sock/struct/msghdr.h"
|
||||
#include "libc/sysv/consts/poll.h"
|
||||
#include "libc/sysv/consts/tcp.h"
|
||||
#include "libc/sysv/consts/msg.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/calls/struct/timespec.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sock/struct/msghdr.h"
|
||||
#include "libc/sock/struct/pollfd.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/clock.h"
|
||||
#include "libc/sysv/consts/ipproto.h"
|
||||
#include "libc/sysv/consts/ipv6.h"
|
||||
#include "libc/sysv/consts/msg.h"
|
||||
#include "libc/sysv/consts/poll.h"
|
||||
#include "libc/sysv/consts/sock.h"
|
||||
#include "libc/sysv/consts/tcp.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "lookup.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
|
@ -79,7 +82,8 @@ static int start_tcp(struct pollfd *pfd, int family, const void *sa, socklen_t s
|
|||
int fd = socket(family, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
|
||||
pfd->fd = fd;
|
||||
pfd->events = POLLOUT;
|
||||
if (!setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT,
|
||||
if (IsLinux() &&
|
||||
!setsockopt(fd, IPPROTO_TCP, TCP_FASTOPEN_CONNECT,
|
||||
&(int){1}, sizeof(int))) {
|
||||
r = sendmsg(fd, &mh, MSG_FASTOPEN|MSG_NOSIGNAL);
|
||||
if (r == ql+2) pfd->events = POLLIN;
|
||||
|
|
2
third_party/musl/res_query.c
vendored
2
third_party/musl/res_query.c
vendored
|
@ -25,8 +25,8 @@
|
|||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dns/ent.h"
|
||||
#include "third_party/musl/resolv.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
#include "third_party/musl/resolv.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
|
|
3
third_party/musl/resolvconf.c
vendored
3
third_party/musl/resolvconf.c
vendored
|
@ -36,6 +36,7 @@
|
|||
#include "libc/stdio/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "third_party/musl/lookup.internal.h"
|
||||
|
||||
asm(".ident\t\"\\n\\n\
|
||||
|
@ -117,7 +118,7 @@ int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
|
|||
conf->attempts = 2;
|
||||
if (search) *search = 0;
|
||||
|
||||
f = fopen("/etc/resolv.conf", "rb");
|
||||
f = fopen("/etc/resolv.conf", "rbe");
|
||||
if (!f) {
|
||||
if (errno == ENOENT ||
|
||||
errno == ENOTDIR ||
|
||||
|
|
41
third_party/musl/serv.c
vendored
Normal file
41
third_party/musl/serv.c
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│
|
||||
│ vi: set noet ft=c ts=8 sw=8 fenc=utf-8 :vi │
|
||||
╚──────────────────────────────────────────────────────────────────────────────╝
|
||||
│ │
|
||||
│ Musl Libc │
|
||||
│ Copyright © 2005-2014 Rich Felker, et al. │
|
||||
│ │
|
||||
│ Permission is hereby granted, free of charge, to any person obtaining │
|
||||
│ a copy of this software and associated documentation files (the │
|
||||
│ "Software"), to deal in the Software without restriction, including │
|
||||
│ without limitation the rights to use, copy, modify, merge, publish, │
|
||||
│ distribute, sublicense, and/or sell copies of the Software, and to │
|
||||
│ permit persons to whom the Software is furnished to do so, subject to │
|
||||
│ the following conditions: │
|
||||
│ │
|
||||
│ The above copyright notice and this permission notice shall be │
|
||||
│ included in all copies or substantial portions of the Software. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, │
|
||||
│ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF │
|
||||
│ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. │
|
||||
│ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY │
|
||||
│ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, │
|
||||
│ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE │
|
||||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/musl/netdb.h"
|
||||
|
||||
void endservent(void)
|
||||
{
|
||||
}
|
||||
|
||||
void setservent(int stayopen)
|
||||
{
|
||||
}
|
||||
|
||||
struct servent *getservent(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
1
third_party/python/BUILD.mk
vendored
1
third_party/python/BUILD.mk
vendored
|
@ -1165,7 +1165,6 @@ THIRD_PARTY_PYTHON_STAGE2_A_DATA = \
|
|||
THIRD_PARTY_PYTHON_STAGE2_A_DIRECTDEPS = \
|
||||
DSP_CORE \
|
||||
LIBC_CALLS \
|
||||
LIBC_DNS \
|
||||
LIBC_FMT \
|
||||
LIBC_INTRIN \
|
||||
LIBC_LOG \
|
||||
|
|
3
third_party/python/Modules/socketmodule.c
vendored
3
third_party/python/Modules/socketmodule.c
vendored
|
@ -8,8 +8,6 @@
|
|||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/dns/dns.h"
|
||||
#include "libc/dns/ent.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/nt/enum/version.h"
|
||||
#include "libc/nt/version.h"
|
||||
|
@ -55,6 +53,7 @@
|
|||
#include "third_party/python/Include/tupleobject.h"
|
||||
#include "third_party/python/Include/warnings.h"
|
||||
#include "third_party/python/Include/yoink.h"
|
||||
#include "third_party/musl/netdb.h"
|
||||
#include "third_party/python/pyconfig.h"
|
||||
|
||||
PYTHON_PROVIDE("_socket");
|
||||
|
|
11
third_party/stb/stb_image.h
vendored
11
third_party/stb/stb_image.h
vendored
|
@ -1,5 +1,6 @@
|
|||
#ifndef COSMOPOLITAN_THIRD_PARTY_STB_STB_IMAGE_H_
|
||||
#define COSMOPOLITAN_THIRD_PARTY_STB_STB_IMAGE_H_
|
||||
#include "libc/stdio/stdio.h"
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
enum {
|
||||
|
@ -10,8 +11,6 @@ enum {
|
|||
STBI_rgb_alpha = 4
|
||||
};
|
||||
|
||||
struct FILE;
|
||||
|
||||
typedef struct {
|
||||
// fill 'data' with 'size' bytes. return number of bytes actually read
|
||||
int (*read)(void *user, char *data, int size);
|
||||
|
@ -37,7 +36,7 @@ unsigned char *stbi_load_from_callbacks(stbi_io_callbacks const *clbk,
|
|||
|
||||
unsigned char *stbi_load(char const *filename, int *x, int *y,
|
||||
int *channels_in_file, int desired_channels);
|
||||
unsigned char *stbi_load_from_file(struct FILE *f, int *x, int *y,
|
||||
unsigned char *stbi_load_from_file(FILE *f, int *x, int *y,
|
||||
int *channels_in_file, int desired_channels);
|
||||
// for stbi_load_from_file, file pointer is left pointing immediately after
|
||||
// image
|
||||
|
@ -60,7 +59,7 @@ unsigned short *stbi_load_16_from_callbacks(stbi_io_callbacks const *clbk,
|
|||
|
||||
unsigned short *stbi_load_16(char const *filename, int *x, int *y,
|
||||
int *channels_in_file, int desired_channels);
|
||||
unsigned short *stbi_load_from_file_16(struct FILE *f, int *x, int *y,
|
||||
unsigned short *stbi_load_from_file_16(FILE *f, int *x, int *y,
|
||||
int *channels_in_file,
|
||||
int desired_channels);
|
||||
|
||||
|
@ -79,9 +78,9 @@ int stbi_is_16_bit_from_memory(unsigned char const *buffer, int len);
|
|||
int stbi_is_16_bit_from_callbacks(stbi_io_callbacks const *clbk, void *user);
|
||||
|
||||
int stbi_info(char const *filename, int *x, int *y, int *comp);
|
||||
int stbi_info_from_file(struct FILE *f, int *x, int *y, int *comp);
|
||||
int stbi_info_from_file(FILE *f, int *x, int *y, int *comp);
|
||||
int stbi_is_16_bit(char const *filename);
|
||||
int stbi_is_16_bit_from_file(struct FILE *f);
|
||||
int stbi_is_16_bit_from_file(FILE *f);
|
||||
|
||||
// for image formats that explicitly notate that they have premultiplied alpha,
|
||||
// we just return the colors as stored in the file. set this flag to force
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue