Skip to contentSkip to conversation

slirp: allow host port 0 for hostfwd

PATCH New Vincent Bernat 1 participant 1 message Feb 25, 2017 Networking

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 slirp: allow host port 0 for hostfwd

The OS will allocate automatically a free port. This is useful if you want to be sure to not get any port conflict. You still have to figure out which port you got, for example with "lsof" (this could be exposed in the monitor if needed).

Example of use:

     $ qemu-system-x86_64 -net user,hostfwd=127.0.0.1:0-:22 ...

Then, get your port with:

     $ lsof -np 1474 | grep LISTEN
     qemu-syst 31777 bernat 12u IPv4 [...] TCP 127.0.0.1:35145 (LISTEN)
---
 net/slirp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/slirp.c +1 -1
index f97ec233454e..11b2dd249a79 100644
@@ -487,7 +487,7 @@ static int slirp_hostfwd(SlirpState *s, const char *redir_str,
         goto fail_syntax;
     }
     host_port = strtol(buf, &end, 0);
-    if (*end != '\0' || host_port < 1 || host_port > 65535) {
+    if (*end != '\0' || host_port < 0 || host_port > 65535) {
         goto fail_syntax;
     }
 
Signature · 1 line
2.11.0