summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
9ab3d9a)
Until now, tcp_open_active() and tcp_open_passive() have only been used
in situations where there is a reasonable default port, e.g. OFP_TCP_PORT.
But for NetFlow there is no universal default, so enhance these functions
so that they can require the user to specify a port explicitly.
Crossported from the 'db' branch, where this is useful for JSON-RPC, which
also has no widely known port.
}
/* Opens a non-blocking TCP socket and connects to 'target', which should be a
}
/* Opens a non-blocking TCP socket and connects to 'target', which should be a
- * string in the format "<host>[:<port>]", where <host> is required and <port>
- * is optional, with 'default_port' assumed if <port> is omitted.
+ * string in the format "<host>[:<port>]". <host> is required. If
+ * 'default_port' is nonzero then <port> 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
*
* On success, returns 0 (indicating connection complete) or EAGAIN (indicating
* connection in progress), in which case the new file descriptor is stored
}
if (port_string && atoi(port_string)) {
sin.sin_port = htons(atoi(port_string));
}
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. */
}
/* Create non-blocking socket. */
}
/* Opens a non-blocking TCP socket, binds to 'target', and listens for incoming
}
/* Opens a non-blocking TCP socket, binds to 'target', and listens for incoming
- * connections. 'target' should be a string in the format "[<port>][:<ip>]",
- * where both <port> and <ip> are optional. If <port> is omitted, it defaults
- * to 'default_port'; if <ip> is omitted it defaults to the wildcard IP
- * address.
+ * connections. 'target' should be a string in the format "[<port>][:<ip>]".
+ * <port> may be omitted if 'default_port' is nonzero, in which case it
+ * defaults to 'default_port'. If <ip> is omitted it defaults to the wildcard
+ * IP address.
*
* The socket will have SO_REUSEADDR turned on.
*
*
* The socket will have SO_REUSEADDR turned on.
*
port_string = strsep(&string_ptr, ":");
if (port_string && atoi(port_string)) {
sin.sin_port = htons(atoi(port_string));
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. */
}
/* Parse optional bind IP. */