[IPCONFIG][DNSAPI][SDK] Renamed DNSCACHEENTRY and fixed its type field(s)

Now, 'ipconfig /displaydns' displays A- and AAAA-records correctly.
This commit is contained in:
Eric Kohl 2019-10-27 08:35:03 +01:00
parent 9bf672d4f1
commit 789edebfac
3 changed files with 201 additions and 159 deletions

View file

@ -34,6 +34,59 @@
HINSTANCE hInstance; HINSTANCE hInstance;
HANDLE ProcessHeap; 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, int LoadStringAndOem(HINSTANCE hInst,
UINT uID, UINT uID,
LPTSTR szNode, LPTSTR szNode,
@ -607,22 +660,20 @@ VOID Release(LPTSTR Index)
IP_ADAPTER_INDEX_MAP AdapterInfo; IP_ADAPTER_INDEX_MAP AdapterInfo;
DWORD ret; DWORD ret;
DWORD i; DWORD i;
PIP_INTERFACE_INFO pInfo = NULL;
ULONG ulOutBufLen = 0;
/* if interface is not given, query GetInterfaceInfo */ if (GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER)
if (Index == NULL)
{ {
PIP_INTERFACE_INFO pInfo = NULL; pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, ulOutBufLen);
ULONG ulOutBufLen = 0; 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); for (i = 0; i < pInfo->NumAdapters; i++)
if (pInfo == NULL)
return;
if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR )
{ {
for (i = 0; i < pInfo->NumAdapters; i++) if (DoNamesMatch(pInfo->Adapter[i].Name, Index))
{ {
CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP)); CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP));
_tprintf(_T("name - %ls\n"), pInfo->Adapter[i].Name); _tprintf(_T("name - %ls\n"), pInfo->Adapter[i].Name);
@ -634,71 +685,57 @@ VOID Release(LPTSTR Index)
DoFormatMessage(ret); DoFormatMessage(ret);
} }
} }
}
HeapFree(ProcessHeap, 0, pInfo); HeapFree(ProcessHeap, 0, pInfo);
}
else
{
DoFormatMessage(0);
HeapFree(ProcessHeap, 0, pInfo);
return;
}
} }
else else
{ {
DoFormatMessage(0); DoFormatMessage(0);
HeapFree(ProcessHeap, 0, pInfo);
return; return;
} }
} }
else else
{ {
; DoFormatMessage(0);
/* FIXME: return;
* 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
*/
} }
} }
VOID Renew(LPTSTR Index) VOID Renew(LPTSTR Index)
{ {
IP_ADAPTER_INDEX_MAP AdapterInfo; IP_ADAPTER_INDEX_MAP AdapterInfo;
PIP_INTERFACE_INFO pInfo;
ULONG ulOutBufLen = 0;
DWORD i; DWORD i;
/* if interface is not given, query GetInterfaceInfo */ pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, sizeof(IP_INTERFACE_INFO));
if (Index == NULL) if (pInfo == NULL)
{ {
PIP_INTERFACE_INFO pInfo; _tprintf(_T("memory allocation error"));
ULONG ulOutBufLen = 0; 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) if (pInfo == NULL)
{ {
_tprintf(_T("memory allocation error")); _tprintf(_T("memory allocation error"));
return; return;
} }
}
/* Make an initial call to GetInterfaceInfo to get /* Make a second call to GetInterfaceInfo to get the actual data we want */
* the necessary size into the ulOutBufLen variable */ if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR)
if (GetInterfaceInfo(pInfo, &ulOutBufLen) == ERROR_INSUFFICIENT_BUFFER) {
for (i = 0; i < pInfo->NumAdapters; i++)
{ {
HeapFree(ProcessHeap, 0, pInfo); if (DoNamesMatch(pInfo->Adapter[i].Name, Index))
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)
{
for (i = 0; i < pInfo->NumAdapters; i++)
{ {
CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP)); CopyMemory(&AdapterInfo, &pInfo->Adapter[i], sizeof(IP_ADAPTER_INDEX_MAP));
_tprintf(_T("name - %ls\n"), pInfo->Adapter[i].Name); _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 else
{ {
; _tprintf(_T("\nGetInterfaceInfo failed : "));
/* FIXME: DoFormatMessage(0);
* 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
*/
} }
HeapFree(ProcessHeap, 0, pInfo);
} }
VOID VOID
@ -741,15 +769,110 @@ FlushDns(VOID)
DoFormatMessage(GetLastError()); DoFormatMessage(GetLastError());
} }
static
VOID
DisplayDnsRecord(
PWSTR pszName,
WORD wType)
{
PDNS_RECORDW pQueryResults = NULL, pThisRecord, pNextRecord;
WCHAR szBuffer[48];
IN_ADDR Addr4;
IN6_ADDR Addr6;
DNS_STATUS Status;
pQueryResults = NULL;
Status = DnsQuery_W(pszName,
wType,
DNS_QUERY_NO_WIRE_QUERY,
NULL,
(PDNS_RECORD *)&pQueryResults,
NULL);
if (Status != ERROR_SUCCESS)
{
#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;
}
_tprintf(_T("\t%S\n"), pszName);
_tprintf(_T("\t----------------------------------------\n"));
pThisRecord = pQueryResults;
while (pThisRecord != NULL)
{
pNextRecord = pThisRecord->pNext;
_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)
{
case DnsSectionQuestion:
_tprintf(_T("\tSection . . . . . . . : Question\n"));
break;
case DnsSectionAnswer:
_tprintf(_T("\tSection . . . . . . . : Answer\n"));
break;
case DnsSectionAuthority:
_tprintf(_T("\tSection . . . . . . . : Authority\n"));
break;
case DnsSectionAdditional:
_tprintf(_T("\tSection . . . . . . . : Additional\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"));
pThisRecord = pNextRecord;
}
DnsRecordListFree((PDNS_RECORD)pQueryResults, DnsFreeRecordList);
}
VOID VOID
DisplayDns(VOID) DisplayDns(VOID)
{ {
PDNSCACHEENTRY DnsEntry = NULL, pThisEntry, pNextEntry; PDNS_CACHE_ENTRY DnsEntry = NULL, pThisEntry, pNextEntry;
PDNS_RECORDW pQueryResults, pThisRecord, pNextRecord;
IN_ADDR Addr4;
IN6_ADDR Addr6;
WCHAR szBuffer[48];
DNS_STATUS Status;
_tprintf(_T("\nReactOS IP Configuration\n\n")); _tprintf(_T("\nReactOS IP Configuration\n\n"));
@ -767,87 +890,9 @@ DisplayDns(VOID)
{ {
pNextEntry = pThisEntry->pNext; pNextEntry = pThisEntry->pNext;
pQueryResults = NULL; DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType1);
Status = DnsQuery_W(pThisEntry->pszName, if (pThisEntry->wType2 != 0)
pThisEntry->wType, DisplayDnsRecord(pThisEntry->pszName, pThisEntry->wType2);
DNS_QUERY_NO_WIRE_QUERY,
NULL,
(PDNS_RECORD *)&pQueryResults,
NULL);
if (Status == 0)
{
_tprintf(_T("\t%S\n"), pThisEntry->pszName);
_tprintf(_T("\t----------------------------------------\n"));
pThisRecord = pQueryResults;
while (pThisRecord != NULL)
{
pNextRecord = pThisRecord->pNext;
_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)
{
case DnsSectionQuestion:
_tprintf(_T("\tSection . . . . . . . : Question\n"));
break;
case DnsSectionAnswer:
_tprintf(_T("\tSection . . . . . . . : Answer\n"));
break;
case DnsSectionAuthority:
_tprintf(_T("\tSection . . . . . . . : Authority\n"));
break;
case DnsSectionAdditional:
_tprintf(_T("\tSection . . . . . . . : Additional\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"));
pThisRecord = pNextRecord;
}
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);
}
if (pThisEntry->pszName) if (pThisEntry->pszName)
LocalFree(pThisEntry->pszName); LocalFree(pThisEntry->pszName);
@ -890,8 +935,6 @@ VOID Usage(VOID)
HeapFree(ProcessHeap, 0, lpUsage); HeapFree(ProcessHeap, 0, lpUsage);
} }
} }
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
@ -975,10 +1018,9 @@ int main(int argc, char *argv[])
break; break;
case 3: /* Process all the options that can have 1 parameter */ case 3: /* Process all the options that can have 1 parameter */
if (DoRelease) if (DoRelease)
_tprintf(_T("\nSorry /release [adapter] is not implemented yet\n")); Release(argv[2]);
//Release(argv[2]);
else if (DoRenew) else if (DoRenew)
_tprintf(_T("\nSorry /renew [adapter] is not implemented yet\n")); Renew(argv[2]);
else if (DoShowclassid) else if (DoShowclassid)
_tprintf(_T("\nSorry /showclassid adapter is not implemented yet\n")); _tprintf(_T("\nSorry /showclassid adapter is not implemented yet\n"));
else if (DoSetclassid) else if (DoSetclassid)

