return error;
}
-\f
+
+/*
+ * This function extracts IP address and port from the target string.
+ *
+ * - On success, function returns true and fills *sin structure with port
+ * and IP address. If port was absent in target string then it will use
+ * corresponding default port value.
+ * - On error, function returns false and *sin contains garbage.
+ */
+bool
+stream_parse_target_with_default_ports(const char *target,
+ uint16_t default_tcp_port,
+ uint16_t default_ssl_port,
+ struct sockaddr_in *sin)
+{
+ return (!strncmp(target, "tcp:", 4)
+ && inet_parse_active(target + 4, default_tcp_port, sin)) ||
+ (!strncmp(target, "ssl:", 4)
+ && inet_parse_active(target + 4, default_ssl_port, sin));
+}
+
/* Attempts to guess the content type of a stream whose first few bytes were
* the 'size' bytes of 'data'. */
static enum stream_content_type
#include <sys/types.h>
#include "openvswitch/types.h"
#include "vlog.h"
+#include "socket-util.h"
struct pstream;
struct stream;
uint16_t default_ptcp_port,
uint16_t default_pssl_port,
struct pstream **);
-\f
+bool stream_parse_target_with_default_ports(const char *target,
+ uint16_t default_tcp_port,
+ uint16_t default_ssl_port,
+ struct sockaddr_in *sin);
+
/* Error reporting. */
enum stream_content_type {
/* Add all the remotes. */
HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) {
struct sockaddr_in *sin = &addrs[n_addrs];
+ const char *target = rconn_get_target(ofconn->rconn);
if (ofconn->band == OFPROTO_OUT_OF_BAND) {
continue;
}
- sin->sin_addr.s_addr = rconn_get_remote_ip(ofconn->rconn);
- if (sin->sin_addr.s_addr) {
- sin->sin_port = rconn_get_remote_port(ofconn->rconn);
+ if (stream_parse_target_with_default_ports(target,
+ OFP_TCP_PORT,
+ OFP_SSL_PORT,
+ sin)) {
n_addrs++;
}
}
SSET_FOR_EACH (target, &targets) {
struct sockaddr_in *sin = &managers[n_managers];
- if ((!strncmp(target, "tcp:", 4)
- && inet_parse_active(target + 4, JSONRPC_TCP_PORT, sin)) ||
- (!strncmp(target, "ssl:", 4)
- && inet_parse_active(target + 4, JSONRPC_SSL_PORT, sin))) {
+ if (stream_parse_target_with_default_ports(target,
+ JSONRPC_TCP_PORT,
+ JSONRPC_SSL_PORT,
+ sin)) {
n_managers++;
}
}