Skip to content

Why can't you do add_hostfwd with a host_port of 0? #354

@thomasjm

Description

@thomasjm

I would like to be able to forward a host port to a guest port, with the host port automatically determined by the OS to avoid race conditions. I tried to do this by passing "host_port": 0 in a command to the API socket.

However, this returns an error that says bad arguments.host_port.

I found that this case is specifically excluded here:

slirp4netns/api.c

Lines 135 to 142 in 9996a4e

fwd->host_port = (int)json_object_dotget_number(jo, "arguments.host_port");
if (fwd->host_port == 0) {
const char *err = "{\"error\":{\"desc\":\"bad request: add_hostfwd: "
"bad arguments.host_port\"}}";
wrc = write(fd, err, strlen(err));
g_free(fwd);
goto finish;
}

Why is this not possible? Is it some limitation of libslirp? (This maybe an awkward time to ask as libslirp seems to be migrating its Gitlab instance and is down at the moment, so I'm having trouble checking over there...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions