diff options
Diffstat (limited to 'sockutil.c')
-rw-r--r-- | sockutil.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -49,8 +49,16 @@ getsockport(int sd) int bind_any(int minport) { + static int lastminport = 0; + static int nextport = 0; int sd; struct sockaddr_in addr; + + if (minport == lastminport) { + minport = nextport; + } else { + lastminport = minport; + } sd = socket(AF_INET, SOCK_STREAM, 0); if (sd == -1) return -1; @@ -59,6 +67,8 @@ bind_any(int minport) do { addr.sin_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, strerror(errno)); |