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)
319 _In_ PIP_ADAPTER_ADDRESSES pAdapterAddresses,
322 PIP_ADAPTER_ADDRESSES
Ptr = pAdapterAddresses;
326 if (
Ptr->IfIndex == IfIndex)
341 _In_ const void *elem1,
342 _In_ const void *elem2)
344 return ((PIP_ADAPTER_ADDRESSES)elem2)->IfIndex - ((PIP_ADAPTER_ADDRESSES)elem1)->IfIndex;
353 PIP_ADAPTER_ADDRESSES pAdapterAddresses =
NULL,
Ptr, *pAdapterSortArray =
NULL;
356 ULONG adaptOutBufLen = 15000;
358 unsigned int i, AdapterCount, AdapterIndex;
360 ULONG Flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST |
361 GAA_FLAG_SKIP_DNS_SERVER;
364 pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)
malloc(adaptOutBufLen);
365 if (pAdapterAddresses ==
NULL)
373 free(pAdapterAddresses);
374 pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)
malloc(adaptOutBufLen);
375 if (pAdapterAddresses ==
NULL)
398 Ptr = pAdapterAddresses;
405 pAdapterSortArray = (PIP_ADAPTER_ADDRESSES*)
malloc(AdapterCount *
sizeof(
PVOID));
406 if (pAdapterSortArray ==
NULL)
413 Ptr = pAdapterAddresses;
416 pAdapterSortArray[AdapterIndex] =
Ptr;
423 for (AdapterIndex = 0; AdapterIndex < AdapterCount; AdapterIndex++)
425 Ptr = pAdapterSortArray[AdapterIndex];
442 EntriesFound =
FALSE;
452 if (EntriesFound ==
FALSE)
464 if (DestinationPattern ==
NULL)
475 else if (EntriesFound ==
FALSE)
480 if (pAdapterSortArray)
481 free(pAdapterSortArray);
482 if (pAdapterAddresses)
483 free(pAdapterAddresses);
485 free(IpForwardTable);
559 if (RowToAdd->dwForwardMetric1 == 0)
560 RowToAdd->dwForwardMetric1 = 1;
561 else if (RowToAdd->dwForwardMetric1 > 9999)
562 RowToAdd->dwForwardMetric1 = 9999;
584 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\PersistentRoutes",
635 if ((
wcscmp(Netmask,
L"255.255.255.255") != 0) &&
647 free(IpForwardTable);
685 PWSTR DestinationPattern)
721 free(IpForwardTable);
729 PWSTR DestinationPattern)
733 DWORD dwIndex = 0, dwBufferSize;
739 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\PersistentRoutes",
871 return (
ret == 0) ? 0 : 1;
CHAR FAR *WSAAPI inet_ntoa(IN IN_ADDR in)
ULONG WSAAPI inet_addr(IN CONST CHAR FAR *cp)
#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)
#define ConInitStdStreams()
void ConResPrintf(FILE *fp, UINT nID,...)
#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
_ACRTIMP int __cdecl _wtoi(const wchar_t *)
_ACRTIMP int __cdecl _wcsicmp(const wchar_t *, const wchar_t *)
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
_ACRTIMP void __cdecl qsort(void *, size_t, size_t, int(__cdecl *)(const void *, const void *))
_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
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
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