https://git.reactos.org/?p=reactos.git;a=commitdiff;h=789edebfac79fd9da5c74…
commit 789edebfac79fd9da5c74afb17917bfda01b6d55
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sun Oct 27 08:35:03 2019 +0100
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sun Oct 27 08:35:03 2019 +0100
[IPCONFIG][DNSAPI][SDK] Renamed DNSCACHEENTRY and fixed its type field(s)
Now, 'ipconfig /displaydns' displays A- and AAAA-records correctly.
---
base/applications/network/ipconfig/ipconfig.c | 344 +++++++++++++++-----------
dll/win32/dnsapi/dnsapi/stubs.c | 2 +-
sdk/include/reactos/windns_undoc.h | 8 +-
3 files changed, 198 insertions(+), 156 deletions(-)
diff --git a/base/applications/network/ipconfig/ipconfig.c
b/base/applications/network/ipconfig/ipconfig.c
index ced1de7072d..fdebdb1d8b4 100644
--- a/base/applications/network/ipconfig/ipconfig.c
+++ b/base/applications/network/ipconfig/ipconfig.c
@@ -34,6 +34,59 @@
HINSTANCE hInstance;
HANDLE ProcessHeap;
+BOOL
+DoNamesMatch(
+ _In_ LPWSTR pszName,
+ _In_ LPTSTR pszPattern)
+{
+ if (pszPattern == NULL)
+ return TRUE;
+
+// if (_wcsicmp(pszName, pszPattern) == 0)
+// return TRUE;
+#if 0
+ for (;;)
+ {
+ if (*pszPattern == L'*')
+ {
+ pszPattern++;
+ if (*pszPattern == L'\0')
+ return TRUE;
+
+ while (towlower(*pszName) != towlower(*pszPattern))
+ {
+ if (*pszName == L'\0')
+ return FALSE;
+
+ pszName++;
+ }
+ }
+ else if (*pszPattern == L'?')
+ {
+ pszPattern++;
+
+ if (*pszName == L'\0')
+ return FALSE;
+
+ pszName++;
+ }
+ else
+ {
+ if (*pszName == L'\0' && *pszPattern == L'\0')
+ return TRUE;
+
+ if (towlower(*pszName) != towlower(*pszPattern))
+ return FALSE;
+
+ pszName++;
+ pszPattern++;
+ }
+ }
+#endif
+
+ return FALSE;
+}
+
int LoadStringAndOem(HINSTANCE hInst,
UINT uID,
LPTSTR szNode,
@@ -607,22 +660,20 @@ VOID Release(LPTSTR Index)
IP_ADAPTER_INDEX_MAP AdapterInfo;
DWORD ret;
DWORD i;
+ PIP_INTERFACE_INFO pInfo = NULL;
+ ULONG ulOutBufLen = 0;
- /* if interface is not given, query GetInterfaceInfo */
- if (Index == NULL)
+ if (GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
{
- PIP_INTERFACE_INFO pInfo = NULL;
- ULONG ulOutBufLen = 0;
+ pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, ulOutBufLen);
+ if (pInfo == NULL)
+ return;
- if (GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
+ if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR )
{
- pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, ulOutBufLen);
- if (pInfo == NULL)
- return;
-
- if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR )
+ for (i = 0; i < pInfo->NumAdapters; i++)
{
- for (i = 0; i < pInfo->NumAdapters; i++)
+ if (DoNamesMatch(pInfo->Adapter[i].Name, Index))
{
CopyMemory(&AdapterInfo, &pInfo->Adapter[i],
sizeof(IP_ADAPTER_INDEX_MAP));
_tprintf(_T("name - %ls\n"), pInfo->Adapter[i].Name);
@@ -634,71 +685,57 @@ VOID Release(LPTSTR Index)
DoFormatMessage(ret);
}
}
-
- HeapFree(ProcessHeap, 0, pInfo);
- }
- else
- {
- DoFormatMessage(0);
- HeapFree(ProcessHeap, 0, pInfo);
- return;
}
+
+ HeapFree(ProcessHeap, 0, pInfo);
}
else
{
DoFormatMessage(0);
+ HeapFree(ProcessHeap, 0, pInfo);
return;
}
}
else
{
- ;
- /* FIXME:
- * we need to be able to release connections by name with support for globbing
- * i.e. ipconfig /release Eth* will release all cards starting with Eth...
- * ipconfig /release *con* will release all cards with 'con' in
their name
- */
+ DoFormatMessage(0);
+ return;
}
}
-
-
-
VOID Renew(LPTSTR Index)
{
IP_ADAPTER_INDEX_MAP AdapterInfo;
+ PIP_INTERFACE_INFO pInfo;
+ ULONG ulOutBufLen = 0;
DWORD i;
- /* if interface is not given, query GetInterfaceInfo */
- if (Index == NULL)
+ pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, sizeof(IP_INTERFACE_INFO));
+ if (pInfo == NULL)
{
- PIP_INTERFACE_INFO pInfo;
- ULONG ulOutBufLen = 0;
+ _tprintf(_T("memory allocation error"));
+ return;
+ }
- pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0,
sizeof(IP_INTERFACE_INFO));
+ /* Make an initial call to GetInterfaceInfo to get
+ * the necessary size into the ulOutBufLen variable */
+ if (GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
+ {
+ HeapFree(ProcessHeap, 0, pInfo);
+ pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, ulOutBufLen);
if (pInfo == NULL)
{
_tprintf(_T("memory allocation error"));
return;
}
+ }
- /* Make an initial call to GetInterfaceInfo to get
- * the necessary size into the ulOutBufLen variable */
- if (GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
- {
- HeapFree(ProcessHeap, 0, pInfo);
- pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, ulOutBufLen);
- if (pInfo == NULL)
- {
- _tprintf(_T("memory allocation error"));
- return;
- }
- }
-
- /* Make a second call to GetInterfaceInfo to get the actual data we want */
- if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR)
+ /* Make a second call to GetInterfaceInfo to get the actual data we want */
+ if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR)
+ {
+ for (i = 0; i < pInfo->NumAdapters; i++)
{
- for (i = 0; i < pInfo->NumAdapters; i++)
+ if (DoNamesMatch(pInfo->Adapter[i].Name, Index))
{
CopyMemory(&AdapterInfo, &pInfo->Adapter[i],
sizeof(IP_ADAPTER_INDEX_MAP));
_tprintf(_T("name - %ls\n"), pInfo->Adapter[i].Name);
@@ -711,23 +748,14 @@ VOID Renew(LPTSTR Index)
}
}
}
- else
- {
- _tprintf(_T("\nGetInterfaceInfo failed : "));
- DoFormatMessage(0);
- }
-
- HeapFree(ProcessHeap, 0, pInfo);
}
else
{
- ;
- /* FIXME:
- * we need to be able to renew connections by name with support for globbing
- * i.e. ipconfig /renew Eth* will renew all cards starting with Eth...
- * ipconfig /renew *con* will renew all cards with 'con' in their
name
- */
+ _tprintf(_T("\nGetInterfaceInfo failed : "));
+ DoFormatMessage(0);
}
+
+ HeapFree(ProcessHeap, 0, pInfo);
}
VOID
@@ -741,113 +769,130 @@ FlushDns(VOID)
DoFormatMessage(GetLastError());
}
+
+static
VOID
-DisplayDns(VOID)
+DisplayDnsRecord(
+ PWSTR pszName,
+ WORD wType)
{
- PDNSCACHEENTRY DnsEntry = NULL, pThisEntry, pNextEntry;
- PDNS_RECORDW pQueryResults, pThisRecord, pNextRecord;
+ PDNS_RECORDW pQueryResults = NULL, pThisRecord, pNextRecord;
+ WCHAR szBuffer[48];
IN_ADDR Addr4;
IN6_ADDR Addr6;
- WCHAR szBuffer[48];
DNS_STATUS Status;
- _tprintf(_T("\nReactOS IP Configuration\n\n"));
-
- if (!DnsGetCacheDataTable(&DnsEntry))
+ pQueryResults = NULL;
+ Status = DnsQuery_W(pszName,
+ wType,
+ DNS_QUERY_NO_WIRE_QUERY,
+ NULL,
+ (PDNS_RECORD *)&pQueryResults,
+ NULL);
+ if (Status != ERROR_SUCCESS)
{
- DoFormatMessage(GetLastError());
+#if 0
+ if (wType != 0)
+ {
+ _tprintf(_T("\t%S\n"), pszName);
+ _tprintf(_T("\t----------------------------------------\n"));
+ _tprintf(_T("\tNo records of type %hu\n\n"), wType);
+ }
+#endif
return;
}
- if (DnsEntry == NULL)
- return;
+ _tprintf(_T("\t%S\n"), pszName);
+ _tprintf(_T("\t----------------------------------------\n"));
- pThisEntry = DnsEntry;
- while (pThisEntry != NULL)
+ pThisRecord = pQueryResults;
+ while (pThisRecord != NULL)
{
- pNextEntry = pThisEntry->pNext;
+ pNextRecord = pThisRecord->pNext;
- pQueryResults = NULL;
- Status = DnsQuery_W(pThisEntry->pszName,
- pThisEntry->wType,
- DNS_QUERY_NO_WIRE_QUERY,
- NULL,
- (PDNS_RECORD *)&pQueryResults,
- NULL);
- if (Status == 0)
+ _tprintf(_T("\tRecord Name . . . . . : %S\n"), pThisRecord->pName);
+ _tprintf(_T("\tRecord Type . . . . . : %hu\n"),
pThisRecord->wType);
+ _tprintf(_T("\tTime To Live. . . . . : %lu\n"),
pThisRecord->dwTtl);
+ _tprintf(_T("\tData Length . . . . . : %hu\n"),
pThisRecord->wDataLength);
+
+ switch (pThisRecord->Flags.S.Section)
{
- _tprintf(_T("\t%S\n"), pThisEntry->pszName);
- _tprintf(_T("\t----------------------------------------\n"));
+ case DnsSectionQuestion:
+ _tprintf(_T("\tSection . . . . . . . : Question\n"));
+ break;
- pThisRecord = pQueryResults;
- while (pThisRecord != NULL)
- {
- pNextRecord = pThisRecord->pNext;
+ case DnsSectionAnswer:
+ _tprintf(_T("\tSection . . . . . . . : Answer\n"));
+ break;
- _tprintf(_T("\tRecord Name . . . . . : %S\n"),
pThisRecord->pName);
- _tprintf(_T("\tRecord Type . . . . . : %hu\n"),
pThisRecord->wType);
- _tprintf(_T("\tTime To Live. . . . . : %lu\n"),
pThisRecord->dwTtl);
- _tprintf(_T("\tData Length . . . . . : %hu\n"),
pThisRecord->wDataLength);
+ case DnsSectionAuthority:
+ _tprintf(_T("\tSection . . . . . . . : Authority\n"));
+ break;
- switch (pThisRecord->Flags.S.Section)
- {
- case DnsSectionQuestion:
- _tprintf(_T("\tSection . . . . . . . : Question\n"));
- break;
+ case DnsSectionAdditional:
+ _tprintf(_T("\tSection . . . . . . . : Additional\n"));
+ break;
+ }
- case DnsSectionAnswer:
- _tprintf(_T("\tSection . . . . . . . : Answer\n"));
- break;
+ switch (pThisRecord->wType)
+ {
+ case DNS_TYPE_A:
+ Addr4.S_un.S_addr = pThisRecord->Data.A.IpAddress;
+ RtlIpv4AddressToStringW(&Addr4, szBuffer);
+ _tprintf(_T("\tA (Host) Record . . . : %S\n"), szBuffer);
+ break;
+
+ case DNS_TYPE_PTR:
+ _tprintf(_T("\tPTR Record. . . . . . : %S\n"),
pThisRecord->Data.PTR.pNameHost);
+ break;
+
+ case DNS_TYPE_NS:
+ _tprintf(_T("\tNS Record . . . . . . : %S\n"),
pThisRecord->Data.NS.pNameHost);
+ break;
+
+ case DNS_TYPE_CNAME:
+ _tprintf(_T("\tCNAME Record. . . . . : %S\n"),
pThisRecord->Data.CNAME.pNameHost);
+ break;
+
+ case DNS_TYPE_AAAA:
+ RtlCopyMemory(&Addr6, &pThisRecord->Data.AAAA.Ip6Address,
sizeof(IN6_ADDR));
+ RtlIpv6AddressToStringW(&Addr6, szBuffer);
+ _tprintf(_T("\tAAAA Record . . . . . : %S\n"), szBuffer);
+ break;
+ }
+ _tprintf(_T("\n\n"));
- case DnsSectionAuthority:
- _tprintf(_T("\tSection . . . . . . . : Authority\n"));
- break;
+ pThisRecord = pNextRecord;
+ }
- case DnsSectionAdditional:
- _tprintf(_T("\tSection . . . . . . . :
Additional\n"));
- break;
- }
+ DnsRecordListFree((PDNS_RECORD)pQueryResults, DnsFreeRecordList);
+}
- switch (pThisRecord->wType)
- {
- case DNS_TYPE_A:
- Addr4.S_un.S_addr = pThisRecord->Data.A.IpAddress;
- RtlIpv4AddressToStringW(&Addr4, szBuffer);
- _tprintf(_T("\tA (Host) Record . . . : %S\n"),
szBuffer);
- break;
-
- case DNS_TYPE_PTR:
- _tprintf(_T("\tPTR Record. . . . . . : %S\n"),
pThisRecord->Data.PTR.pNameHost);
- break;
-
- case DNS_TYPE_NS:
- _tprintf(_T("\tNS Record . . . . . . : %S\n"),
pThisRecord->Data.NS.pNameHost);
- break;
-
- case DNS_TYPE_CNAME:
- _tprintf(_T("\tCNAME Record. . . . . : %S\n"),
pThisRecord->Data.CNAME.pNameHost);
- break;
-
- case DNS_TYPE_AAAA:
- RtlCopyMemory(&Addr6,
&pThisRecord->Data.AAAA.Ip6Address, sizeof(IN6_ADDR));
- RtlIpv6AddressToStringW(&Addr6, szBuffer);
- _tprintf(_T("\tAAAA Record . . . . . : %S\n"),
szBuffer);
- break;
- }
- _tprintf(_T("\n\n"));
- pThisRecord = pNextRecord;
- }
+VOID
+DisplayDns(VOID)
+{
+ PDNS_CACHE_ENTRY DnsEntry = NULL, pThisEntry, pNextEntry;
- DnsRecordListFree((PDNS_RECORD)pQueryResults, DnsFreeRecordList);
- pQueryResults = NULL;
- }
- else if (Status != ERROR_SUCCESS && pThisEntry->wType != 0)
- {
- _tprintf(_T("\t%S\n"), pThisEntry->pszName);
- _tprintf(_T("\t----------------------------------------\n"));
- _tprintf(_T("\tNo records of type %hu\n\n"),
pThisEntry->wType);
- }
+ _tprintf(_T("\nReactOS IP Configuration\n\n"));
+
+ if (!DnsGetCacheDataTable(&DnsEntry))
+ {
+ DoFormatMessage(GetLastError());
+ return;
+ }
+
+ if (DnsEntry == NULL)
+ return;
+
+ pThisEntry = DnsEntry;
+ while (pThisEntry != NULL)
+ {
+ pNextEntry = pThisEntry->pNext;
+
+ DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType1);
+ if (pThisEntry->wType2 != 0)
+ DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType2);
if (pThisEntry->pszName)
LocalFree(pThisEntry->pszName);
@@ -890,8 +935,6 @@ VOID Usage(VOID)
HeapFree(ProcessHeap, 0, lpUsage);
}
}
-
-
}
int main(int argc, char *argv[])
@@ -975,10 +1018,9 @@ int main(int argc, char *argv[])
break;
case 3: /* Process all the options that can have 1 parameter */
if (DoRelease)
- _tprintf(_T("\nSorry /release [adapter] is not implemented
yet\n"));
- //Release(argv[2]);
+ Release(argv[2]);
else if (DoRenew)
- _tprintf(_T("\nSorry /renew [adapter] is not implemented
yet\n"));
+ Renew(argv[2]);
else if (DoShowclassid)
_tprintf(_T("\nSorry /showclassid adapter is not implemented
yet\n"));
else if (DoSetclassid)
diff --git a/dll/win32/dnsapi/dnsapi/stubs.c b/dll/win32/dnsapi/dnsapi/stubs.c
index 76bb1ef63c5..2832270d36b 100644
--- a/dll/win32/dnsapi/dnsapi/stubs.c
+++ b/dll/win32/dnsapi/dnsapi/stubs.c
@@ -276,7 +276,7 @@ DnsGetBufferLengthForStringCopy()
BOOL
WINAPI
DnsGetCacheDataTable(
- _Out_ PDNSCACHEENTRY *DnsCache)
+ _Out_ PDNS_CACHE_ENTRY *DnsCache)
{
UNIMPLEMENTED;
return TRUE;
diff --git a/sdk/include/reactos/windns_undoc.h b/sdk/include/reactos/windns_undoc.h
index af04fabb2c3..3af80a1dfc5 100644
--- a/sdk/include/reactos/windns_undoc.h
+++ b/sdk/include/reactos/windns_undoc.h
@@ -9,10 +9,10 @@ typedef struct _DNS_CACHE_ENTRY
{
struct _DNS_CACHE_ENTRY *pNext; /* Pointer to next entry */
PWSTR pszName; /* DNS Record Name */
- unsigned short wType; /* DNS Record Type */
- unsigned short wUnknown; /* Unknown */
+ unsigned short wType1; /* DNS Record Type 1 */
+ unsigned short wType2; /* DNS Record Type 2 */
unsigned short wFlags; /* DNS Record Flags */
-} DNSCACHEENTRY, *PDNSCACHEENTRY;
+} DNS_CACHE_ENTRY, *PDNS_CACHE_ENTRY;
BOOL
WINAPI
@@ -21,7 +21,7 @@ DnsFlushResolverCache(VOID);
BOOL
WINAPI
DnsGetCacheDataTable(
- _Out_ PDNSCACHEENTRY *DnsCache);
+ _Out_ PDNS_CACHE_ENTRY *DnsCache);
#ifdef __cplusplus
}