Author: janderwald
Date: Tue Oct 28 05:06:16 2008
New Revision: 37037
URL:
http://svn.reactos.org/svn/reactos?rev=37037&view=rev
Log:
- Rewrite getResInfo to directly return a linked list of IP_ADDR_STRING structures
- Might fix manual DNS bug
Modified:
trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c
trunk/reactos/dll/win32/iphlpapi/resinfo.h
trunk/reactos/dll/win32/iphlpapi/resinfo_reactos.c
Modified: trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/iphlpap…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/iphlpapi_main.c [iso-8859-1] Tue Oct 28 05:06:16
2008
@@ -1367,7 +1367,7 @@
if (!resInfo)
return ERROR_OUTOFMEMORY;
- size = sizeof(FIXED_INFO) + (resInfo->riCount > 0 ? (resInfo->riCount - 1) *
+ size = sizeof(FIXED_INFO) + (resInfo->riCount > 1 ? (resInfo->riCount-1) *
sizeof(IP_ADDR_STRING) : 0);
if (!pFixedInfo || *pOutBufLen < size) {
*pOutBufLen = size;
@@ -1383,25 +1383,16 @@
TRACE("GetComputerNameExA: %s\n", pFixedInfo->DomainName);
- if (resInfo->riCount > 0) {
- PIP_ADDR_STRING ptr;
- int i;
-
- for (i = 0, ptr = &pFixedInfo->DnsServerList; i < resInfo->riCount
&& ptr;
- i++, ptr = ptr->Next) {
- struct sockaddr_in *addr_v4 =
- (struct sockaddr_in *)&resInfo->riAddressList[i];
- toIPAddressString
- (addr_v4->sin_addr.s_addr,
- ptr->IpAddress.String);
- if (i == resInfo->riCount - 1)
- ptr->Next = NULL;
- else if (i == 0)
- ptr->Next = (PIP_ADDR_STRING)((LPBYTE)pFixedInfo + sizeof(FIXED_INFO));
- else
- ptr->Next = (PIP_ADDR_STRING)((PBYTE)ptr + sizeof(IP_ADDR_STRING));
- }
- }
+ if (resInfo->riCount > 0)
+ {
+ CopyMemory(&pFixedInfo->DnsServerList, resInfo->DnsList,
sizeof(IP_ADDR_STRING));
+ if (resInfo->riCount > 1)
+ {
+ pFixedInfo->DnsServerList.Next = (struct _IP_ADDR_STRING*)((char*)pFixedInfo +
sizeof(FIXED_INFO));
+ CopyMemory(pFixedInfo->DnsServerList.Next, resInfo->DnsList->Next,
sizeof(IP_ADDR_STRING) * (resInfo->riCount-1));
+ }
+ }
+
pFixedInfo->NodeType = HYBRID_NODETYPE;
regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey);
@@ -1490,7 +1481,7 @@
Context->uSizeRequired += sizeof(IP_ADDR_STRING);
if (Context->uSizeAvailable >= Context->uSizeRequired)
{
- pNext = ((char*)Context->pLastAddr) + sizeof(IP_ADDR_STRING);
+ pNext = (IP_ADDR_STRING*)(((char*)Context->pLastAddr) +
sizeof(IP_ADDR_STRING));
WideCharToMultiByte(CP_ACP, 0, Server, -1, pNext->IpAddress.String, 16, NULL,
NULL);
pNext->IpAddress.String[15] = '\0';
Context->pLastAddr->Next = pNext;
Modified: trunk/reactos/dll/win32/iphlpapi/resinfo.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/resinfo…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/resinfo.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/resinfo.h [iso-8859-1] Tue Oct 28 05:06:16 2008
@@ -23,6 +23,7 @@
typedef struct _IPHLP_RES_INFO {
DWORD riCount;
+ IP_ADDR_STRING * DnsList;
struct sockaddr_in *riAddressList;
} IPHLP_RES_INFO, *PIPHLP_RES_INFO;
Modified: trunk/reactos/dll/win32/iphlpapi/resinfo_reactos.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/iphlpapi/resinfo…
==============================================================================
--- trunk/reactos/dll/win32/iphlpapi/resinfo_reactos.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/iphlpapi/resinfo_reactos.c [iso-8859-1] Tue Oct 28 05:06:16
2008
@@ -49,8 +49,7 @@
typedef struct _NAME_SERVER_LIST_PRIVATE {
UINT NumServers;
- UINT CurrentName;
- PIP_ADDRESS_STRING AddrString;
+ IP_ADDR_STRING * pCurrent;
} NAME_SERVER_LIST_PRIVATE, *PNAME_SERVER_LIST_PRIVATE;
NTSYSAPI
@@ -177,22 +176,23 @@
CreateNameServerListEnumNamesFuncCount);
}
-VOID CreateNameServerListEnumNamesFunc( PWCHAR Interface,
- PWCHAR Server,
- PVOID _Data ) {
- PNAME_SERVER_LIST_PRIVATE Data = (PNAME_SERVER_LIST_PRIVATE)_Data;
-
- if (WideCharToMultiByte(CP_ACP, 0, Server, -1,
- Data->AddrString[Data->CurrentName].String,
- 16, NULL, NULL))
- {
- Data->AddrString[Data->CurrentName].String[15] = '\0';
- Data->CurrentName++;
- }
- else
- {
- Data->AddrString[Data->CurrentName].String[0] = '\0';
- }
+VOID CreateNameServerListEnumNamesFunc(
+ PWCHAR Interface,
+ PWCHAR Server,
+ PVOID _Data )
+{
+ PNAME_SERVER_LIST_PRIVATE Data = (PNAME_SERVER_LIST_PRIVATE)_Data;
+
+ if (WideCharToMultiByte(CP_ACP, 0, Server, -1,
Data->pCurrent->IpAddress.String, 16, NULL, NULL))
+ {
+ Data->pCurrent->Next = (struct _IP_ADDR_STRING*)(char*)Data->pCurrent +
sizeof(IP_ADDR_STRING);
+ Data->pCurrent = Data->pCurrent->Next;
+ Data->NumServers++;
+ }
+ else
+ {
+ Data->pCurrent->IpAddress.String[0] = '\0';
+ }
}
static void CreateNameServerListEnumIfFunc( HKEY RegHandle,
@@ -213,51 +213,37 @@
}
PIPHLP_RES_INFO getResInfo() {
- DWORD i, ServerCount;
- NAME_SERVER_LIST_PRIVATE PrivateNSEnum = { 0 };
+ DWORD ServerCount;
+ NAME_SERVER_LIST_PRIVATE PrivateNSEnum;
PIPHLP_RES_INFO ResInfo;
- struct sockaddr_in *AddrList;
-
+ IP_ADDR_STRING * DnsList;
+
+ PrivateNSEnum.NumServers = 0;
ServerCount = CountNameServers( &PrivateNSEnum );
PrivateNSEnum.NumServers = ServerCount;
- PrivateNSEnum.AddrString =
- (PIP_ADDRESS_STRING)
- RtlAllocateHeap( GetProcessHeap(), 0,
- ServerCount * sizeof(IP_ADDRESS_STRING) );
- PrivateNSEnum.CurrentName = 0;
-
- ResInfo =
- (PIPHLP_RES_INFO)RtlAllocateHeap
- ( GetProcessHeap(), 0,
- sizeof(IPHLP_RES_INFO) +
- (ServerCount * sizeof(struct sockaddr_in)) );
-
- if( !ResInfo ) {
- RtlFreeHeap( GetProcessHeap(), 0, PrivateNSEnum.AddrString );
- return NULL;
- }
-
- ResInfo->riCount = ServerCount;
- AddrList = (struct sockaddr_in *)
- (((PCHAR)ResInfo) + sizeof(IPHLP_RES_INFO));
- ResInfo->riAddressList = AddrList;
+ DnsList = HeapAlloc(GetProcessHeap(), 0, ServerCount * sizeof(IP_ADDR_STRING));
+ ZeroMemory(DnsList, ServerCount * sizeof(IP_ADDR_STRING));
+
+ ResInfo = (PIPHLP_RES_INFO)RtlAllocateHeap ( GetProcessHeap(), 0,
sizeof(IPHLP_RES_INFO));
+ if( !ResInfo )
+ {
+ HeapFree( GetProcessHeap(), 0, DnsList );
+ return NULL;
+ }
+
+ PrivateNSEnum.NumServers = 0;
+ PrivateNSEnum.pCurrent = DnsList;
MakeNameServerList( &PrivateNSEnum );
-
- for( i = 0; i < PrivateNSEnum.CurrentName; i++ ) {
- /* Hmm seems that dns servers are always AF_INET but ... */
- ResInfo->riAddressList[i].sin_family = AF_INET;
- ResInfo->riAddressList[i].sin_addr.s_addr =
- inet_addr(PrivateNSEnum.AddrString[i].String );
- ResInfo->riAddressList[i].sin_port = 0;
- }
-
- RtlFreeHeap( GetProcessHeap(), 0, PrivateNSEnum.AddrString );
+ ResInfo->DnsList = DnsList;
+ ResInfo->riCount = PrivateNSEnum.NumServers;
return ResInfo;
}
-VOID disposeResInfo( PIPHLP_RES_INFO InfoPtr ) {
+VOID disposeResInfo( PIPHLP_RES_INFO InfoPtr )
+{
RtlFreeHeap( GetProcessHeap(), 0, InfoPtr );
-}
+ HeapFree(GetProcessHeap(), 0, InfoPtr->DnsList);
+}