diff options
author | Markus Armbruster <armbru@redhat.com> | 2012-02-07 15:09:15 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2012-02-24 09:06:58 -0600 |
commit | 877691f96f4ffba2dba45ba5556eacd53b77237b (patch) | |
tree | a3a601eddef91cf5dc2d2f7d2a6ab39dfb53a76e /qemu-sockets.c | |
parent | 136faa362d2835998a04779696a504147cf410ce (diff) |
sockets: Clean up inet_listen_opts()'s convoluted bind() loop
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'qemu-sockets.c')
-rw-r--r-- | qemu-sockets.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/qemu-sockets.c b/qemu-sockets.c index e6e6c72dfd..6bcb8e3e0f 100644 --- a/qemu-sockets.c +++ b/qemu-sockets.c @@ -107,7 +107,7 @@ int inet_listen_opts(QemuOpts *opts, int port_offset) char port[33]; char uaddr[INET6_ADDRSTRLEN+1]; char uport[33]; - int slisten,rc,to,try_next; + int slisten, rc, to, port_min, port_max, p; memset(&ai,0, sizeof(ai)); ai.ai_flags = AI_PASSIVE | AI_ADDRCONFIG; @@ -159,20 +159,18 @@ int inet_listen_opts(QemuOpts *opts, int port_offset) } #endif - for (;;) { + port_min = inet_getport(e); + port_max = to ? to + port_offset : port_min; + for (p = port_min; p <= port_max; p++) { + inet_setport(e, p); if (bind(slisten, e->ai_addr, e->ai_addrlen) == 0) { goto listen; } - try_next = to && (inet_getport(e) <= to + port_offset); - if (!try_next) + if (p == port_max) { fprintf(stderr,"%s: bind(%s,%s,%d): %s\n", __FUNCTION__, inet_strfamily(e->ai_family), uaddr, inet_getport(e), strerror(errno)); - if (try_next) { - inet_setport(e, inet_getport(e) + 1); - continue; } - break; } closesocket(slisten); } |