Commit 433990d6 authored by Alex Henrie's avatar Alex Henrie Committed by Alexandre Julliard

iphlpapi/tests: Build rotating buffers into ntoa and ntoa6.

parent 71affb28
...@@ -169,28 +169,25 @@ static void freeIPHlpApi(void) ...@@ -169,28 +169,25 @@ static void freeIPHlpApi(void)
/* replacement for inet_ntoa */ /* replacement for inet_ntoa */
static const char *ntoa( DWORD ip ) static const char *ntoa( DWORD ip )
{ {
static char buffer[40]; static char buffers[4][16];
static int i = -1;
ip = htonl(ip); ip = htonl(ip);
sprintf( buffer, "%u.%u.%u.%u", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff ); i = (i + 1) % ARRAY_SIZE(buffers);
return buffer; sprintf( buffers[i], "%u.%u.%u.%u", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, ip & 0xff );
return buffers[i];
} }
static const char *ntoa6( IN6_ADDR *ip ) static const char *ntoa6( IN6_ADDR *ip )
{ {
static char buffer[40]; static char buffers[4][40];
char *buf = buffer; static int i = -1;
unsigned short *p = ip->u.Word; unsigned short *p = ip->u.Word;
unsigned int i = 0;
while (i < 8) i = (i + 1) % ARRAY_SIZE(buffers);
{ sprintf( buffers[i], "%x:%x:%x:%x:%x:%x:%x:%x",
if (i > 0) htons(p[0]), htons(p[1]), htons(p[2]), htons(p[3]), htons(p[4]), htons(p[5]), htons(p[6]), htons(p[7]) );
*buf++ = ':'; return buffers[i];
buf += sprintf( buf, "%x", htons(p[i]) );
i++;
}
return buffer;
} }
/* /*
...@@ -382,8 +379,6 @@ static void testGetIpForwardTable(void) ...@@ -382,8 +379,6 @@ static void testGetIpForwardTable(void)
trace( "IP forward table: %u entries\n", buf->dwNumEntries ); trace( "IP forward table: %u entries\n", buf->dwNumEntries );
for (i = 0; i < buf->dwNumEntries; i++) for (i = 0; i < buf->dwNumEntries; i++)
{ {
char buffer[100];
if (!U1(buf->table[i]).dwForwardDest) /* Default route */ if (!U1(buf->table[i]).dwForwardDest) /* Default route */
{ {
todo_wine todo_wine
...@@ -403,9 +398,8 @@ todo_wine ...@@ -403,9 +398,8 @@ todo_wine
* value so it is not worth testing in this case. */ * value so it is not worth testing in this case. */
} }
sprintf( buffer, "dest %s", ntoa( buf->table[i].dwForwardDest )); trace( "%u: dest %s mask %s gw %s if %u type %u proto %u\n", i,
sprintf( buffer + strlen(buffer), " mask %s", ntoa( buf->table[i].dwForwardMask )); ntoa( buf->table[i].dwForwardDest ), ntoa( buf->table[i].dwForwardMask ),
trace( "%u: %s gw %s if %u type %u proto %u\n", i, buffer,
ntoa( buf->table[i].dwForwardNextHop ), buf->table[i].dwForwardIfIndex, ntoa( buf->table[i].dwForwardNextHop ), buf->table[i].dwForwardIfIndex,
U1(buf->table[i]).dwForwardType, U1(buf->table[i]).dwForwardProto ); U1(buf->table[i]).dwForwardType, U1(buf->table[i]).dwForwardProto );
} }
...@@ -890,12 +884,10 @@ static void testGetTcpTable(void) ...@@ -890,12 +884,10 @@ static void testGetTcpTable(void)
trace( "TCP table: %u entries\n", buf->dwNumEntries ); trace( "TCP table: %u entries\n", buf->dwNumEntries );
for (i = 0; i < buf->dwNumEntries; i++) for (i = 0; i < buf->dwNumEntries; i++)
{ {
char buffer[40]; trace( "%u: local %s:%u remote %s:%u state %u\n", i,
sprintf( buffer, "local %s:%u", ntoa(buf->table[i].dwLocalAddr), ntohs(buf->table[i].dwLocalPort),
ntoa(buf->table[i].dwLocalAddr), ntohs(buf->table[i].dwLocalPort) ); ntoa(buf->table[i].dwRemoteAddr), ntohs(buf->table[i].dwRemotePort),
trace( "%u: %s remote %s:%u state %u\n", U(buf->table[i]).dwState );
i, buffer, ntoa( buf->table[i].dwRemoteAddr ),
ntohs(buf->table[i].dwRemotePort), U(buf->table[i]).dwState );
} }
} }
HeapFree(GetProcessHeap(), 0, buf); HeapFree(GetProcessHeap(), 0, buf);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment