Skip to content

Commit ea189a3

Browse files
committed
[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.
1 parent 9750f6d commit ea189a3

File tree

22 files changed

+149
-4
lines changed

22 files changed

+149
-4
lines changed

base/applications/network/ipconfig/ipconfig.c

Lines changed: 107 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,110 @@ DisplayDns(VOID)
12281228
}
12291229
}
12301230

1231-
VOID Usage(VOID)
1231+
VOID
1232+
ShowClassId(
1233+
LPWSTR pszAdapterName)
1234+
{
1235+
_tprintf(_T("\nSorry /showclassid adapter is not implemented yet\n"));
1236+
}
1237+
1238+
VOID
1239+
SetClassId(
1240+
LPWSTR pszAdapterName,
1241+
LPWSTR pszClassId)
1242+
{
1243+
PIP_ADAPTER_INFO pAdapterInfo = NULL;
1244+
PIP_ADAPTER_INFO pAdapter = NULL, pFoundAdapter = NULL;
1245+
ULONG adaptOutBufLen = 0;
1246+
ULONG ret = 0;
1247+
WCHAR szFriendlyName[MAX_PATH];
1248+
WCHAR szKeyName[256];
1249+
MIB_IFROW mibEntry;
1250+
HKEY hKey;
1251+
1252+
ConResPrintf(StdOut, IDS_HEADER);
1253+
1254+
/* call GetAdaptersInfo to obtain the adapter info */
1255+
ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
1256+
if (ret != ERROR_BUFFER_OVERFLOW)
1257+
{
1258+
DoFormatMessage(ret);
1259+
return;
1260+
}
1261+
1262+
pAdapterInfo = (IP_ADAPTER_INFO *)HeapAlloc(ProcessHeap, 0, adaptOutBufLen);
1263+
if (pAdapterInfo == NULL)
1264+
{
1265+
_tprintf(_T("memory allocation error"));
1266+
return;
1267+
}
1268+
1269+
ret = GetAdaptersInfo(pAdapterInfo, &adaptOutBufLen);
1270+
if (ret != NO_ERROR)
1271+
{
1272+
DoFormatMessage(0);
1273+
goto done;
1274+
}
1275+
1276+
pAdapter = pAdapterInfo;
1277+
while (pAdapter)
1278+
{
1279+
GetAdapterFriendlyName(pAdapter->AdapterName, MAX_PATH, szFriendlyName);
1280+
1281+
if (MatchWildcard(pszAdapterName, szFriendlyName))
1282+
{
1283+
mibEntry.dwIndex = pAdapter->Index;
1284+
GetIfEntry(&mibEntry);
1285+
1286+
if (mibEntry.dwOperStatus == MIB_IF_OPER_STATUS_CONNECTED ||
1287+
mibEntry.dwOperStatus == MIB_IF_OPER_STATUS_OPERATIONAL)
1288+
{
1289+
pFoundAdapter = pAdapter;
1290+
break;
1291+
}
1292+
}
1293+
1294+
pAdapter = pAdapter->Next;
1295+
}
1296+
1297+
if (pFoundAdapter)
1298+
{
1299+
swprintf(szKeyName,
1300+
L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\%S",
1301+
pFoundAdapter->AdapterName);
1302+
1303+
ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
1304+
szKeyName,
1305+
0,
1306+
KEY_WRITE,
1307+
&hKey);
1308+
if (ret != ERROR_SUCCESS)
1309+
{
1310+
ConResPrintf(StdOut, IDS_DHCPSETIDERROR, szFriendlyName);
1311+
DoFormatMessage(ret);
1312+
goto done;
1313+
}
1314+
1315+
if (pszClassId == NULL)
1316+
pszClassId = L"";
1317+
1318+
RegSetValueExW(hKey, L"DhcpClassId", 0, REG_SZ, (LPBYTE)pszClassId, (wcslen(pszClassId) + 1) * sizeof(WCHAR));
1319+
RegCloseKey(hKey);
1320+
1321+
ConResPrintf(StdOut, IDS_DHCPSETIDSUCCESS, szFriendlyName);
1322+
}
1323+
else
1324+
{
1325+
ConResPrintf(StdOut, IDS_DHCPNOADAPTER);
1326+
}
1327+
1328+
done:
1329+
if (pAdapterInfo)
1330+
HeapFree(ProcessHeap, 0, pAdapterInfo);
1331+
}
1332+
1333+
VOID
1334+
Usage(VOID)
12321335
{
12331336
ConResPrintf(StdOut, IDS_USAGE);
12341337
}
@@ -1321,15 +1424,15 @@ int wmain(int argc, wchar_t *argv[])
13211424
else if (DoRenew)
13221425
Renew(argv[2]);
13231426
else if (DoShowclassid)
1324-
_tprintf(_T("\nSorry /showclassid adapter is not implemented yet\n"));
1427+
ShowClassId(argv[2]);
13251428
else if (DoSetclassid)
1326-
_tprintf(_T("\nSorry /setclassid adapter is not implemented yet\n"));
1429+
SetClassId(argv[2], NULL);
13271430
else
13281431
Usage();
13291432
break;
13301433
case 4: /* Process all the options that can have 2 parameters */
13311434
if (DoSetclassid)
1332-
_tprintf(_T("\nSorry /setclassid adapter [classid]is not implemented yet\n"));
1435+
SetClassId(argv[2], argv[3]);
13331436
else
13341437
Usage();
13351438
break;

