X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fnetwork%2Flookup_name.c;h=aa558c197abe813865ba28c1228be272bae62924;hb=b67d56c7b3b0f84360db749aa6f431a07761d9c8;hp=0e6db9ef0f78c835beca00e0034120d6b183932a;hpb=4f35eb7591031a1e5ef9828f9304361f282f28b9;p=musl diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c index 0e6db9ef..aa558c19 100644 --- a/src/network/lookup_name.c +++ b/src/network/lookup_name.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "lookup.h" #include "stdio_impl.h" #include "syscall.h" @@ -49,7 +50,7 @@ static int name_from_hosts(struct address buf[static MAXADDRS], char canon[stati { char line[512]; size_t l = strlen(name); - int cnt = 0, badfam = 0; + int cnt = 0, badfam = 0, have_canon = 0; unsigned char _buf[1032]; FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); if (!f) switch (errno) { @@ -79,14 +80,19 @@ static int name_from_hosts(struct address buf[static MAXADDRS], char canon[stati continue; default: badfam = EAI_NONAME; - continue; + 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)) memcpy(canon, p, z-p+1); + if (is_valid_hostname(p)) { + have_canon = 1; + memcpy(canon, p, z-p+1); + } } __fclose_ca(f); return cnt ? cnt : badfam; @@ -98,11 +104,6 @@ struct dpc_ctx { int cnt; }; -int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *), void *); -int __dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int); -int __res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int); -int __res_msend_rc(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int, const struct resolvconf *); - #define RR_A 1 #define RR_CNAME 5 #define RR_AAAA 28 @@ -153,6 +154,7 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 0, 0, 0, qbuf[nq], sizeof *qbuf); if (qlens[nq] == -1) return EAI_NONAME; + qbuf[nq][3] = 0; /* don't need AD flag */ nq++; } } @@ -160,14 +162,17 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static if (__res_msend_rc(nq, qp, qlens, ap, alens, sizeof *abuf, conf) < 0) return EAI_SYSTEM; + for (i=0; i