summaryrefslogtreecommitdiffstats
path: root/sockutil.c
diff options
context:
space:
mode:
Diffstat (limited to 'sockutil.c')
-rw-r--r--sockutil.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/sockutil.c b/sockutil.c
index 05097b2..f13bcaf 100644
--- a/sockutil.c
+++ b/sockutil.c
@@ -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));