Skip to content

Problem: Unable to bind UDP to wildcard port #3034

Open
@StevePER

Description

@StevePER

Issue description

With TCP it's possible to bind to any available port by specifying a port of 0 or *. I would like the ability to do the same with UDP.

It seems trivial to add this capability to udp_address_t::resolve using the same logic as tcp_address_t::resolve, as follows:

//  Allow 0 specifically, to detect invalid port error in atoi if not
uint16_t port;
if (port_str == "*" || port_str == "0")
    //  Resolve wildcard to 0 to allow autoselection of port
    port = 0;
else {
    //  Parse the port number (0 is not a valid port).
    port = (uint16_t) atoi (port_str.c_str ());
    if (port == 0) {
        errno = EINVAL;
        return -1;
    }
}

But I can't see a clean way to implement getting the bound port back out again. (Caveat: I am new to zmq). For TCP, the last_address is set in socket_base_t::bind, but as far as I can see the UDP socket isn't bound to a port at this point.

Environment

  • libzmq version (commit hash if unreleased): 4.2.3
  • OS: Red Hat Linux 7.4

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions