SOURCES: libtirpc-more-ports.patch (NEW) - Added a optimization to...
baggins
baggins at pld-linux.org
Tue May 8 13:49:39 CEST 2007
Author: baggins Date: Tue May 8 11:49:39 2007 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- Added a optimization to bindresvport that allows more ports to be tried.
---- Files affected:
SOURCES:
libtirpc-more-ports.patch (NONE -> 1.1) (NEW)
---- Diffs:
================================================================
Index: SOURCES/libtirpc-more-ports.patch
diff -u /dev/null SOURCES/libtirpc-more-ports.patch:1.1
--- /dev/null Tue May 8 13:49:39 2007
+++ SOURCES/libtirpc-more-ports.patch Tue May 8 13:49:34 2007
@@ -0,0 +1,55 @@
+diff --git a/src/bindresvport.c b/src/bindresvport.c
+index b197efa..bc75d29 100644
+--- a/src/bindresvport.c
++++ b/src/bindresvport.c
+@@ -62,6 +62,7 @@ bindresvport(sd, sin)
+ #ifdef __linux__
+
+ #define STARTPORT 600
++#define LOWPORT 512
+ #define ENDPORT (IPPORT_RESERVED - 1)
+ #define NPORTS (ENDPORT - STARTPORT + 1)
+
+@@ -76,10 +77,13 @@ bindresvport_sa(sd, sa)
+ #ifdef INET6
+ struct sockaddr_in6 *sin6;
+ #endif
+- u_int16_t port;
+ u_int16_t *portp;
++ static u_int16_t port;
++ static short startport = STARTPORT;
+ socklen_t salen;
+- int i;
++ int nports = ENDPORT - startport + 1;
++ int endport = ENDPORT;
++ int i;
+
+ if (sa == NULL) {
+ salen = sizeof(myaddr);
+@@ -119,13 +123,22 @@ bindresvport_sa(sd, sa)
+ }
+ res = -1;
+ errno = EADDRINUSE;
+- for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; i++) {
++ again:
++ for (i = 0; i < nports; ++i) {
+ *portp = htons(port++);
+- if (port > ENDPORT) {
+- port = STARTPORT;
+- }
++ if (port > endport)
++ port = startport;
+ res = bind(sd, sa, salen);
++ if (res >= 0 || errno != EADDRINUSE)
++ break;
+ }
++ if (i == nports && startport != LOWPORT) {
++ startport = LOWPORT;
++ endport = STARTPORT - 1;
++ nports = STARTPORT - LOWPORT;
++ port = LOWPORT + port % (STARTPORT - LOWPORT);
++ goto again;
++ }
+ return (res);
+ }
+ #else
================================================================
More information about the pld-cvs-commit
mailing list