comparison src/lib/net.c @ 21097:3f83d38ba0b3

lib: Add net_ipport2str Converts struct ip_addr + port into either 127.0.0.1:6000 or [::1]:6000.
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Wed, 09 Nov 2016 15:17:01 +0200
parents 13a159cfd232
children 5ab8dc1a4a6f
comparison
equal deleted inserted replaced
21096:95f568387300 21097:3f83d38ba0b3
1044 *host_r = host; 1044 *host_r = host;
1045 *port_r = port; 1045 *port_r = port;
1046 return 0; 1046 return 0;
1047 } 1047 }
1048 1048
1049 int net_ipport2str(const struct ip_addr *ip, in_port_t port, const char **str_r)
1050 {
1051 if (!IPADDR_IS_V4(ip) && !IPADDR_IS_V6(ip)) return -1;
1052
1053 *str_r = t_strdup_printf("%s%s%s:%u",
1054 IPADDR_IS_V6(ip) ? "[" : "",
1055 net_ip2addr(ip),
1056 IPADDR_IS_V6(ip) ? "]" : "",
1057 port);
1058 return 0;
1059 }
1060
1049 int net_ipv6_mapped_ipv4_convert(const struct ip_addr *src, 1061 int net_ipv6_mapped_ipv4_convert(const struct ip_addr *src,
1050 struct ip_addr *dest) 1062 struct ip_addr *dest)
1051 { 1063 {
1052 #ifdef HAVE_IPV6 1064 #ifdef HAVE_IPV6
1053 static uint8_t v4_prefix[] = 1065 static uint8_t v4_prefix[] =