If no source IP, or AF_UNSPEC, use sendto(). This works around
authoraland <aland>
Thu, 8 Jun 2006 19:42:13 +0000 (19:42 +0000)
committeraland <aland>
Thu, 8 Jun 2006 19:42:13 +0000 (19:42 +0000)
the bug also fixed in 1.36/1.37 of src/main/listen.c.

src/lib/udpfromto.c

index fe986a0..dec4325 100644 (file)
@@ -180,11 +180,22 @@ int sendfromto(int s, void *buf, size_t len, int flags,
        struct in_pktinfo pktinfo, *pktinfo_ptr;
        memset(&pktinfo, 0, sizeof(struct in_pktinfo));
 # endif
+       struct sockaddr_in      *s4;
 
 # ifdef HAVE_IP_SENDSRCADDR
        char cmsgbuf[CMSG_SPACE(sizeof(struct in_addr))];
 # endif
 
+       s4 = (struct sockaddr_in *) from;
+
+       /*
+        *      Source is unset, empty, or unspecified,
+        *      fall back to sendto().
+        */
+       if (!s4 || (fromlen == 0) || (s4->sin_family == AF_UNSPEC)) {
+               return sendto(s, buf, len, flags, to, tolen);
+       }
+
        /* Set up iov and msgh structures. */
        memset(&msgh, 0, sizeof(struct msghdr));
        iov.iov_base = buf;