From: Terry Burton Date: Thu, 6 Jan 2022 20:17:54 +0000 (+0000) Subject: udpfromto: Use plain sendto if our source address is 0.0.0.0 or ::/0 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4daf1ed214c34a407563bc431c4bd9eff228b0f1;p=thirdparty%2Ffreeradius-server.git udpfromto: Use plain sendto if our source address is 0.0.0.0 or ::/0 FreeBSD sendmsg returns EINVAL if IP_SENDSRCADDR is INADDR_ANY{,6}. --- diff --git a/src/lib/util/udpfromto.c b/src/lib/util/udpfromto.c index f59b9c6945..539e83e774 100644 --- a/src/lib/util/udpfromto.c +++ b/src/lib/util/udpfromto.c @@ -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));