mirror of
https://github.com/reactos/reactos.git
synced 2026-05-31 08:17:09 +08:00
[ROUTE] Add /f option to the add and delete command
This commit is contained in:
@@ -12,8 +12,12 @@ BEGIN
|
||||
Manipulates the network routing tables.\n\n\
|
||||
ROUTE [-f] [-p] command [destination]\n\
|
||||
[MASK netmask] [gateway] [METRIC metric]\n\n\
|
||||
-f Not supported yet.\n\n\
|
||||
-p Not supported yet.\n\n\
|
||||
-f Cleans the routing table of all gateway entries prior to\n\
|
||||
executing the command. Can be used with the ADD and\n\
|
||||
DELETE command.\n\n\
|
||||
-p Makes a route persistent between boots of the system. By\n\
|
||||
default, routes are not persistent when the system is\n\
|
||||
restarted. Can be used with the ADD command.\n\n\
|
||||
command One of the following options:\n\
|
||||
PRINT Prints the routes.\n\
|
||||
ADD Add a new route.\n\
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#define IPBUF 17
|
||||
#define IN_ADDR_OF(x) *((struct in_addr *)&(x))
|
||||
|
||||
#define FLUSH_FLAG 0x1
|
||||
#define DELETE_FLAG 0x1
|
||||
#define PERSISTENT_FLAG 0x2
|
||||
|
||||
static
|
||||
@@ -401,6 +401,51 @@ CreatePersistentIpForwardEntry(
|
||||
return Error;
|
||||
}
|
||||
|
||||
static
|
||||
DWORD
|
||||
DeleteCustomRoutes(VOID)
|
||||
{
|
||||
WCHAR Destination[IPBUF], Netmask[IPBUF];
|
||||
PMIB_IPFORWARDTABLE IpForwardTable = NULL;
|
||||
ULONG Size = 0;
|
||||
DWORD Error = ERROR_SUCCESS;
|
||||
ULONG i;
|
||||
|
||||
if ((GetIpForwardTable(NULL, &Size, TRUE)) == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
if (!(IpForwardTable = malloc(Size)))
|
||||
{
|
||||
Error = ERROR_NOT_ENOUGH_MEMORY;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
Error = GetIpForwardTable(IpForwardTable, &Size, TRUE);
|
||||
if (Error != ERROR_SUCCESS)
|
||||
goto done;
|
||||
|
||||
for (i = 0; i < IpForwardTable->dwNumEntries; i++)
|
||||
{
|
||||
mbstowcs(Destination, inet_ntoa(IN_ADDR_OF(IpForwardTable->table[i].dwForwardDest)), IPBUF);
|
||||
mbstowcs(Netmask, inet_ntoa(IN_ADDR_OF(IpForwardTable->table[i].dwForwardMask)), IPBUF);
|
||||
|
||||
if ((wcscmp(Netmask, L"255.255.255.255") != 0) &&
|
||||
((wcscmp(Destination, L"127.0.0.0") != 0) || (wcscmp(Netmask, L"255.0.0.0") != 0)) &&
|
||||
((wcscmp(Destination, L"224.0.0.0") != 0) || (wcscmp(Netmask, L"240.0.0.0") != 0)))
|
||||
{
|
||||
Error = DeleteIpForwardEntry(&IpForwardTable->table[i]);
|
||||
if (Error != ERROR_SUCCESS)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
if (IpForwardTable)
|
||||
free(IpForwardTable);
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
AddRoute(
|
||||
@@ -414,7 +459,10 @@ AddRoute(
|
||||
|
||||
if ((argc <= start) || !ConvertAddCmdLine(&RowToAdd, argc, argv, start))
|
||||
return 1;
|
||||
|
||||
|
||||
if (flags & DELETE_FLAG)
|
||||
DeleteCustomRoutes();
|
||||
|
||||
if (flags & PERSISTENT_FLAG)
|
||||
Error = CreatePersistentIpForwardEntry(&RowToAdd);
|
||||
else
|
||||
@@ -441,6 +489,9 @@ DeleteRoute(
|
||||
if ((argc < start + 2) || !ConvertAddCmdLine(&RowToDel, argc, argv, start))
|
||||
return 1;
|
||||
|
||||
if (flags & DELETE_FLAG)
|
||||
DeleteCustomRoutes();
|
||||
|
||||
Error = DeleteIpForwardEntry(&RowToDel);
|
||||
if (Error != ERROR_SUCCESS)
|
||||
{
|
||||
@@ -467,7 +518,7 @@ wmain(
|
||||
{
|
||||
if (!_wcsicmp(&argv[i][1], L"f"))
|
||||
{
|
||||
flags |= FLUSH_FLAG;
|
||||
flags |= DELETE_FLAG;
|
||||
}
|
||||
else if (!_wcsicmp(&argv[i][1], L"p"))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user