Adds IPv6 addrs to win32 get_interfaces response

unstable
James Lee 2012-03-05 21:57:39 -07:00
parent 78d84d9472
commit 085b3b5640
1 changed files with 41 additions and 16 deletions

View File

@ -1,4 +1,5 @@
#include "precomp.h" #include "precomp.h"
#include <ws2ipdef.h>
/* /*
* Returns zero or more local interfaces to the requestor * Returns zero or more local interfaces to the requestor
@ -18,47 +19,70 @@ DWORD request_net_config_get_interfaces(Remote *remote, Packet *packet)
DWORD interface_index_bigendian; DWORD interface_index_bigendian;
MIB_IFROW iface; MIB_IFROW iface;
ULONG flags = GAA_FLAG_INCLUDE_PREFIX | GAA_FLAG_SKIP_DNS_SERVER;
LPSOCKADDR sockaddr;
ULONG family = AF_UNSPEC;
IP_ADAPTER_ADDRESSES *pAdapters = NULL;
IP_ADAPTER_ADDRESSES *pCurr = NULL;
ULONG outBufLen = 0;
IP_ADAPTER_UNICAST_ADDRESS_LH *pAddr;
LPSOCKADDR foo;
// Call once with a length of 0 to get how much we need to allocate
GetAdaptersAddresses(family, flags, NULL, pAdapters, &outBufLen);
do do
{ {
// Allocate memory for reading addresses into // Allocate memory for reading addresses into
if (!(table = (PMIB_IPADDRTABLE)malloc(tableSize))) if (!(pAdapters = (IP_ADAPTER_ADDRESSES *)malloc(outBufLen)))
{ {
result = ERROR_NOT_ENOUGH_MEMORY; result = ERROR_NOT_ENOUGH_MEMORY;
break; break;
} }
// Get the IP address table // Get the IP address table
if (GetIpAddrTable(table, &tableSize, TRUE) != NO_ERROR) if (GetAdaptersAddresses(family, flags, NULL, pAdapters, &outBufLen))
{ {
result = GetLastError(); result = GetLastError();
break; break;
} }
// Enumerate the entries // Enumerate the entries
for (index = 0; for (pCurr = pAdapters; pCurr; pCurr = pCurr->Next)
index < table->dwNumEntries;
index++)
{ {
entryCount = 0; entryCount = 0;
interface_index_bigendian = htonl(table->table[index].dwIndex); interface_index_bigendian = htonl(pCurr->IfIndex);
entries[entryCount].header.length = sizeof(DWORD); entries[entryCount].header.length = sizeof(DWORD);
entries[entryCount].header.type = TLV_TYPE_INTERFACE_INDEX; entries[entryCount].header.type = TLV_TYPE_INTERFACE_INDEX;
entries[entryCount].buffer = (PUCHAR)&interface_index_bigendian; entries[entryCount].buffer = (PUCHAR)&interface_index_bigendian;
entryCount++; entryCount++;
entries[entryCount].header.length = sizeof(DWORD); for (pAddr = (void*)pCurr->FirstUnicastAddress; pAddr; pAddr = (void*)pAddr->Next)
entries[entryCount].header.type = TLV_TYPE_IP; {
entries[entryCount].buffer = (PUCHAR)&table->table[index].dwAddr; foo = pAddr->Address.lpSockaddr;
entryCount++; if (foo->sa_family == AF_INET) {
entries[entryCount].header.length = 4;
entries[entryCount].header.type = TLV_TYPE_IP;
entries[entryCount].buffer = (PUCHAR)&(((struct sockaddr_in *)foo)->sin_addr);
} else {
entries[entryCount].header.length = 16;
entries[entryCount].header.type = TLV_TYPE_IP;
entries[entryCount].buffer = (PUCHAR)&(((struct sockaddr_in6 *)foo)->sin6_addr);
}
entryCount++;
entries[entryCount].header.length = sizeof(DWORD); #if 0
entries[entryCount].header.type = TLV_TYPE_NETMASK; entries[entryCount].header.length = sizeof(DWORD);
entries[entryCount].buffer = (PUCHAR)&table->table[index].dwMask; entries[entryCount].header.type = TLV_TYPE_NETMASK;
entryCount++; entries[entryCount].buffer = (PUCHAR)&;
entryCount++;
iface.dwIndex = table->table[index].dwIndex; #endif
}
#if 0
// If interface information can get gotten, use it. // If interface information can get gotten, use it.
if (GetIfEntry(&iface) == NO_ERROR) if (GetIfEntry(&iface) == NO_ERROR)
{ {
@ -81,6 +105,7 @@ DWORD request_net_config_get_interfaces(Remote *remote, Packet *packet)
entryCount++; entryCount++;
} }
} }
#endif
// Add the interface group // Add the interface group
packet_add_tlv_group(response, TLV_TYPE_NETWORK_INTERFACE, packet_add_tlv_group(response, TLV_TYPE_NETWORK_INTERFACE,