]> andersk Git - openssh.git/blobdiff - bsd-bindresvport.c
doc
[openssh.git] / bsd-bindresvport.c
index 04780673b7087b38ee77859d939817c5fe414f89..15bb667da50c43f8905f07076f07d13467afe463 100644 (file)
@@ -61,6 +61,7 @@ bindresvport_af(sd, sa, af)
        struct sockaddr_in *sin;
        struct sockaddr_in6 *sin6;
        u_int16_t *portp;
+       u_int16_t port;
        int salen;
        int i;
 
@@ -83,10 +84,13 @@ bindresvport_af(sd, sa, af)
        }
        sa->sa_family = af;
 
-       if (*portp == 0)
-               *portp = (u_int16_t)(arc4random() % NPORTS) + STARTPORT;
+       port = ntohs(*portp);
+       if (port == 0)
+               port = (arc4random() % NPORTS) + STARTPORT;
 
        for(i = 0; i < NPORTS; i++) {
+               *portp = htons(port);
+               
                error = bind(sd, sa, salen);
                
                /* Terminate on success */
@@ -97,7 +101,9 @@ bindresvport_af(sd, sa, af)
                if ((error < 0) && !((errno == EADDRINUSE) || (errno == EINVAL)))
                        break;
                        
-               *portp = (i % NPORTS) + STARTPORT;
+               port++;
+               if (port > ENDPORT)
+                       port = STARTPORT;
        }
 
        return (error);
This page took 0.047386 seconds and 4 git commands to generate.