@@ -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 ;
0 commit comments