struct client *client = (struct client *)context;
const struct http_request *http_req = http_server_request_get(req);
struct http_server_response *http_resp;
- const char *ipport;
string_t *content;
if (strcmp(http_req->method, "GET") != 0) {
/* Compose response payload */
content = t_str_new(1024);
- (void)net_ipport2str(&client->server_ip, client->server_port, &ipport);
- str_printfa(content, "Server: %s\r\n", ipport);
- (void)net_ipport2str(&client->ip, client->port, &ipport);
- str_printfa(content, "Client: %s\r\n", ipport);
+ str_printfa(content, "Server: %s\r\n",
+ net_ipport2str(&client->server_ip, client->server_port));
+ str_printfa(content, "Client: %s\r\n",
+ net_ipport2str(&client->ip, client->port));
str_printfa(content, "Host: %s", http_req->target.url->host.name);
if (http_req->target.url->port != 0)
str_printfa(content, ":%u", http_req->target.url->port);
req->req, "X-Dovecot-Auth-Service", input->service);
}
if (input->local_ip.family != 0) {
- const char *addr;
- if (net_ipport2str(&input->local_ip, input->local_port,
- &addr) == 0) {
- http_client_request_add_header(
- req->req, "X-Dovecot-Auth-Local", addr);
- }
+ http_client_request_add_header(
+ req->req, "X-Dovecot-Auth-Local",
+ net_ipport2str(&input->local_ip,
+ input->local_port));
}
if (input->remote_ip.family != 0) {
- const char *addr;
- if (net_ipport2str(&input->remote_ip, input->remote_port,
- &addr) == 0) {
- http_client_request_add_header(
- req->req, "X-Dovecot-Auth-Remote", addr);
- }
+ http_client_request_add_header(
+ req->req, "X-Dovecot-Auth-Remote",
+ net_ipport2str(&input->remote_ip,
+ input->remote_port));
}
}
i_assert(prclient->ips_count > 0);
- if (net_ipport2str(prclient->ips, prclient->port, &address) < 0)
- i_unreached();
+ address = net_ipport2str(prclient->ips, prclient->port);
label = t_strconcat("tcp:", address, NULL);
program_client_set_label(pclient, label);
i_assert(ips != NULL && ips_count > 0);
- if (net_ipport2str(ips, port, &label) < 0)
- i_unreached();
- label = t_strconcat("tcp:", label, NULL);
+ label = t_strconcat("tcp:", net_ipport2str(ips, port), NULL);
pool = pool_alloconly_create("program client net", 1024);
prclient = p_new(pool, struct program_client_remote, 1);
return 0;
}
-int net_ipport2str(const struct ip_addr *ip, in_port_t port, const char **str_r)
+const char *net_ipport2str(const struct ip_addr *ip, in_port_t port)
{
- if (!IPADDR_IS_V4(ip) && !IPADDR_IS_V6(ip)) return -1;
+ i_assert(IPADDR_IS_V4(ip) || IPADDR_IS_V6(ip));
- *str_r = t_strdup_printf("%s%s%s:%u",
- IPADDR_IS_V6(ip) ? "[" : "",
- net_ip2addr(ip),
- IPADDR_IS_V6(ip) ? "]" : "",
- port);
- return 0;
+ return t_strdup_printf("%s%s%s:%u",
+ (IPADDR_IS_V6(ip) ? "[" : ""), net_ip2addr(ip),
+ (IPADDR_IS_V6(ip) ? "]" : ""), port);
}
int net_ipv6_mapped_ipv4_convert(const struct ip_addr *src,
through. */
int net_str2hostport(const char *str, in_port_t default_port,
const char **host_r, in_port_t *port_r);
-/* Converts ip and port to ipv4:port or [ipv6]:port. Returns -1 if
- ip is not valid IPv4 or IPv6 address. */
-int net_ipport2str(const struct ip_addr *ip, in_port_t port, const char **str_r);
+/* Converts ip and port to ipv4:port or [ipv6]:port. Triggers an assert crash
+ when IP is not valid. */
+const char *net_ipport2str(const struct ip_addr *ip, in_port_t port);
/* Convert IPv6 mapped IPv4 address to an actual IPv4 address. Returns 0 if
successful, -1 if the source address isn't IPv6 mapped IPv4 address. */
ctx->to = timeout_add(ctx->to_msecs,
stats_carbon_timeout,
ctx);
- if (net_ipport2str(&ip, port, &host) < 0)
- i_unreached();
- ctx->endpoint = p_strdup(ctx->pool, host);
+ ctx->endpoint = p_strdup(ctx->pool, net_ipport2str(&ip, port));
ctx->callback = callback;
ctx->ctx = cb_ctx;