ReactOS 0.4.16-dev-1948-gd260c1d
route.c
Go to the documentation of this file.
1/* Poor man's route
2 *
3 * Supported commands:
4 *
5 * "print"
6 * "add" target ["mask" mask] gw ["metric" metric]
7 * "delete" target gw
8 *
9 * Goals:
10 *
11 * Flexible, simple
12 */
13
14#define WIN32_NO_STATUS
15#include <stdarg.h>
16#include <stdlib.h>
17#include <windef.h>
18#include <winbase.h>
19#include <winreg.h>
20#include <stdio.h>
21#include <malloc.h>
22#define _INC_WINDOWS
23#include <winsock2.h>
24#include <iphlpapi.h>
25#include <ws2tcpip.h>
26#include <ip2string.h>
27#include <conutils.h>
28
29#include "resource.h"
30
31#define IPBUF 17
32#define IN_ADDR_OF(x) *((struct in_addr *)&(x))
33
34#define DELETE_FLAG 0x1
35#define PERSISTENT_FLAG 0x2
36
37static
38BOOL
41 _In_ PWSTR Pattern)
42{
43 size_t TextLength, PatternLength, TextIndex = 0, PatternIndex = 0;
44 size_t StartIndex = -1, MatchIndex = 0;
45
46 if (Pattern == NULL)
47 return TRUE;
48
49 TextLength = wcslen(Text);
50 PatternLength = wcslen(Pattern);
51
52 while (TextIndex < TextLength)
53 {
54 if ((PatternIndex < PatternLength) &&
55 ((Pattern[PatternIndex] == L'?') ||
56 (towlower(Pattern[PatternIndex]) == towlower(Text[TextIndex]))))
57 {
58 TextIndex++;
59 PatternIndex++;
60 }
61 else if ((PatternIndex < PatternLength) &&
62 (Pattern[PatternIndex] == L'*'))
63 {
64 StartIndex = PatternIndex;
65 MatchIndex = TextIndex;
66 PatternIndex++;
67 }
68 else if (StartIndex != -1)
69 {
70 PatternIndex = StartIndex + 1;
71 MatchIndex++;
72 TextIndex = MatchIndex;
73 }
74 else
75 {
76 return FALSE;
77 }
78 }
79
80 while ((PatternIndex < PatternLength) &&
81 (Pattern[PatternIndex] == L'*'))
82 {
83 PatternIndex++;
84 }
85
86 return (PatternIndex == PatternLength);
87}
88
89static
90VOID
92 _In_ PWSTR RouteValue,
94 _Out_ PWSTR *Netmask,
95 _Out_ PWSTR *Gateway,
96 _Out_ PWSTR *Metric)
97{
98 PWSTR Ptr, DestPtr;
99
100 if (Destination)
101 *Destination = NULL;
102
103 if (Netmask)
104 *Netmask = NULL;
105
106 if (Gateway)
107 *Gateway = NULL;
108
109 if (Metric)
110 *Metric = NULL;
111
112 DestPtr = RouteValue;
113 if (Destination)
114 *Destination = DestPtr;
115
116 Ptr = wcschr(DestPtr, L',');
117 if (Ptr == NULL)
118 return;
119
120 *Ptr = L'\0';
121 Ptr++;
122
123 DestPtr = Ptr;
124 if (Netmask)
125 *Netmask = DestPtr;
126
127 Ptr = wcschr(DestPtr, L',');
128 if (Ptr == NULL)
129 return;
130
131 *Ptr = L'\0';
132 Ptr++;
133
134 DestPtr = Ptr;
135 if (Gateway)
136 *Gateway = DestPtr;
137
138 Ptr = wcschr(DestPtr, L',');
139 if (Ptr == NULL)
140 return;
141
142 *Ptr = L'\0';
143 Ptr++;
144
145 if (Metric)
146 *Metric = Ptr;
147}
148
149static
150BOOL
152 _In_ int argc,
153 _In_ WCHAR **argv,
154 _In_ int start,
156 _Out_ PWSTR *Netmask,
157 _Out_ PWSTR *Gateway,
158 _Out_ PWSTR *Metric)
159{
160 int i;
161
162 if (Destination)
163 *Destination = NULL;
164
165 if (Netmask)
166 *Netmask = NULL;
167
168 if (Gateway)
169 *Gateway = NULL;
170
171 if (Metric)
172 *Metric = NULL;
173
174 if (argc > start)
175 {
176 if (Destination)
178 }
179 else
180 return FALSE;
181
182 for (i = start + 1; i < argc; i++)
183 {
184 if (!_wcsicmp(argv[i], L"mask"))
185 {
186 i++;
187 if (i >= argc)
188 return FALSE;
189 if (Netmask)
190 *Netmask = argv[i];
191 }
192 else if (!_wcsicmp(argv[i], L"metric"))
193 {
194 i++;
195 if (i >= argc)
196 return FALSE;
197 if (Metric)
198 *Metric = argv[i];
199 }
200 else
201 {
202 if (Gateway)
203 *Gateway = argv[i];
204 }
205 }
206
207 return TRUE;
208}
209
210static
211VOID
213 _In_ PBYTE Mac,
215{
216 swprintf(Buffer, L"%02X %02X %02X %02X %02X %02X ",
217 Mac[0], Mac[1], Mac[2], Mac[3], Mac[4], Mac[5]);
218}
219
220static
221DWORD
224{
225 WCHAR szBuffer[64];
226 DWORD dwIndex = 0, dwBufferSize;
227 BOOL EntriesFound = FALSE;
228 HKEY hKey;
230 PWSTR Destination, Netmask, Gateway, Metric;
231
234
236 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\PersistentRoutes",
237 0,
238 KEY_READ,
239 &hKey);
240 if (Error == ERROR_SUCCESS)
241 {
242 for (;;)
243 {
244 dwBufferSize = 64;
245
247 dwIndex,
248 szBuffer,
249 &dwBufferSize,
250 NULL,
251 NULL,
252 NULL,
253 NULL);
254 if (Error != ERROR_SUCCESS)
255 {
258
259 break;
260 }
261
264 &Netmask,
265 &Gateway,
266 &Metric);
267
269 {
270 if (EntriesFound == FALSE)
272 ConResPrintf(StdOut, IDS_PERSISTENT_ENTRY, Destination, Netmask, Gateway, Metric);
273 EntriesFound = TRUE;
274 }
275
276 dwIndex++;
277 }
278
280 }
281
282 if (EntriesFound == FALSE)
284
285 return Error;
286}
287
288static
289VOID
292 _In_ PIP_ADAPTER_UNICAST_ADDRESS UnicastAddress,
293 _In_ DWORD IfIndex)
294{
295 PIP_ADAPTER_UNICAST_ADDRESS Ptr = UnicastAddress;
296
297 while (Ptr)
298 {
299 if (Ptr->Address.lpSockaddr->sa_family == AF_INET)
300 {
301 struct sockaddr_in *si = (struct sockaddr_in *)(Ptr->Address.lpSockaddr);
303 return;
304 }
305
306 Ptr = Ptr->Next;
307 }
308
309 swprintf(pBuffer, L"%lx", IfIndex);
310}
311
312static
313VOID
316 _In_ PIP_ADAPTER_ADDRESSES pAdapterAddresses,
317 _In_ DWORD IfIndex)
318{
319 PIP_ADAPTER_ADDRESSES Ptr = pAdapterAddresses;
320
321 while (Ptr)
322 {
323 if (Ptr->IfIndex == IfIndex)
324 {
325 FormatIPv4Address(pBuffer, Ptr->FirstUnicastAddress, Ptr->IfIndex);
326 return;
327 }
328
329 Ptr = Ptr->Next;
330 }
331
332 swprintf(pBuffer, L"%lx", IfIndex);
333}
334
335static
336int
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
344static
345DWORD
347 _In_ PWSTR DestinationPattern)
348{
349 PMIB_IPFORWARDTABLE IpForwardTable = NULL;
350 PIP_ADAPTER_ADDRESSES pAdapterAddresses = NULL, Ptr, *pAdapterSortArray = NULL;
351 ULONG Size = 0;
353 ULONG adaptOutBufLen = 15000;
354 WCHAR Destination[IPBUF], Gateway[IPBUF], Netmask[IPBUF], Interface[IPBUF];
355 unsigned int i, AdapterCount, AdapterIndex;
356 BOOL EntriesFound;
357 ULONG Flags = /*GAA_FLAG_SKIP_UNICAST |*/ GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
358 GAA_FLAG_SKIP_DNS_SERVER;
359
360 /* set required buffer size */
361 pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)malloc(adaptOutBufLen);
362 if (pAdapterAddresses == NULL)
363 {
365 goto Error;
366 }
367
368 if (GetAdaptersAddresses(AF_INET, Flags, NULL, pAdapterAddresses, &adaptOutBufLen) == ERROR_BUFFER_OVERFLOW)
369 {
370 free(pAdapterAddresses);
371 pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)malloc(adaptOutBufLen);
372 if (pAdapterAddresses == NULL)
373 {
375 goto Error;
376 }
377 }
378
380 {
381 if (!(IpForwardTable = malloc(Size)))
382 {
384 goto Error;
385 }
386 }
387
388 if (((Error = GetAdaptersAddresses(AF_INET, Flags, NULL, pAdapterAddresses, &adaptOutBufLen)) == NO_ERROR) &&
389 ((Error = GetIpForwardTable(IpForwardTable, &Size, TRUE)) == NO_ERROR))
390 {
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 {
406 goto Error;
407 }
408
409 AdapterIndex = 0;
410 Ptr = pAdapterAddresses;
411 while (Ptr)
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];
423 if (Ptr->IfType == IF_TYPE_ETHERNET_CSMACD)
424 {
426 PrintMacAddress(Ptr->PhysicalAddress, PhysicalAddress);
427 ConResPrintf(StdOut, IDS_ETHERNET_ENTRY, Ptr->IfIndex, PhysicalAddress, Ptr->Description);
428 }
429 else
430 {
431 ConResPrintf(StdOut, IDS_INTERFACE_ENTRY, Ptr->IfIndex, Ptr->Description);
432 }
433 }
435
439 EntriesFound = FALSE;
440 for (i = 0; i < IpForwardTable->dwNumEntries; i++)
441 {
443 mbstowcs(Netmask, inet_ntoa(IN_ADDR_OF(IpForwardTable->table[i].dwForwardMask)), IPBUF);
444 mbstowcs(Gateway, inet_ntoa(IN_ADDR_OF(IpForwardTable->table[i].dwForwardNextHop)), IPBUF);
445 GetFirstIPv4AddressFromIndex(Interface, pAdapterAddresses, IpForwardTable->table[i].dwForwardIfIndex);
446
447 if (MatchWildcard(Destination, DestinationPattern))
448 {
449 if (EntriesFound == FALSE)
453 Netmask,
454 Gateway,
455 Interface,
456 IpForwardTable->table[i].dwForwardMetric1);
457 EntriesFound = TRUE;
458 }
459 }
460
461 if (DestinationPattern == NULL)
462 {
463 for (i = 0; i < IpForwardTable->dwNumEntries; i++)
464 {
465 if (IpForwardTable->table[i].dwForwardDest == 0)
466 {
467 mbstowcs(Gateway, inet_ntoa(IN_ADDR_OF(IpForwardTable->table[i].dwForwardNextHop)), IPBUF);
469 }
470 }
471 }
472 else if (EntriesFound == FALSE)
474 }
475
476Error:
477 if (pAdapterSortArray)
478 free(pAdapterSortArray);
479 if (pAdapterAddresses)
480 free(pAdapterAddresses);
481 if (IpForwardTable)
482 free(IpForwardTable);
483
484 if (Error != ERROR_SUCCESS)
486
487 return Error;
488}
489
490static
491int
493 _In_ int argc,
494 _In_ WCHAR **argv,
495 _In_ int start,
496 _In_ int flags)
497{
498 PWSTR DestinationPattern = NULL;
499 DWORD Error;
500
501 if (argc > start)
503 &DestinationPattern, NULL, NULL, NULL);
504
505 Error = PrintActiveRoutes(DestinationPattern);
506 if (Error == ERROR_SUCCESS)
507 Error = PrintPersistentRoutes(DestinationPattern);
508
509 return (Error == ERROR_SUCCESS) ? 0 : 2;
510}
511
512static
513BOOL
515 _Out_ PMIB_IPFORWARDROW RowToAdd,
516 _In_ int argc,
517 _In_ WCHAR **argv,
518 _In_ int start)
519{
520 int i;
521 char addr[16];
522
523 if (argc > start)
524 {
525 wcstombs(addr, argv[start], 16);
526 RowToAdd->dwForwardDest = inet_addr(addr);
527 }
528 else
529 return FALSE;
530
531 for (i = start + 1; i < argc; i++)
532 {
533 if (!_wcsicmp(argv[i], L"mask"))
534 {
535 i++;
536 if (i >= argc)
537 return FALSE;
538 wcstombs(addr, argv[i], 16);
539 RowToAdd->dwForwardMask = inet_addr(addr);
540 }
541 else if (!_wcsicmp(argv[i], L"metric"))
542 {
543 i++;
544 if (i >= argc)
545 return FALSE;
546 RowToAdd->dwForwardMetric1 = _wtoi(argv[i]);
547 }
548 else
549 {
550 wcstombs(addr, argv[i], 16);
551 RowToAdd->dwForwardNextHop = inet_addr(addr);
552 }
553 }
554
555 /* Restrict metric value to range 1 to 9999 */
556 if (RowToAdd->dwForwardMetric1 == 0)
557 RowToAdd->dwForwardMetric1 = 1;
558 else if (RowToAdd->dwForwardMetric1 > 9999)
559 RowToAdd->dwForwardMetric1 = 9999;
560
561 return TRUE;
562}
563
564static
565DWORD
567 _In_ PMIB_IPFORWARDROW RowToAdd)
568{
569 WCHAR Destination[IPBUF], Gateway[IPBUF], Netmask[IPBUF];
570 WCHAR ValueName[64];
571 HKEY hKey;
573
574 mbstowcs(Destination, inet_ntoa(IN_ADDR_OF(RowToAdd->dwForwardDest)), IPBUF);
575 mbstowcs(Netmask, inet_ntoa(IN_ADDR_OF(RowToAdd->dwForwardMask)), IPBUF);
576 mbstowcs(Gateway, inet_ntoa(IN_ADDR_OF(RowToAdd->dwForwardNextHop)), IPBUF);
577
578 swprintf(ValueName, L"%s,%s,%s,%ld", Destination, Netmask, Gateway, RowToAdd->dwForwardMetric1);
579
581 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\PersistentRoutes",
582 0,
583 NULL,
585 KEY_WRITE,
586 NULL,
587 &hKey,
588 NULL);
589 if (Error == ERROR_SUCCESS)
590 {
592 ValueName,
593 0,
594 REG_SZ,
595 (LPBYTE)L"",
596 sizeof(WCHAR));
597
599 }
600
601 return Error;
602}
603
604static
605DWORD
607{
608 WCHAR Destination[IPBUF], Netmask[IPBUF];
609 PMIB_IPFORWARDTABLE IpForwardTable = NULL;
610 ULONG Size = 0;
612 ULONG i;
613
615 {
616 if (!(IpForwardTable = malloc(Size)))
617 {
619 goto done;
620 }
621 }
622
623 Error = GetIpForwardTable(IpForwardTable, &Size, TRUE);
624 if (Error != ERROR_SUCCESS)
625 goto done;
626
627 for (i = 0; i < IpForwardTable->dwNumEntries; i++)
628 {
630 mbstowcs(Netmask, inet_ntoa(IN_ADDR_OF(IpForwardTable->table[i].dwForwardMask)), IPBUF);
631
632 if ((wcscmp(Netmask, L"255.255.255.255") != 0) &&
633 ((wcscmp(Destination, L"127.0.0.0") != 0) || (wcscmp(Netmask, L"255.0.0.0") != 0)) &&
634 ((wcscmp(Destination, L"224.0.0.0") != 0) || (wcscmp(Netmask, L"240.0.0.0") != 0)))
635 {
636 Error = DeleteIpForwardEntry(&IpForwardTable->table[i]);
637 if (Error != ERROR_SUCCESS)
638 break;
639 }
640 }
641
642done:
643 if (IpForwardTable)
644 free(IpForwardTable);
645
646 return Error;
647}
648
649static
650int
652 _In_ int argc,
653 _In_ WCHAR **argv,
654 _In_ int start,
655 _In_ int flags)
656{
657 MIB_IPFORWARDROW RowToAdd = { 0 };
658 DWORD Error;
659
660 if ((argc <= start) || !ConvertAddCmdLine(&RowToAdd, argc, argv, start))
661 return 1;
662
663 if (flags & DELETE_FLAG)
665
668 else
669 Error = CreateIpForwardEntry(&RowToAdd);
670 if (Error != ERROR_SUCCESS)
671 {
673 return 2;
674 }
675
676 return 0;
677}
678
679static
680DWORD
682 PWSTR DestinationPattern)
683{
684 WCHAR Destination[IPBUF], Netmask[IPBUF];
685 PMIB_IPFORWARDTABLE IpForwardTable = NULL;
686 ULONG Size = 0;
688 ULONG i;
689
691 {
692 if (!(IpForwardTable = malloc(Size)))
693 {
695 goto done;
696 }
697 }
698
699 Error = GetIpForwardTable(IpForwardTable, &Size, TRUE);
700 if (Error != ERROR_SUCCESS)
701 goto done;
702
703 for (i = 0; i < IpForwardTable->dwNumEntries; i++)
704 {
706 mbstowcs(Netmask, inet_ntoa(IN_ADDR_OF(IpForwardTable->table[i].dwForwardMask)), IPBUF);
707
708 if (MatchWildcard(Destination, DestinationPattern))
709 {
710 Error = DeleteIpForwardEntry(&IpForwardTable->table[i]);
711 if (Error != ERROR_SUCCESS)
712 break;
713 }
714 }
715
716done:
717 if (IpForwardTable)
718 free(IpForwardTable);
719
720 return Error;
721}
722
723static
724DWORD
726 PWSTR DestinationPattern)
727{
728
729 WCHAR szBuffer[64];
730 DWORD dwIndex = 0, dwBufferSize;
731 HKEY hKey;
734
736 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\PersistentRoutes",
737 0,
738 KEY_READ,
739 &hKey);
740 if (Error == ERROR_SUCCESS)
741 {
742 for (;;)
743 {
744 dwBufferSize = 64;
745
747 dwIndex,
748 szBuffer,
749 &dwBufferSize,
750 NULL,
751 NULL,
752 NULL,
753 NULL);
754 if (Error != ERROR_SUCCESS)
755 {
758
759 break;
760 }
761
764 NULL,
765 NULL,
766 NULL);
767
768 if (MatchWildcard(Destination, DestinationPattern))
769 {
770 Error = RegDeleteValueW(hKey, szBuffer);
771 if (Error != ERROR_SUCCESS)
772 break;
773 }
774
775 dwIndex++;
776 }
777
779 }
780
781 return Error;
782}
783
784static int
786 _In_ int argc,
787 _In_ WCHAR **argv,
788 _In_ int start,
789 _In_ int flags)
790{
791 PWSTR DestinationPattern = NULL;
792 DWORD Error;
793
794 if ((argc <= start) ||
796 &DestinationPattern, NULL, NULL, NULL))
797 return 1;
798
799 if (flags & DELETE_FLAG)
801
802 Error = DeleteActiveRoutes(DestinationPattern);
803 if (Error == ERROR_SUCCESS)
804 Error = DeletePersistentRoutes(DestinationPattern);
805
806 if (Error != ERROR_SUCCESS)
807 {
809 return 2;
810 }
811
812 return 0;
813}
814
815int
817 _In_ int argc,
818 _In_ WCHAR **argv)
819{
820 int i, flags = 0, ret = 0;
821
822 /* Initialize the Console Standard Streams */
824
825 for (i = 1; i < argc; i++)
826 {
827 if (argv[i][0] == L'-' || argv[i][0] == L'/')
828 {
829 if (!_wcsicmp(&argv[i][1], L"f"))
830 {
832 }
833 else if (!_wcsicmp(&argv[i][1], L"p"))
834 {
836 }
837 else
838 {
839 ret = 1;
840 break;
841 }
842 }
843 else
844 {
845 if (!_wcsicmp(argv[i], L"print"))
846 ret = PrintRoutes(argc, argv, i + 1, flags);
847 else if (!_wcsicmp(argv[i], L"add"))
848 ret = AddRoute(argc, argv, i + 1, flags);
849 else if (!_wcsicmp(argv[i], L"delete"))
850 ret = DeleteRoutes(argc, argv, i + 1, flags);
851 else
852 ret = 1;
853
854 break;
855 }
856 }
857
858 if (argc == 1)
859 ret = 1;
860
861 if (ret == 1)
862 {
864// ConResPrintf(StdErr, IDS_USAGE2);
866 }
867
868 return (ret == 0) ? 0 : 1;
869}
static int argc
Definition: ServiceArgs.c:12
CHAR FAR *WSAAPI inet_ntoa(IN IN_ADDR in)
Definition: addrconv.c:160
ULONG WSAAPI inet_addr(IN CONST CHAR FAR *cp)
Definition: addrconv.c:71
#define ConInitStdStreams()
Definition: fc.c:13
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define StdErr
Definition: fc.c:15
#define IDS_NONE
Definition: resource.h:144
#define IDS_USAGE3
Definition: resource.h:5
#define IDS_ROUTE_ADD_ERROR
Definition: resource.h:6
#define IDS_INTERFACE_LIST
Definition: resource.h:10
#define IDS_INTERFACE_ENTRY
Definition: resource.h:11
#define IDS_ETHERNET_ENTRY
Definition: resource.h:12
#define IDS_IPV4_ROUTE_TABLE
Definition: resource.h:13
#define IDS_ROUTE_DEL_ERROR
Definition: resource.h:7
#define IDS_ACTIVE_ROUTES
Definition: resource.h:14
#define IDS_ROUTES_ENTRY
Definition: resource.h:17
#define IDS_USAGE1
Definition: resource.h:3
#define IDS_PERSISTENT_ROUTES
Definition: resource.h:15
#define IDS_PERSISTENT_HEADER
Definition: resource.h:20
#define IDS_SEPARATOR
Definition: resource.h:9
#define IDS_DEFAULT_GATEWAY
Definition: resource.h:18
#define IDS_ROUTES_HEADER
Definition: resource.h:19
#define IDS_PERSISTENT_ENTRY
Definition: resource.h:16
#define IDS_ROUTE_ENUM_ERROR
Definition: resource.h:8
static DWORD DeleteCustomRoutes(VOID)
Definition: route.c:606
static int AddRoute(_In_ int argc, _In_ WCHAR **argv, _In_ int start, _In_ int flags)
Definition: route.c:651
#define DELETE_FLAG
Definition: route.c:34
static VOID PrintMacAddress(_In_ PBYTE Mac, _In_ PWSTR Buffer)
Definition: route.c:212
static BOOL ParseCmdLine(_In_ int argc, _In_ WCHAR **argv, _In_ int start, _Out_ PWSTR *Destination, _Out_ PWSTR *Netmask, _Out_ PWSTR *Gateway, _Out_ PWSTR *Metric)
Definition: route.c:151
static int PrintRoutes(_In_ int argc, _In_ WCHAR **argv, _In_ int start, _In_ int flags)
Definition: route.c:492
static DWORD DeleteActiveRoutes(PWSTR DestinationPattern)
Definition: route.c:681
static DWORD PrintActiveRoutes(_In_ PWSTR DestinationPattern)
Definition: route.c:346
static DWORD PrintPersistentRoutes(_In_ PWSTR Filter)
Definition: route.c:222
static BOOL ConvertAddCmdLine(_Out_ PMIB_IPFORWARDROW RowToAdd, _In_ int argc, _In_ WCHAR **argv, _In_ int start)
Definition: route.c:514
static int DeleteRoutes(_In_ int argc, _In_ WCHAR **argv, _In_ int start, _In_ int flags)
Definition: route.c:785
static DWORD CreatePersistentIpForwardEntry(_In_ PMIB_IPFORWARDROW RowToAdd)
Definition: route.c:566
#define PERSISTENT_FLAG
Definition: route.c:35
static DWORD DeletePersistentRoutes(PWSTR DestinationPattern)
Definition: route.c:725
static VOID FormatIPv4Address(_Out_ PWCHAR pBuffer, _In_ PIP_ADAPTER_UNICAST_ADDRESS UnicastAddress, _In_ DWORD IfIndex)
Definition: route.c:290
static int CompareAdapters(_In_ const void *elem1, _In_ const void *elem2)
Definition: route.c:337
static BOOL MatchWildcard(_In_ PWSTR Text, _In_ PWSTR Pattern)
Definition: route.c:39
#define IPBUF
Definition: route.c:31
static VOID GetFirstIPv4AddressFromIndex(_Out_ PWSTR pBuffer, _In_ PIP_ADAPTER_ADDRESSES pAdapterAddresses, _In_ DWORD IfIndex)
Definition: route.c:314
static VOID ParsePersistentRouteValue(_In_ PWSTR RouteValue, _Out_ PWSTR *Destination, _Out_ PWSTR *Netmask, _Out_ PWSTR *Gateway, _Out_ PWSTR *Metric)
Definition: route.c:91
#define IN_ADDR_OF(x)
Definition: route.c:32
BOOL Error
Definition: chkdsk.c:66
#define RegCloseKey(hKey)
Definition: registry.h:49
Definition: bufpool.h:45
char * Text
Definition: combotst.c:136
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegCreateKeyExW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey, _In_ DWORD Reserved, _In_opt_ LPWSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_opt_ LPDWORD lpdwDisposition)
Definition: reg.c:1096
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
Definition: reg.c:2330
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2830
#define wcschr
Definition: compat.h:17
#define ERROR_NO_MORE_ITEMS
Definition: compat.h:105
#define swprintf
Definition: precomp.h:40
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
#define AF_INET
Definition: tcpip.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_opt_ PFLT_FILTER Filter
Definition: fltkernel.h:1801
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
FxAutoRegKey hKey
GLuint start
Definition: gl.h:1545
GLbitfield flags
Definition: glext.h:7161
GLenum const GLvoid * addr
Definition: glext.h:9621
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder)
DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute)
DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute)
#define IF_TYPE_ETHERNET_CSMACD
Definition: ipifcons.h:26
#define REG_SZ
Definition: layer.c:22
#define argv
Definition: mplay32.c:18
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:3051
NTSYSAPI PWSTR NTAPI RtlIpv4AddressToStringW(_In_ const struct in_addr *Addr, _Out_writes_(16) PWCHAR S)
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define KEY_READ
Definition: nt_native.h:1026
#define REG_OPTION_NON_VOLATILE
Definition: nt_native.h:1060
#define KEY_WRITE
Definition: nt_native.h:1034
BYTE * PBYTE
Definition: pedump.c:66
PVOID pBuffer
int wmain()
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
wcstombs
Definition: stdlib.h:1013
mbstowcs
Definition: stdlib.h:925
DWORD dwForwardNextHop
Definition: ipmib.h:74
DWORD dwForwardMetric1
Definition: ipmib.h:88
IF_INDEX dwForwardIfIndex
Definition: ipmib.h:75
DWORD dwForwardDest
Definition: ipmib.h:71
DWORD dwForwardMask
Definition: ipmib.h:72
DWORD dwNumEntries
Definition: ipmib.h:97
MIB_IPFORWARDROW table[1]
Definition: ipmib.h:98
struct in_addr sin_addr
Definition: winsock.h:506
#define towlower(c)
Definition: wctype.h:97
uint16_t * PWSTR
Definition: typedefs.h:56
unsigned char * LPBYTE
Definition: typedefs.h:53
uint16_t * PWCHAR
Definition: typedefs.h:56
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:307
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegSetValueEx
Definition: winreg.h:540
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress
Definition: iotypes.h:1098
__wchar_t WCHAR
Definition: xmlstorage.h:180