]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
udpfromto: Use plain sendto if our source address is 0.0.0.0 or ::/0
authorTerry Burton <tez@terryburton.co.uk>
Thu, 6 Jan 2022 20:17:54 +0000 (20:17 +0000)
committerAlan T. DeKok <aland@freeradius.org>
Fri, 7 Jan 2022 14:29:20 +0000 (09:29 -0500)
FreeBSD sendmsg returns EINVAL if IP_SENDSRCADDR is INADDR_ANY{,6}.

src/lib/util/udpfromto.c

index f59b9c6945bd6154c007f8fa916d741774252ed7..539e83e774e7597fb8d0a3684bd999bf3ea764bc 100644 (file)
@@ -433,9 +433,15 @@ int sendfromto(int fd, void *buf, size_t len, int flags,
 #  endif
 
        /*
-        *      No "from", just use regular sendto.
+        *      No "from" or "from" is 0.0.0.0 or ::/0, just use regular sendto.
         */
-       if (!from || (from_len == 0)) return sendto(fd, buf, len, flags, to, to_len);
+       if (!from || (from_len == 0) ||
+               (from->sa_family == AF_INET &&
+                       (((struct sockaddr_in *) from)->sin_addr.s_addr == INADDR_ANY)) ||
+               (from->sa_family == AF_INET6 &&
+                       IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6 *) from)->sin6_addr))
+       )
+               return sendto(fd, buf, len, flags, to, to_len);
 
        /* Set up control buffer iov and msgh structures. */
        memset(&cbuf, 0, sizeof(cbuf));