[IPCONFIG] Implement the /setclassid option

The current implementation does not notify the dhcp client of the changed registry setting. Windows IPCONFIG calls DhcpHandlePnpEvent after setting the DhcpClassId registry value.
This commit is contained in:
Eric Kohl
2025-07-20 13:58:13 +02:00
parent 9750f6decd
commit ea189a3048
22 changed files with 149 additions and 4 deletions

View File

@@ -1228,7 +1228,110 @@ DisplayDns(VOID)
}
}
VOID Usage(VOID)
VOID
ShowClassId(
LPWSTR pszAdapterName)
{
_tprintf(_T("\nSorry /showclassid adapter is not implemented yet\n"));
}
VOID
SetClassId(
LPWSTR pszAdapterName,
LPWSTR pszClassId)
{
PIP_ADAPTER_INFO pAdapterInfo = NULL;
PIP_ADAPTER_INFO pAdapter = NULL, pFoundAdapter = NULL;
ULONG adaptOutBufLen = 0;
ULONG ret = 0;
WCHAR szFriendlyName[MAX_PATH];
WCHAR szKeyName[256];
MIB_IFROW mibEntry;
HKEY hKey;
ConResPrintf(StdOut, IDS_HEADER);
/* call GetAdaptersInfo to obtain the adapter info */
ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
if (ret != ERROR_BUFFER_OVERFLOW)
{
DoFormatMessage(ret);
return;
}
pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
if (pAdapterInfo == NULL)
{
_tprintf(_T("memory allocation error"));
return;
}
ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
if (ret != NO_ERROR)
{
DoFormatMessage(0);
goto done;
}
pAdapter = pAdapterInfo;
while (pAdapter)
{
GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
if (MatchWildcard(pszAdapterName, szFriendlyName))
{
mibEntry.dwIndex = pAdapter->Index;
GetIfEntry(&mibEntry);
if (mibEntry.dwOperStatus == MIB_IF_OPER_STATUS_CONNECTED ||
mibEntry.dwOperStatus == MIB_IF_OPER_STATUS_OPERATIONAL)
{
pFoundAdapter = pAdapter;
break;
}
}
pAdapter = pAdapter->Next;
}
if (pFoundAdapter)
{
swprintf(szKeyName,
L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%S",
pFoundAdapter->AdapterName);
ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
szKeyName,
0,
KEY_WRITE,
&hKey);
if (ret != ERROR_SUCCESS)
{
ConResPrintf(StdOut, IDS_DHCPSETIDERROR, szFriendlyName);
DoFormatMessage(ret);
goto done;
}
if (pszClassId == NULL)
pszClassId = L"";
RegSetValueExW(hKey, L"DhcpClassId", 0, REG_SZ, (LPBYTE)pszClassId, (wcslen(pszClassId) + 1) * sizeof(WCHAR));
RegCloseKey(hKey);
ConResPrintf(StdOut, IDS_DHCPSETIDSUCCESS, szFriendlyName);
}
else
{
ConResPrintf(StdOut, IDS_DHCPNOADAPTER);
}
done:
if (pAdapterInfo)
HeapFree(ProcessHeap, 0, pAdapterInfo);
}
VOID
Usage(VOID)
{
ConResPrintf(StdOut, IDS_USAGE);
}
@@ -1321,15 +1424,15 @@ int wmain(int argc, wchar_t *argv[])
else if (DoRenew)
Renew(argv[2]);
else if (DoShowclassid)
_tprintf(_T("\nSorry /showclassid adapter is not implemented yet\n"));
ShowClassId(argv[2]);
else if (DoSetclassid)
_tprintf(_T("\nSorry /setclassid adapter is not implemented yet\n"));
SetClassId(argv[2], NULL);
else
Usage();
break;
case 4: /* Process all the options that can have 2 parameters */
if (DoSetclassid)
_tprintf(_T("\nSorry /setclassid adapter [classid]is not implemented yet\n"));
SetClassId(argv[2], argv[3]);
else
Usage();
break;

View File

@@ -91,6 +91,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -93,6 +93,8 @@ BEGIN
IDS_DHCPRELEASED "Die IP-Adresse für den Adapter %ls wurde bereits freigegeben.\n"
IDS_DHCPRELEASEERROR "Beim Freigeben der Schnittstelle %ls ist folgender Fehler aufgetreten: "
IDS_DHCPRENEWERROR "Beim Aktualisieren der Schnittstelle %ls ist folgender Fehler aufgetreten: "
IDS_DHCPSETIDERROR "Fehler beim Festlegen der Klassenkennung für Adapter %ls: "
IDS_DHCPSETIDSUCCESS "Klassenkennung für Adapter %ls festgelegt."
END
STRINGTABLE

View File

@@ -91,6 +91,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -91,6 +91,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -92,6 +92,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -94,6 +94,8 @@ BEGIN
IDS_DHCPRELEASED "L'adresse IP de l'adaptateur %ls a déjà été libérée.\n"
IDS_DHCPRELEASEERROR "Une erreur est survenue lors de la libération de l'interface %ls : "
IDS_DHCPRENEWERROR "Une erreur est survenue lors du renouvellement de l'interface %ls : "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -91,6 +91,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -91,6 +91,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -91,6 +91,8 @@ BEGIN
IDS_DHCPRELEASED "アダプタ %ls に対する IP アドレス はすでに解放されています。\n"
IDS_DHCPRELEASEERROR "インターフェース %ls の解放中にエラーが起きました: "
IDS_DHCPRENEWERROR "インターフェース %ls の更新中にエラーが起きました: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -91,6 +91,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -70,6 +70,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -92,6 +92,8 @@ BEGIN
IDS_DHCPRELEASED "Adresa IP pentru adaptorul %ls a fost deja eliberată.\n"
IDS_DHCPRELEASEERROR "A apărut o eroare în timpul eliberării interfeței %ls: "
IDS_DHCPRENEWERROR "A apărut o eroare în timpul reînnoirii interfeței %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -92,6 +92,8 @@ BEGIN
IDS_DHCPRELEASED "IP-адрес для адаптера ""%ls"" уже освобождён.\n"
IDS_DHCPRELEASEERROR "Произошла ошибка при освобождении интерфейса ""%ls"": "
IDS_DHCPRENEWERROR "Произошла ошибка при обновлении интерфейса ""%ls"": "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -91,6 +91,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -91,6 +91,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -92,6 +92,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -92,6 +92,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -92,6 +92,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -92,6 +92,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -92,6 +92,8 @@ BEGIN
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
END
STRINGTABLE

View File

@@ -77,3 +77,5 @@
#define IDS_DHCPRELEASED 207
#define IDS_DHCPRELEASEERROR 208
#define IDS_DHCPRENEWERROR 209
#define IDS_DHCPSETIDERROR 210
#define IDS_DHCPSETIDSUCCESS 211