X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fsocket-util.c;h=e400bb543abc1cdbf34919aa84e9d111083c0849;hb=6d65eee8b1f4d96b9c925d3b31758268345a4636;hp=3fcd5a1e8e79f73210c0d2ec70feeb33b370a1dd;hpb=e8b52a913a8fc3d2ef0dae82eda5905668ebfae1;p=openvswitch diff --git a/lib/socket-util.c b/lib/socket-util.c index 3fcd5a1e..e400bb54 100644 --- a/lib/socket-util.c +++ b/lib/socket-util.c @@ -292,8 +292,9 @@ guess_netmask(uint32_t ip) } /* Opens a non-blocking TCP socket and connects to 'target', which should be a - * string in the format "[:]", where is required and - * is optional, with 'default_port' assumed if is omitted. + * string in the format "[:]". is required. If + * 'default_port' is nonzero then is optional and defaults to + * 'default_port'. * * On success, returns 0 (indicating connection complete) or EAGAIN (indicating * connection in progress), in which case the new file descriptor is stored @@ -335,6 +336,10 @@ tcp_open_active(const char *target_, uint16_t default_port, } if (port_string && atoi(port_string)) { sin.sin_port = htons(atoi(port_string)); + } else if (!default_port) { + VLOG_ERR("%s: port number must be specified", target_); + error = EAFNOSUPPORT; + goto exit; } /* Create non-blocking socket. */ @@ -376,10 +381,10 @@ exit: } /* Opens a non-blocking TCP socket, binds to 'target', and listens for incoming - * connections. 'target' should be a string in the format "[][:]", - * where both and are optional. If is omitted, it defaults - * to 'default_port'; if is omitted it defaults to the wildcard IP - * address. + * connections. 'target' should be a string in the format "[][:]". + * may be omitted if 'default_port' is nonzero, in which case it + * defaults to 'default_port'. If is omitted it defaults to the wildcard + * IP address. * * The socket will have SO_REUSEADDR turned on. * @@ -406,6 +411,10 @@ tcp_open_passive(const char *target_, uint16_t default_port) port_string = strsep(&string_ptr, ":"); if (port_string && atoi(port_string)) { sin.sin_port = htons(atoi(port_string)); + } else if (!default_port) { + VLOG_ERR("%s: port number must be specified", target_); + error = EAFNOSUPPORT; + goto exit; } /* Parse optional bind IP. */