diff options
Diffstat (limited to 'sockutil.c')
-rw-r--r-- | sockutil.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -56,8 +56,16 @@ getsockport(int sd) int bind_any(int minport, unsigned short ss_family) { + static int lastminport = 0; + static int nextport = 0; int sd; struct sockaddr_storage addr; + + if (minport == lastminport) { + minport = nextport; + } else { + lastminport = minport; + } sd = socket(ss_family, SOCK_STREAM, 0); if (sd == -1) return -1; @@ -77,6 +85,7 @@ bind_any(int minport, unsigned short ss_family) ipv6p->sin6_port = htons(minport++); } while (bind(sd, (struct sockaddr *)&addr, sizeof addr) != 0); } + nextport = minport; if (listen(sd, 0) == -1) { syslog(LOG_WARNING, "listen error %d, %s", errno, |