14#define WIN32_NO_STATUS
32#define IN_ADDR_OF(x) *((struct in_addr *)&(x))
34#define DELETE_FLAG 0x1
35#define PERSISTENT_FLAG 0x2
43 size_t TextLength, PatternLength, TextIndex = 0, PatternIndex = 0;
44 size_t StartIndex = -1, MatchIndex = 0;
50 PatternLength =
wcslen(Pattern);
52 while (TextIndex < TextLength)
54 if ((PatternIndex < PatternLength) &&
55 ((Pattern[PatternIndex] ==
L'?') ||
61 else if ((PatternIndex < PatternLength) &&
62 (Pattern[PatternIndex] ==
L'*'))
64 StartIndex = PatternIndex;
65 MatchIndex = TextIndex;
68 else if (StartIndex != -1)
70 PatternIndex = StartIndex + 1;
72 TextIndex = MatchIndex;
80 while ((PatternIndex < PatternLength) &&
81 (Pattern[PatternIndex] ==
L'*'))
86 return (PatternIndex == PatternLength);
112 DestPtr = RouteValue;
217 Mac[0], Mac[1], Mac[2], Mac[3], Mac[4], Mac[5]);
226 DWORD dwIndex = 0, dwBufferSize;
236 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\PersistentRoutes",
270 if (EntriesFound ==
FALSE)
282 if (EntriesFound ==
FALSE)
292 _In_ PIP_ADAPTER_UNICAST_ADDRESS UnicastAddress,
295 PIP_ADAPTER_UNICAST_ADDRESS
Ptr = UnicastAddress;
299 if (
Ptr->Address.lpSockaddr->sa_family ==
AF_INET)
316 _In_ PIP_ADAPTER_ADDRESSES pAdapterAddresses,
319 PIP_ADAPTER_ADDRESSES
Ptr = pAdapterAddresses;
323 if (
Ptr->IfIndex == IfIndex)
338 _In_ const void *elem1,
339 _In_ const void *elem2)
341 return ((PIP_ADAPTER_ADDRESSES)elem2)->IfIndex - ((PIP_ADAPTER_ADDRESSES)elem1)->IfIndex;
350 PIP_ADAPTER_ADDRESSES pAdapterAddresses =
NULL,
Ptr, *pAdapterSortArray =
NULL;
353 ULONG adaptOutBufLen = 15000;
355 unsigned int i, AdapterCount, AdapterIndex;
357 ULONG Flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
358 GAA_FLAG_SKIP_DNS_SERVER;
361 pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)
malloc(adaptOutBufLen);
362 if (pAdapterAddresses ==
NULL)
370 free(pAdapterAddresses);
371 pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)
malloc(adaptOutBufLen);
372 if (pAdapterAddresses ==
NULL)
395 Ptr = pAdapterAddresses;
402 pAdapterSortArray = (PIP_ADAPTER_ADDRESSES*)
malloc(AdapterCount *
sizeof(
PVOID));
403 if (pAdapterSortArray ==
NULL)
410 Ptr = pAdapterAddresses;
413 pAdapterSortArray[AdapterIndex] =
Ptr;
420 for (AdapterIndex = 0; AdapterIndex < AdapterCount; AdapterIndex++)
422 Ptr = pAdapterSortArray[AdapterIndex];
439 EntriesFound =
FALSE;
449 if (EntriesFound ==
FALSE)
461 if (DestinationPattern ==
NULL)
472 else if (EntriesFound ==
FALSE)
477 if (pAdapterSortArray)
478 free(pAdapterSortArray);
479 if (pAdapterAddresses)
480 free(pAdapterAddresses);
482 free(IpForwardTable);
556 if (RowToAdd->dwForwardMetric1 == 0)
557 RowToAdd->dwForwardMetric1 = 1;
558 else if (RowToAdd->dwForwardMetric1 > 9999)
559 RowToAdd->dwForwardMetric1 = 9999;
581 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\PersistentRoutes",
632 if ((
wcscmp(Netmask,
L"255.255.255.255") != 0) &&
644 free(IpForwardTable);
682 PWSTR DestinationPattern)
718 free(IpForwardTable);
726 PWSTR DestinationPattern)
730 DWORD dwIndex = 0, dwBufferSize;
736 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\PersistentRoutes",
868 return (
ret == 0) ? 0 : 1;
CHAR FAR *WSAAPI inet_ntoa(IN IN_ADDR in)
ULONG WSAAPI inet_addr(IN CONST CHAR FAR *cp)
#define ConInitStdStreams()
void ConResPrintf(FILE *fp, UINT nID,...)
#define IDS_ROUTE_ADD_ERROR
#define IDS_INTERFACE_LIST
#define IDS_INTERFACE_ENTRY
#define IDS_ETHERNET_ENTRY
#define IDS_IPV4_ROUTE_TABLE
#define IDS_ROUTE_DEL_ERROR
#define IDS_ACTIVE_ROUTES
#define IDS_PERSISTENT_ROUTES
#define IDS_PERSISTENT_HEADER
#define IDS_DEFAULT_GATEWAY
#define IDS_ROUTES_HEADER
#define IDS_PERSISTENT_ENTRY
#define IDS_ROUTE_ENUM_ERROR
static DWORD DeleteCustomRoutes(VOID)
static int AddRoute(_In_ int argc, _In_ WCHAR **argv, _In_ int start, _In_ int flags)
static VOID PrintMacAddress(_In_ PBYTE Mac, _In_ PWSTR Buffer)
static BOOL ParseCmdLine(_In_ int argc, _In_ WCHAR **argv, _In_ int start, _Out_ PWSTR *Destination, _Out_ PWSTR *Netmask, _Out_ PWSTR *Gateway, _Out_ PWSTR *Metric)
static int PrintRoutes(_In_ int argc, _In_ WCHAR **argv, _In_ int start, _In_ int flags)
static DWORD DeleteActiveRoutes(PWSTR DestinationPattern)
static DWORD PrintActiveRoutes(_In_ PWSTR DestinationPattern)
static DWORD PrintPersistentRoutes(_In_ PWSTR Filter)
static BOOL ConvertAddCmdLine(_Out_ PMIB_IPFORWARDROW RowToAdd, _In_ int argc, _In_ WCHAR **argv, _In_ int start)
static int DeleteRoutes(_In_ int argc, _In_ WCHAR **argv, _In_ int start, _In_ int flags)
static DWORD CreatePersistentIpForwardEntry(_In_ PMIB_IPFORWARDROW RowToAdd)
static DWORD DeletePersistentRoutes(PWSTR DestinationPattern)
static VOID FormatIPv4Address(_Out_ PWCHAR pBuffer, _In_ PIP_ADAPTER_UNICAST_ADDRESS UnicastAddress, _In_ DWORD IfIndex)
static int CompareAdapters(_In_ const void *elem1, _In_ const void *elem2)
static BOOL MatchWildcard(_In_ PWSTR Text, _In_ PWSTR Pattern)
static VOID GetFirstIPv4AddressFromIndex(_Out_ PWSTR pBuffer, _In_ PIP_ADAPTER_ADDRESSES pAdapterAddresses, _In_ DWORD IfIndex)
static VOID ParsePersistentRouteValue(_In_ PWSTR RouteValue, _Out_ PWSTR *Destination, _Out_ PWSTR *Netmask, _Out_ PWSTR *Gateway, _Out_ PWSTR *Metric)
#define RegCloseKey(hKey)
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
#define ERROR_INSUFFICIENT_BUFFER
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)
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
LONG WINAPI RegDeleteValueW(HKEY hKey, LPCWSTR lpValueName)
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)
#define ERROR_NO_MORE_ITEMS
_Must_inspect_result_ _In_opt_ PFLT_FILTER Filter
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
GLenum const GLvoid * addr
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
_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
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
NTSYSAPI PWSTR NTAPI RtlIpv4AddressToStringW(_In_ const struct in_addr *Addr, _Out_writes_(16) PWCHAR S)
#define REG_OPTION_NON_VOLATILE
_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)
IF_INDEX dwForwardIfIndex
MIB_IPFORWARDROW table[1]
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
#define ERROR_BUFFER_OVERFLOW
#define HKEY_LOCAL_MACHINE
_Must_inspect_result_ _In_ ULONG Flags
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS PhysicalAddress