From: damien Date: Sat, 22 Jan 2000 07:17:42 +0000 (+0000) Subject: - Missing htons() in bsd-bindresvport.c, fix from Holger Trapp X-Git-Tag: V_1_2_2_PRE28~7 X-Git-Url: http://andersk.mit.edu/gitweb/openssh.git/commitdiff_plain/1e64903d1653d24b851863948965976860705910?ds=sidebyside - Missing htons() in bsd-bindresvport.c, fix from Holger Trapp --- diff --git a/ChangeLog b/ChangeLog index 60654d88..cc05e2a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,8 @@ - Make IPv4 use the default in RPM packages - Irix uses preformatted manpages + - Missing htons() in bsd-bindresvport.c, fix from Holger Trapp + 20000120 - Don't use getaddrinfo on AIX diff --git a/bsd-bindresvport.c b/bsd-bindresvport.c index 04780673..15bb667d 100644 --- a/bsd-bindresvport.c +++ b/bsd-bindresvport.c @@ -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);