Reactos

[ROUTE] Sort network interfaces by index

Eric Kohl fc84d686 05caf999

+40 -5
+40 -5
base/applications/network/route/route.c
··· 333 333 } 334 334 335 335 static 336 + int 337 + CompareAdapters( 338 + _In_ const void *elem1, 339 + _In_ const void *elem2) 340 + { 341 + return ((PIP_ADAPTER_ADDRESSES)elem2)->IfIndex - ((PIP_ADAPTER_ADDRESSES)elem1)->IfIndex; 342 + } 343 + 344 + static 336 345 DWORD 337 346 PrintActiveRoutes( 338 347 _In_ PWSTR DestinationPattern) 339 348 { 340 349 PMIB_IPFORWARDTABLE IpForwardTable = NULL; 341 - PIP_ADAPTER_ADDRESSES pAdapterAddresses = NULL, Ptr; 350 + PIP_ADAPTER_ADDRESSES pAdapterAddresses = NULL, Ptr, *pAdapterSortArray = NULL; 342 351 ULONG Size = 0; 343 352 DWORD Error = ERROR_SUCCESS; 344 353 ULONG adaptOutBufLen = 15000; 345 354 WCHAR Destination[IPBUF], Gateway[IPBUF], Netmask[IPBUF], Interface[IPBUF]; 346 - unsigned int i; 355 + unsigned int i, AdapterCount, AdapterIndex; 347 356 BOOL EntriesFound; 348 357 ULONG Flags = /*GAA_FLAG_SKIP_UNICAST |*/ GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | 349 358 GAA_FLAG_SKIP_DNS_SERVER; ··· 381 390 { 382 391 ConResPrintf(StdOut, IDS_SEPARATOR); 383 392 ConResPrintf(StdOut, IDS_INTERFACE_LIST); 384 - /* FIXME - sort by the index! */ 393 + 394 + AdapterCount = 0; 395 + Ptr = pAdapterAddresses; 396 + while (Ptr) 397 + { 398 + AdapterCount++; 399 + Ptr = Ptr->Next; 400 + } 401 + 402 + pAdapterSortArray = (PIP_ADAPTER_ADDRESSES*)malloc(AdapterCount * sizeof(PVOID)); 403 + if (pAdapterSortArray == NULL) 404 + { 405 + Error = ERROR_NOT_ENOUGH_MEMORY; 406 + goto Error; 407 + } 408 + 409 + AdapterIndex = 0; 385 410 Ptr = pAdapterAddresses; 386 411 while (Ptr) 387 412 { 413 + pAdapterSortArray[AdapterIndex] = Ptr; 414 + AdapterIndex++; 415 + Ptr = Ptr->Next; 416 + } 417 + 418 + qsort(pAdapterSortArray, AdapterCount, sizeof(PVOID), CompareAdapters); 419 + 420 + for (AdapterIndex = 0; AdapterIndex < AdapterCount; AdapterIndex++) 421 + { 422 + Ptr = pAdapterSortArray[AdapterIndex]; 388 423 if (Ptr->IfType == IF_TYPE_ETHERNET_CSMACD) 389 424 { 390 425 WCHAR PhysicalAddress[20]; ··· 395 430 { 396 431 ConResPrintf(StdOut, IDS_INTERFACE_ENTRY, Ptr->IfIndex, Ptr->Description); 397 432 } 398 - 399 - Ptr = Ptr->Next; 400 433 } 401 434 ConResPrintf(StdOut, IDS_SEPARATOR); 402 435 ··· 441 474 } 442 475 443 476 Error: 477 + if (pAdapterSortArray) 478 + free(pAdapterSortArray); 444 479 if (pAdapterAddresses) 445 480 free(pAdapterAddresses); 446 481 if (IpForwardTable)