]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - resolv/res_send.c
time/tst-strftime2.c: Make the file easier to maintain
[thirdparty/glibc.git] / resolv / res_send.c
index dde0425a33d2b3d889d668a6ce311347ad8e4436..ca441c4ce1de95a0eb52b701718d0da49bb34c36 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2016-2018 Free Software Foundation, Inc.
+/* Copyright (C) 2016-2019 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
 #include <unistd.h>
 #include <kernel-features.h>
 #include <libc-diag.h>
-#include <hp-timing.h>
+#include <random-bits.h>
 
 #if PACKETSZ > 65536
 #define MAXPACKET       PACKETSZ
@@ -309,15 +309,7 @@ nameserver_offset (struct __res_state *statp)
   if ((offset & 1) == 0)
     {
       /* Initialization is required.  */
-#if HP_TIMING_AVAIL
-      uint64_t ticks;
-      HP_TIMING_NOW (ticks);
-      offset = ticks;
-#else
-      struct timeval tv;
-      __gettimeofday (&tv, NULL);
-      offset = ((tv.tv_sec << 8) ^ tv.tv_usec);
-#endif
+      offset = random_bits ();
       /* The lowest bit is the most random.  Preserve it.  */
       offset <<= 1;
 
@@ -471,6 +463,8 @@ __res_context_send (struct resolv_context *ctx,
                                        '\0',
                                        sizeof (struct sockaddr_in6)
                                        - sizeof (struct sockaddr_in));
+                       else
+                               return -1;
                }
                EXT(statp).nscount = statp->nscount;
        }
@@ -941,6 +935,18 @@ reopen (res_state statp, int *terrno, int ns)
                        return (-1);
                }
 
+               /* Enable full ICMP error reporting for this
+                  socket.  */
+               if (__res_enable_icmp (nsap->sa_family,
+                                      EXT (statp).nssocks[ns]) < 0)
+                 {
+                   int saved_errno = errno;
+                   __res_iclose (statp, false);
+                   __set_errno (saved_errno);
+                   *terrno = saved_errno;
+                   return -1;
+                 }
+
                /*
                 * On a 4.3BSD+ machine (client and server,
                 * actually), sending to a nameserver datagram
@@ -1152,25 +1158,27 @@ send_dg(res_state statp,
                if (have_sendmmsg >= 0 && nwritten == 0 && buf2 != NULL
                    && !single_request)
                  {
-                   struct iovec iov[2];
-                   struct mmsghdr reqs[2];
-                   reqs[0].msg_hdr.msg_name = NULL;
-                   reqs[0].msg_hdr.msg_namelen = 0;
-                   reqs[0].msg_hdr.msg_iov = &iov[0];
-                   reqs[0].msg_hdr.msg_iovlen = 1;
-                   iov[0].iov_base = (void *) buf;
-                   iov[0].iov_len = buflen;
-                   reqs[0].msg_hdr.msg_control = NULL;
-                   reqs[0].msg_hdr.msg_controllen = 0;
-
-                   reqs[1].msg_hdr.msg_name = NULL;
-                   reqs[1].msg_hdr.msg_namelen = 0;
-                   reqs[1].msg_hdr.msg_iov = &iov[1];
-                   reqs[1].msg_hdr.msg_iovlen = 1;
-                   iov[1].iov_base = (void *) buf2;
-                   iov[1].iov_len = buflen2;
-                   reqs[1].msg_hdr.msg_control = NULL;
-                   reqs[1].msg_hdr.msg_controllen = 0;
+                   struct iovec iov =
+                     { .iov_base = (void *) buf, .iov_len = buflen };
+                   struct iovec iov2 =
+                     { .iov_base = (void *) buf2, .iov_len = buflen2 };
+                   struct mmsghdr reqs[2] =
+                     {
+                       {
+                         .msg_hdr =
+                           {
+                             .msg_iov = &iov,
+                             .msg_iovlen = 1,
+                           },
+                       },
+                       {
+                         .msg_hdr =
+                           {
+                             .msg_iov = &iov2,
+                             .msg_iovlen = 1,
+                           }
+                       },
+                     };
 
                    int ndg = __sendmmsg (pfd[0].fd, reqs, 2, MSG_NOSIGNAL);
                    if (__glibc_likely (ndg == 2))