Merged pull request #670 from heinrich5991/fix_netaddrstrmissingport.

made net_addr_str give a string without port if it is = 0
This commit is contained in:
minus7 2011-04-28 14:54:25 -07:00
commit b60dc13fbb

View file

@ -571,13 +571,23 @@ int net_addr_comp(const NETADDR *a, const NETADDR *b)
void net_addr_str(const NETADDR *addr, char *string, int max_length)
{
if(addr->type == NETTYPE_IPV4)
{
if(addr->port != 0)
str_format(string, max_length, "%d.%d.%d.%d:%d", addr->ip[0], addr->ip[1], addr->ip[2], addr->ip[3], addr->port);
else
str_format(string, max_length, "%d.%d.%d.%d", addr->ip[0], addr->ip[1], addr->ip[2], addr->ip[3]);
}
else if(addr->type == NETTYPE_IPV6)
{
if(addr->port != 0)
str_format(string, max_length, "[%x:%x:%x:%x:%x:%x:%x:%x]:%d",
(addr->ip[0]<<8)|addr->ip[1], (addr->ip[2]<<8)|addr->ip[3], (addr->ip[4]<<8)|addr->ip[5], (addr->ip[6]<<8)|addr->ip[7],
(addr->ip[8]<<8)|addr->ip[9], (addr->ip[10]<<8)|addr->ip[11], (addr->ip[12]<<8)|addr->ip[13], (addr->ip[14]<<8)|addr->ip[15],
addr->port);
else
str_format(string, max_length, "[%x:%x:%x:%x:%x:%x:%x:%x]",
(addr->ip[0]<<8)|addr->ip[1], (addr->ip[2]<<8)|addr->ip[3], (addr->ip[4]<<8)|addr->ip[5], (addr->ip[6]<<8)|addr->ip[7],
(addr->ip[8]<<8)|addr->ip[9], (addr->ip[10]<<8)|addr->ip[11], (addr->ip[12]<<8)|addr->ip[13], (addr->ip[14]<<8)|addr->ip[15]);
}
else
str_format(string, max_length, "unknown type %d", addr->type);