[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,10 +660,6 @@ VOID Release(LPTSTR Index)
IP_ADAPTER_INDEX_MAP AdapterInfo; IP_ADAPTER_INDEX_MAP AdapterInfo;
DWORD ret; DWORD ret;
DWORD i; DWORD i;
/* if interface is not given, query GetInterfaceInfo */
if (Index == NULL)
{
PIP_INTERFACE_INFO pInfo = NULL; PIP_INTERFACE_INFO pInfo = NULL;
ULONG ulOutBufLen = 0; ULONG ulOutBufLen = 0;
@ -623,6 +672,8 @@ VOID Release(LPTSTR Index)
if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR ) 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)); 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,6 +685,7 @@ VOID Release(LPTSTR Index)
DoFormatMessage(ret); DoFormatMessage(ret);
} }
} }
}
HeapFree(ProcessHeap, 0, pInfo); HeapFree(ProcessHeap, 0, pInfo);
} }
@ -650,30 +702,13 @@ VOID Release(LPTSTR Index)
return; 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
*/
}
}
VOID Renew(LPTSTR Index) VOID Renew(LPTSTR Index)
{ {
IP_ADAPTER_INDEX_MAP AdapterInfo; IP_ADAPTER_INDEX_MAP AdapterInfo;
DWORD i;
/* if interface is not given, query GetInterfaceInfo */
if (Index == NULL)
{
PIP_INTERFACE_INFO pInfo; PIP_INTERFACE_INFO pInfo;
ULONG ulOutBufLen = 0; ULONG ulOutBufLen = 0;
DWORD i;
pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, sizeof(IP_INTERFACE_INFO)); pInfo = (IP_INTERFACE_INFO *)HeapAlloc(ProcessHeap, 0, sizeof(IP_INTERFACE_INFO));
if (pInfo == NULL) if (pInfo == NULL)
@ -699,6 +734,8 @@ VOID Renew(LPTSTR Index)
if (GetInterfaceInfo(pInfo, &ulOutBufLen) == NO_ERROR) 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)); 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,6 +748,7 @@ VOID Renew(LPTSTR Index)
} }
} }
} }
}
else else
{ {
_tprintf(_T("\nGetInterfaceInfo failed : ")); _tprintf(_T("\nGetInterfaceInfo failed : "));
@ -719,16 +757,6 @@ VOID Renew(LPTSTR Index)
HeapFree(ProcessHeap, 0, pInfo); 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
*/
}
}
VOID VOID
FlushDns(VOID) FlushDns(VOID)
@ -741,42 +769,40 @@ FlushDns(VOID)
DoFormatMessage(GetLastError()); DoFormatMessage(GetLastError());
} }
static
VOID VOID
DisplayDns(VOID) DisplayDnsRecord(
PWSTR pszName,
WORD wType)
{ {
PDNSCACHEENTRY DnsEntry = NULL, pThisEntry, pNextEntry; PDNS_RECORDW pQueryResults = NULL, pThisRecord, pNextRecord;
PDNS_RECORDW pQueryResults, pThisRecord, pNextRecord; WCHAR szBuffer[48];
IN_ADDR Addr4; IN_ADDR Addr4;
IN6_ADDR Addr6; IN6_ADDR Addr6;
WCHAR szBuffer[48];
DNS_STATUS Status; DNS_STATUS Status;
_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;
pQueryResults = NULL; pQueryResults = NULL;
Status = DnsQuery_W(pThisEntry->pszName, Status = DnsQuery_W(pszName,
pThisEntry->wType, wType,
DNS_QUERY_NO_WIRE_QUERY, DNS_QUERY_NO_WIRE_QUERY,
NULL, NULL,
(PDNS_RECORD *)&pQueryResults, (PDNS_RECORD *)&pQueryResults,
NULL); NULL);
if (Status == 0) if (Status != ERROR_SUCCESS)
{ {
_tprintf(_T("\t%S\n"), pThisEntry->pszName); #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")); _tprintf(_T("\t----------------------------------------\n"));
pThisRecord = pQueryResults; pThisRecord = pQueryResults;
@ -840,15 +866,34 @@ DisplayDns(VOID)
} }
DnsRecordListFree((PDNS_RECORD)pQueryResults, DnsFreeRecordList); DnsRecordListFree((PDNS_RECORD)pQueryResults, DnsFreeRecordList);
pQueryResults = NULL;
} }
else if (Status != ERROR_SUCCESS && pThisEntry->wType != 0)
VOID
DisplayDns(VOID)
{ {
_tprintf(_T("\t%S\n"), pThisEntry->pszName); PDNS_CACHE_ENTRY DnsEntry = NULL, pThisEntry, pNextEntry;
_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) if (pThisEntry->pszName)
LocalFree(pThisEntry->pszName); LocalFree(pThisEntry->pszName);
LocalFree(pThisEntry); LocalFree(pThisEntry);
@ -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
} }