struct ip_addr *ips;
in_port_t port;
unsigned int i, ips_count;
- const char *p;
-
- p = strrchr(host, ':');
- if (p != NULL) {
- if (net_str2port(p + 1, &port) < 0)
- i_fatal("Invalid director port in %s", host);
- host = t_strdup_until(host, p);
- } else {
- port = dir->self_port;
- }
+
+ if (net_str2hostport(host, dir->self_port, &host, &port) < 0)
+ i_fatal("Invalid director host:port in '%s'", host);
if (net_gethostbyname(host, &ips, &ips_count) < 0)
i_fatal("Unknown director host: %s", host);
return NULL;
}
-static bool
-parse_hostport(const char *str, in_port_t default_port,
- const char **host_r, in_port_t *port_r)
-{
- const char *p;
-
- /* host:port */
- p = strrchr(str, ':');
- if (p == NULL && default_port != 0) {
- *host_r = str;
- *port_r = default_port;
- } else {
- if (p == NULL || net_str2port(p+1, port_r) < 0)
- return FALSE;
- *host_r = t_strdup_until(str, p);
- }
- return TRUE;
-}
-
static int
doveadm_tcp_connect_port(const char *host, in_port_t port)
{
const char *host;
in_port_t port;
- if (!parse_hostport(target, default_port, &host, &port)) {
+ if (net_str2hostport(target, default_port, &host, &port) < 0) {
i_fatal("Port not known for %s. Either set proxy_port "
"or use %s:port", target, target);
}
struct ioloop *ioloop;
struct istream *input;
const char *host, *p, *const *destp;
- in_port_t port = DEFAULT_SUBMISSION_PORT;
-
- host = smtp_client->set->submission_host;
- p = strchr(host, ':');
- if (p != NULL) {
- host = t_strdup_until(host, p);
- if (net_str2port(p + 1, &port) < 0) {
- *error_r = t_strdup_printf(
- "Invalid port in submission_host: %s", p+1);
- return -1;
- }
+ in_port_t port;
+
+ if (net_str2hostport(smtp_client->set->submission_host,
+ DEFAULT_SUBMISSION_PORT, &host, &port) < 0) {
+ *error_r = t_strdup_printf(
+ "Invalid submission_host: %s", host);
+ return -1;
}
if (o_stream_nfinish(smtp_client->output) < 0) {
iostream_rawlog_try_create_tcp(const char *path,
struct istream **input, struct ostream **output)
{
- const char *p, *host;
+ const char *host;
struct ip_addr *ips;
unsigned int ips_count;
in_port_t port;
if (strchr(path, '/') != NULL)
return 0;
- if ((p = strchr(path, ':')) == NULL)
+ if (net_str2hostport(path, 0, &host, &port) < 0 || port == 0)
return 0;
- if (net_str2port(p+1, &port) < 0)
- return 0;
- host = t_strdup_until(path, p);
ret = net_gethostbyname(host, &ips, &ips_count);
if (ret != 0) {