Author: phater
Date: Fri Jun 2 17:52:20 2017
New Revision: 74750
URL:
http://svn.reactos.org/svn/reactos?rev=74750&view=rev
Log:
[MSWSOCK] Call explicitly DnsQuery_W. Copy host aliases if available as answer from the
query
Modified:
trunk/reactos/dll/win32/mswsock/mswhelper.c
trunk/reactos/dll/win32/mswsock/mswhelper.h
trunk/reactos/dll/win32/mswsock/nsplookup.c
Modified: trunk/reactos/dll/win32/mswsock/mswhelper.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/mswsock/mswhelpe…
==============================================================================
--- trunk/reactos/dll/win32/mswsock/mswhelper.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/mswsock/mswhelper.c [iso-8859-1] Fri Jun 2 17:52:20 2017
@@ -423,7 +423,7 @@
return NULL;
}
- ret = MultiByteToWideChar(1252,
+ ret = MultiByteToWideChar(CP_ACP,
0,
aStr,
aStrByteLen,
@@ -464,7 +464,7 @@
return NULL;
}
- ret = WideCharToMultiByte(1252,
+ ret = WideCharToMultiByte(CP_ACP,
0,
wStr,
charLen,
@@ -553,7 +553,7 @@
if (aCount >= MAX_ARRAY_SIZE)
return NULL;
- bItmLen = (strlen(*aSrcPtr) + 1) * sizeof(char);
+ bItmLen = strlen(*aSrcPtr) + 1;
aStrByteLen[aCount] = bItmLen;
bLen += sizeof(*aSrcPtr) + bItmLen;
@@ -591,3 +591,93 @@
return resA;
}
+
+char**
+StrAryCpyHeapAllocWToA(_In_opt_ HANDLE hHeap,
+ _In_ WCHAR** wStrAry)
+{
+ WCHAR** wSrcPtr;
+ char** aDstPtr;
+ char* aDstNextStr;
+ DWORD aStrByteLen[MAX_ARRAY_SIZE];
+ int bLen;
+ int bItmLen;
+ int aCount;
+ int i1;
+ char** resA;
+ int ret;
+ char* aStr;
+
+ if (hHeap == 0)
+ hHeap = GetProcessHeap();
+
+ /* Calculating size of array ... */
+ wSrcPtr = wStrAry;
+ bLen = 0;
+ aCount = 0;
+
+ while (*wSrcPtr != NULL)
+ {
+ if (aCount >= MAX_ARRAY_SIZE)
+ return NULL;
+
+ bItmLen = wcslen(*wSrcPtr) + 1;
+ aStrByteLen[aCount] = bItmLen;
+
+ bLen += sizeof(*wSrcPtr) + bItmLen;
+
+ wSrcPtr++;
+ aCount++;
+ }
+
+ /* size for NULL-terminator */
+ bLen += sizeof(*wSrcPtr);
+
+ /* get memory */
+ resA = HeapAlloc(hHeap, 0, bLen);
+
+ /* copy data */
+ wSrcPtr = wStrAry;
+ aDstPtr = resA;
+
+ /* pos for the first string */
+ aDstNextStr = (char*)(resA + aCount + 1);
+ for (i1 = 0; i1 < aCount; i1++)
+ {
+ bItmLen = aStrByteLen[i1];
+
+ *aDstPtr = aDstNextStr;
+
+ aStr = HeapAlloc(hHeap, 0, bItmLen);
+ if (aStr == NULL)
+ {
+ HeapFree(hHeap, 0, aStr);
+ return NULL;
+ }
+
+ ret = WideCharToMultiByte(CP_ACP,
+ 0,
+ *wSrcPtr,
+ bItmLen,
+ aStr,
+ bItmLen,
+ NULL,
+ NULL);
+ if (ret != bItmLen)
+ {
+ HeapFree(hHeap, 0, aStr);
+ return NULL;
+ }
+ RtlCopyMemory(*aDstPtr, aStr, bItmLen);
+ HeapFree(hHeap, 0, aStr);
+
+ aDstNextStr = (char*)((DWORD)aDstNextStr + (DWORD)bItmLen);
+ aDstPtr++;
+ wSrcPtr++;
+ }
+
+ /* terminate with NULL */
+ *aDstPtr = NULL;
+
+ return resA;
+}
Modified: trunk/reactos/dll/win32/mswsock/mswhelper.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/mswsock/mswhelpe…
==============================================================================
--- trunk/reactos/dll/win32/mswsock/mswhelper.h [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/mswsock/mswhelper.h [iso-8859-1] Fri Jun 2 17:52:20 2017
@@ -117,4 +117,13 @@
_In_opt_ HANDLE hHeap,
_In_ char** aStrAry);
+/* strary:
+ ptr1 ... ptrn \0
+ data1 ... datan
+*/
+char**
+StrAryCpyHeapAllocWToA(
+ _In_opt_ HANDLE hHeap,
+ _In_ WCHAR** aStrAry);
+
#endif // _MSWHELPER_H
Modified: trunk/reactos/dll/win32/mswsock/nsplookup.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/mswsock/nsplooku…
==============================================================================
--- trunk/reactos/dll/win32/mswsock/nsplookup.c [iso-8859-1] (original)
+++ trunk/reactos/dll/win32/mswsock/nsplookup.c [iso-8859-1] Fri Jun 2 17:52:20 2017
@@ -469,12 +469,14 @@
_Out_ PWSHOSTINFOINTERN hostinfo)
{
HANDLE hHeap = GetProcessHeap();
- DNS_STATUS dns_status = {0};
+ DNS_STATUS dns_status = { 0 };
/* include/WinDNS.h -- look up DNS_RECORD on MSDN */
- PDNS_RECORD dp;
- PDNS_RECORD curr;
+ PDNS_RECORDW dp;
+ PDNS_RECORDW curr;
INT result = ERROR_SUCCESS;
DWORD dwQueryFlags = DNS_QUERY_STANDARD;
+ PWCHAR Aliases[WS2_INTERNAL_MAX_ALIAS] = { 0 };
+ int AliasIndex = 0;
/* needed to be cleaned up if != NULL */
dp = NULL;
@@ -492,13 +494,12 @@
/* DNS_TYPE_A: include/WinDNS.h */
/* DnsQuery -- lib/dnsapi/dnsapi/query.c */
- dns_status = DnsQuery(data->hostnameW,
- DNS_TYPE_A,
- dwQueryFlags,
- /* extra dns servers */ 0,
- &dp,
- 0);
-
+ dns_status = DnsQuery_W(data->hostnameW,
+ DNS_TYPE_A,
+ dwQueryFlags,
+ NULL /* extra dns servers */,
+ &dp,
+ NULL);
if (dns_status == ERROR_INVALID_NAME)
{
WSASetLastError(WSAEFAULT);
@@ -517,7 +518,10 @@
curr = dp;
while ((curr->pNext != NULL) || (curr->wType != DNS_TYPE_A))
{
- /* FIXME build aliases list */
+ if (curr->wType == DNS_TYPE_CNAME)
+ {
+ Aliases[AliasIndex++] = curr->Data.Cname.pNameHost;
+ }
curr = curr->pNext;
}
@@ -526,10 +530,12 @@
result = WSASERVICE_NOT_FOUND;
goto cleanup;
}
-
hostinfo->hostnameW = StrCpyHeapAllocW(hHeap, curr->pName);
hostinfo->addr4 = curr->Data.A.IpAddress;
- /* FIXME attach built aliases list */
+ if (AliasIndex)
+ {
+ hostinfo->servaliasesA = StrAryCpyHeapAllocWToA(hHeap,
(WCHAR**)&Aliases);
+ }
result = ERROR_SUCCESS;
cleanup: