rework langinfo code for ABI compat and for use by time code
[musl] / src / network / __dns.c
index 8cd7d5d..372a587 100644 (file)
@@ -29,7 +29,7 @@ int __dns_doqueries(unsigned char *dest, const char *name, int *rr, int rrcnt)
        time_t t0 = time(0);
        int fd;
        FILE *f, _f;
-       unsigned char _buf[64];
+       unsigned char _buf[256];
        char line[64], *s, *z;
        union {
                struct sockaddr_in sin;
@@ -82,28 +82,28 @@ int __dns_doqueries(unsigned char *dest, const char *name, int *rr, int rrcnt)
        }
        if (f) __fclose_ca(f);
        if (!nns) {
-               ns[0].sin.sin_family = AF_INET;
+               ns[0].sin.sin_family = family = AF_INET;
                ns[0].sin.sin_port = htons(53);
+               ns[0].sin.sin_addr.s_addr = htonl(0x7f000001);
                nns=1;
                sl = sizeof sa.sin;
        }
 
        /* Get local address and open/bind a socket */
        sa.sin.sin_family = family;
-       fd = socket(family, SOCK_DGRAM, 0);
+       fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
+
+       pthread_cleanup_push(cleanup, (void *)(intptr_t)fd);
+       pthread_setcancelstate(cs, 0);
+
        if (bind(fd, (void *)&sa, sl) < 0) {
                errcode = EAI_SYSTEM;
                goto out;
        }
-       /* Nonblocking to work around Linux UDP select bug */
-       fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
 
        pfd.fd = fd;
        pfd.events = POLLIN;
 
-       pthread_cleanup_push(cleanup, (void *)(intptr_t)fd);
-       pthread_setcancelstate(cs, 0);
-
        /* Loop until we timeout; break early on success */
        for (; time(0)-t0 < TIMEOUT; ) {