tangled
alpha
login
or
join now
huwcampbell.com
/
reactos
0
fork
atom
Reactos
0
fork
atom
overview
issues
pulls
pipelines
[ROUTE] Sort network interfaces by index
Eric Kohl
7 months ago
fc84d686
05caf999
+40
-5
1 changed file
expand all
collapse all
unified
split
base
applications
network
route
route.c
+40
-5
base/applications/network/route/route.c
reviewed
···
333
333
}
334
334
335
335
static
336
336
+
int
337
337
+
CompareAdapters(
338
338
+
_In_ const void *elem1,
339
339
+
_In_ const void *elem2)
340
340
+
{
341
341
+
return ((PIP_ADAPTER_ADDRESSES)elem2)->IfIndex - ((PIP_ADAPTER_ADDRESSES)elem1)->IfIndex;
342
342
+
}
343
343
+
344
344
+
static
336
345
DWORD
337
346
PrintActiveRoutes(
338
347
_In_ PWSTR DestinationPattern)
339
348
{
340
349
PMIB_IPFORWARDTABLE IpForwardTable = NULL;
341
341
-
PIP_ADAPTER_ADDRESSES pAdapterAddresses = NULL, Ptr;
350
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
346
-
unsigned int i;
355
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
384
-
/* FIXME - sort by the index! */
393
393
+
394
394
+
AdapterCount = 0;
395
395
+
Ptr = pAdapterAddresses;
396
396
+
while (Ptr)
397
397
+
{
398
398
+
AdapterCount++;
399
399
+
Ptr = Ptr->Next;
400
400
+
}
401
401
+
402
402
+
pAdapterSortArray = (PIP_ADAPTER_ADDRESSES*)malloc(AdapterCount * sizeof(PVOID));
403
403
+
if (pAdapterSortArray == NULL)
404
404
+
{
405
405
+
Error = ERROR_NOT_ENOUGH_MEMORY;
406
406
+
goto Error;
407
407
+
}
408
408
+
409
409
+
AdapterIndex = 0;
385
410
Ptr = pAdapterAddresses;
386
411
while (Ptr)
387
412
{
413
413
+
pAdapterSortArray[AdapterIndex] = Ptr;
414
414
+
AdapterIndex++;
415
415
+
Ptr = Ptr->Next;
416
416
+
}
417
417
+
418
418
+
qsort(pAdapterSortArray, AdapterCount, sizeof(PVOID), CompareAdapters);
419
419
+
420
420
+
for (AdapterIndex = 0; AdapterIndex < AdapterCount; AdapterIndex++)
421
421
+
{
422
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
398
-
399
399
-
Ptr = Ptr->Next;
400
433
}
401
434
ConResPrintf(StdOut, IDS_SEPARATOR);
402
435
···
441
474
}
442
475
443
476
Error:
477
477
+
if (pAdapterSortArray)
478
478
+
free(pAdapterSortArray);
444
479
if (pAdapterAddresses)
445
480
free(pAdapterAddresses);
446
481
if (IpForwardTable)