Reduce code duplication in bind_port_helper()