]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
Make statd_get_socket actually honour the 'port' parameter.
authorneilbrown <neilbrown>
Mon, 28 Feb 2005 03:19:40 +0000 (03:19 +0000)
committerneilbrown <neilbrown>
Mon, 28 Feb 2005 03:19:40 +0000 (03:19 +0000)
ChangeLog
utils/statd/rmtcall.c

index 331364a7a2c6d2d2997059e3d5dc310a5df11fb9..271b2ee70730b3d2aaa094b6e3ad83d77c8c96dd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2005-02-28  Trond Myklebust <trond.myklebust@fys.uio.no>
+       * utils/statd/rmtcall.c(statd_get_socket): If a port number is
+       explicitly given, make sure to try to bind to that.
+       
 2005-01-11  Chip Salzenberg  <chip@pobox.com>
 
        * debian/changelog: Version 1.0.7-1.
index f6798f9b29b9e5623dd9617dd529b09b8b5cad34..474bbb4242b3a254ddb5af426abb53b130b9356c 100644 (file)
@@ -65,7 +65,7 @@ statd_get_socket(int port)
 
        memset(&sin, 0, sizeof(sin));
        sin.sin_family = AF_INET;
-       sin.sin_port = port;
+       sin.sin_addr.s_addr = INADDR_ANY;
        /*
         * If a local hostname is given (-n option to statd), bind to the address
         * specified. This is required to support clients that ignore the mon_name in
@@ -76,11 +76,18 @@ statd_get_socket(int port)
                if (hp)
                        sin.sin_addr = *(struct in_addr *) hp->h_addr;
        }
+       if (port != 0) {
+               sin.sin_port = htons(port);
+               if (bind(sockfd, &sin, sizeof(sin)) == 0)
+                       goto out_success;
+               note(N_CRIT, "statd: failed to bind to outgoing port, %d\n"
+                               "       falling back on randomly chosen port\n", port);
+       }
        if (bindresvport(sockfd, &sin) < 0) {
                dprintf(N_WARNING,
                        "process_hosts: can't bind to reserved port\n");
        }
-
+out_success:
        return sockfd;
 }