base/applications/network/ipconfig/lang/bg-BG.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ BEGIN
9191
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
9292
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
9393
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
94+
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
95+
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
9496
END
9597

9698
STRINGTABLE

base/applications/network/ipconfig/lang/de-DE.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ BEGIN
9393
IDS_DHCPRELEASED "Die IP-Adresse für den Adapter %ls wurde bereits freigegeben.\n"
9494
IDS_DHCPRELEASEERROR "Beim Freigeben der Schnittstelle %ls ist folgender Fehler aufgetreten: "
9595
IDS_DHCPRENEWERROR "Beim Aktualisieren der Schnittstelle %ls ist folgender Fehler aufgetreten: "
96+
IDS_DHCPSETIDERROR "Fehler beim Festlegen der Klassenkennung für Adapter %ls: "
97+
IDS_DHCPSETIDSUCCESS "Klassenkennung für Adapter %ls festgelegt."
9698
END
9799

98100
STRINGTABLE

base/applications/network/ipconfig/lang/el-GR.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ BEGIN
9191
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
9292
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
9393
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
94+
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
95+
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
9496
END
9597

9698
STRINGTABLE

base/applications/network/ipconfig/lang/en-US.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ BEGIN
9191
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
9292
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
9393
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
94+
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
95+
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
9496
END
9597

9698
STRINGTABLE

base/applications/network/ipconfig/lang/es-ES.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ BEGIN
9292
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
9393
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
9494
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
95+
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
96+
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
9597
END
9698

9799
STRINGTABLE

base/applications/network/ipconfig/lang/fr-FR.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ BEGIN
9494
IDS_DHCPRELEASED "L'adresse IP de l'adaptateur %ls a déjà été libérée.\n"
9595
IDS_DHCPRELEASEERROR "Une erreur est survenue lors de la libération de l'interface %ls : "
9696
IDS_DHCPRENEWERROR "Une erreur est survenue lors du renouvellement de l'interface %ls : "
97+
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
98+
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
9799
END
98100

99101
STRINGTABLE

base/applications/network/ipconfig/lang/id-ID.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ BEGIN
9191
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
9292
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
9393
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
94+
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
95+
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
9496
END
9597

9698
STRINGTABLE

base/applications/network/ipconfig/lang/it-IT.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ BEGIN
9191
IDS_DHCPRELEASED "IP address for adapter %ls has already been released.\n"
9292
IDS_DHCPRELEASEERROR "An error occurred while releasing interface %ls: "
9393
IDS_DHCPRENEWERROR "An error occurred while renewing interface %ls: "
94+
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
95+
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
9496
END
9597

9698
STRINGTABLE

base/applications/network/ipconfig/lang/ja-JP.rc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ BEGIN
9191
IDS_DHCPRELEASED "アダプタ %ls に対する IP アドレス はすでに解放されています。\n"
9292
IDS_DHCPRELEASEERROR "インターフェース %ls の解放中にエラーが起きました: "
9393
IDS_DHCPRENEWERROR "インターフェース %ls の更新中にエラーが起きました: "
94+
IDS_DHCPSETIDERROR "Attempt to set the class id for adapter %ls failed: "
95+
IDS_DHCPSETIDSUCCESS "Successfully set the class id for adapter %ls.\n"
9496
END
9597

9698
STRINGTABLE

0 commit comments

Comments
 (0)