]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
connect to the remote side, not the local one...
authorAlan T. DeKok <aland@freeradius.org>
Thu, 24 Aug 2017 12:53:58 +0000 (08:53 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 24 Aug 2017 20:25:24 +0000 (16:25 -0400)
src/lib/util/socket.c

index 59a7cd6a2d2696252fb447978719f8aa986685ae..493d12ebb3310884137b17f5c517bad5d1fb60e3 100644 (file)
@@ -407,11 +407,6 @@ int fr_socket_client_udp(fr_ipaddr_t const *src_ipaddr, uint16_t *src_port, fr_i
                }
        }
 
-       if (fr_ipaddr_to_sockaddr(dst_ipaddr, dst_port, &salocal, &salen) < 0) {
-               close(sockfd);
-               return -1;
-       }
-
        /*
         *      Although we ignore SIGPIPE, some operating systems
         *      like BSD and OSX ignore the ignoring.
@@ -428,6 +423,13 @@ int fr_socket_client_udp(fr_ipaddr_t const *src_ipaddr, uint16_t *src_port, fr_i
        }
 #endif
 
+       /*
+        *      FreeBSD jail issues.  We bind to 0.0.0.0, but the
+        *      kernel instead binds us to a 1.2.3.4.  So once the
+        *      socket is bound, ask it what it's IP address is.
+        */
+       salen = sizeof(salocal);
+       memset(&salocal, 0, salen);
        if (getsockname(sockfd, (struct sockaddr *) &salocal, &salen) < 0) {
                fr_strerror_printf("Failed getting socket name: %s", fr_syserror(errno));
                return -1;
@@ -436,6 +438,14 @@ int fr_socket_client_udp(fr_ipaddr_t const *src_ipaddr, uint16_t *src_port, fr_i
        if (fr_ipaddr_from_sockaddr(&salocal, salen, &my_ipaddr, &my_port) < 0) return -1;
        if (src_port) *src_port = my_port;
 
+       /*
+        *      And now get our destination
+        */
+       if (fr_ipaddr_to_sockaddr(dst_ipaddr, dst_port, &salocal, &salen) < 0) {
+               close(sockfd);
+               return -1;
+       }
+
        if (connect(sockfd, (struct sockaddr *) &salocal, salen) < 0) {
                /*
                 *      POSIX says the only time we will get this,