Commit 7df2d4b2 authored by Andrew Nguyen's avatar Andrew Nguyen Committed by Alexandre Julliard

ipconfig: Move socket address string generation to a helper function.

parent fea9d8f1
...@@ -130,6 +130,13 @@ static void print_field(int msg, const WCHAR *value) ...@@ -130,6 +130,13 @@ static void print_field(int msg, const WCHAR *value)
ipconfig_printfW(formatW, field, value); ipconfig_printfW(formatW, field, value);
} }
static BOOL socket_address_to_string(WCHAR *buf, DWORD len, SOCKET_ADDRESS *addr)
{
return WSAAddressToStringW(addr->lpSockaddr,
addr->iSockaddrLength, NULL,
buf, &len) == 0;
}
static void print_basic_information(void) static void print_basic_information(void)
{ {
IP_ADAPTER_ADDRESSES *adapters; IP_ADAPTER_ADDRESSES *adapters;
...@@ -150,6 +157,7 @@ static void print_basic_information(void) ...@@ -150,6 +157,7 @@ static void print_basic_information(void)
static const WCHAR newlineW[] = {'\n',0}; static const WCHAR newlineW[] = {'\n',0};
IP_ADAPTER_UNICAST_ADDRESS *addr; IP_ADAPTER_UNICAST_ADDRESS *addr;
WCHAR addr_buf[54];
ipconfig_message_printfW(STRING_ADAPTER_FRIENDLY, iftype_to_string(p->IfType), p->FriendlyName); ipconfig_message_printfW(STRING_ADAPTER_FRIENDLY, iftype_to_string(p->IfType), p->FriendlyName);
ipconfig_printfW(newlineW); ipconfig_printfW(newlineW);
...@@ -157,12 +165,7 @@ static void print_basic_information(void) ...@@ -157,12 +165,7 @@ static void print_basic_information(void)
for (addr = p->FirstUnicastAddress; addr; addr = addr->Next) for (addr = p->FirstUnicastAddress; addr; addr = addr->Next)
{ {
WCHAR addr_buf[54]; if (socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &addr->Address))
DWORD len = sizeof(addr_buf)/sizeof(WCHAR);
if (WSAAddressToStringW(addr->Address.lpSockaddr,
addr->Address.iSockaddrLength, NULL,
addr_buf, &len) == 0)
print_field(STRING_IP_ADDRESS, addr_buf); print_field(STRING_IP_ADDRESS, addr_buf);
/* FIXME: Output corresponding subnet mask. */ /* FIXME: Output corresponding subnet mask. */
} }
...@@ -287,6 +290,7 @@ static void print_full_information(void) ...@@ -287,6 +290,7 @@ static void print_full_information(void)
{ {
IP_ADAPTER_UNICAST_ADDRESS *addr; IP_ADAPTER_UNICAST_ADDRESS *addr;
WCHAR physaddr_buf[3 * MAX_ADAPTER_ADDRESS_LENGTH]; WCHAR physaddr_buf[3 * MAX_ADAPTER_ADDRESS_LENGTH];
WCHAR addr_buf[54];
ipconfig_message_printfW(STRING_ADAPTER_FRIENDLY, iftype_to_string(p->IfType), p->FriendlyName); ipconfig_message_printfW(STRING_ADAPTER_FRIENDLY, iftype_to_string(p->IfType), p->FriendlyName);
ipconfig_printfW(newlineW); ipconfig_printfW(newlineW);
...@@ -299,12 +303,7 @@ static void print_full_information(void) ...@@ -299,12 +303,7 @@ static void print_full_information(void)
for (addr = p->FirstUnicastAddress; addr; addr = addr->Next) for (addr = p->FirstUnicastAddress; addr; addr = addr->Next)
{ {
WCHAR addr_buf[54]; if (socket_address_to_string(addr_buf, sizeof(addr_buf)/sizeof(WCHAR), &addr->Address))
DWORD len = sizeof(addr_buf)/sizeof(WCHAR);
if (WSAAddressToStringW(addr->Address.lpSockaddr,
addr->Address.iSockaddrLength, NULL,
addr_buf, &len) == 0)
print_field(STRING_IP_ADDRESS, addr_buf); print_field(STRING_IP_ADDRESS, addr_buf);
/* FIXME: Output corresponding subnet mask. */ /* FIXME: Output corresponding subnet mask. */
} }
......
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