View file

@ -276,7 +276,7 @@ DnsGetBufferLengthForStringCopy()
BOOL BOOL
WINAPI WINAPI
DnsGetCacheDataTable( DnsGetCacheDataTable(
_Out_ PDNSCACHEENTRY *DnsCache) _Out_ PDNS_CACHE_ENTRY *DnsCache)
{ {
UNIMPLEMENTED; UNIMPLEMENTED;
return TRUE; return TRUE;

View file

@ -9,10 +9,10 @@ typedef struct _DNS_CACHE_ENTRY
{ {
struct _DNS_CACHE_ENTRY *pNext; /* Pointer to next entry */ struct _DNS_CACHE_ENTRY *pNext; /* Pointer to next entry */
PWSTR pszName; /* DNS Record Name */ PWSTR pszName; /* DNS Record Name */
unsigned short wType; /* DNS Record Type */ unsigned short wType1; /* DNS Record Type 1 */
unsigned short wUnknown; /* Unknown */ unsigned short wType2; /* DNS Record Type 2 */
unsigned short wFlags; /* DNS Record Flags */ unsigned short wFlags; /* DNS Record Flags */
} DNSCACHEENTRY, *PDNSCACHEENTRY; } DNS_CACHE_ENTRY, *PDNS_CACHE_ENTRY;
BOOL BOOL
WINAPI WINAPI
@ -21,7 +21,7 @@ DnsFlushResolverCache(VOID);
BOOL BOOL
WINAPI WINAPI
DnsGetCacheDataTable( DnsGetCacheDataTable(
_Out_ PDNSCACHEENTRY *DnsCache); _Out_ PDNS_CACHE_ENTRY *DnsCache);
#ifdef __cplusplus #ifdef __cplusplus
} }