netplay address printing:

* Don't cast if we can safely alter the format specifiers
 * Fix a spelling error: 'address famliy' -> 'address family'

git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@7897 4a71c877-e1ca-e34f-864e-861f7616d084
master
Giel van Schijndel 2009-07-26 12:34:26 +00:00 committed by Git SVN Gateway
parent ae8ec8652c
commit 7952b39be8
1 changed files with 15 additions and 15 deletions

View File

@ -359,29 +359,29 @@ static int addressToText(const struct sockaddr* addr, char* buf, size_t size)
unsigned char* address = (unsigned char*)&((const struct sockaddr_in*)addr)->sin_addr.s_addr;
return snprintf(buf, size,
"%i.%i.%i.%i",
(int)(address[0]),
(int)(address[1]),
(int)(address[2]),
(int)(address[3]));
"%hhu.%hhu.%hhu.%hhu",
address[0],
address[1],
address[2],
address[3]);
}
case AF_INET6:
{
uint16_t* address = (uint16_t*)&((const struct sockaddr_in6*)addr)->sin6_addr.s6_addr;
return snprintf(buf, size,
"%x:%x:%x:%x:%x:%x:%x:%x",
(int)ntohs(address[0]),
(int)ntohs(address[1]),
(int)ntohs(address[2]),
(int)ntohs(address[3]),
(int)ntohs(address[4]),
(int)ntohs(address[5]),
(int)ntohs(address[6]),
(int)ntohs(address[7]));
"%hx:%hx:%hx:%hx:%hx:%hx:%hx:%hx",
ntohs(address[0]),
ntohs(address[1]),
ntohs(address[2]),
ntohs(address[3]),
ntohs(address[4]),
ntohs(address[5]),
ntohs(address[6]),
ntohs(address[7]));
}
default:
ASSERT(!"Unknown address famliy", "Got non IPv4 or IPv6 address!");
ASSERT(!"Unknown address family", "Got non IPv4 or IPv6 address!");
return -1;
}
}