Massively cleaned up #include's, so they're in a consistent
[freeradius.git] / src / lib / udpfromto.c
index fe986a0..e4535fc 100644 (file)
  * Version: $Id$
  */
 
-#include <freeradius-devel/autoconf.h>
+#include <freeradius-devel/ident.h>
+RCSID("$Id$")
 
-#ifdef WITH_UDPFROMTO
-static const char rcsid[] = "$Id$";
+#include <freeradius-devel/udpfromto.h>
 
-#include <sys/types.h>
+#ifdef WITH_UDPFROMTO
 
 #ifdef HAVE_SYS_UIO_H
 #include <sys/uio.h>
 #endif
 
-#include <netinet/in.h>
-#include <errno.h>
-#include <unistd.h>
 #include <fcntl.h>
-#include <string.h>
 
-#include <freeradius-devel/udpfromto.h>
 
 int udpfromto_init(int s)
 {
@@ -180,11 +175,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;