In order to ensure we have the correct routes for various vpn connections, we typically run a batch file that calls commands similar to the following:
route add xxx.xxx.xxx.xxx mask 255.255.255.0 yyy.yyy.yyy.yyy
We have a C# application that uses the NetworkInterfaces
clas开发者_JS百科s to listen for network events, and runs this command using the Process
command.
This isn't ideal, and I was wondering if there are a certain set of Win32 API calls that would mean I can add/remove routes without shelling out to a console app. In order words, what API calls is route.exe
making to do it's stuff?
I think CreateIpForwardEntry
and it's colleagues might be the way to go, but I'm not too sure. I read about it here: http://msdn.microsoft.com/en-us/library/aa365860(VS.85).aspx
Without any doubt, the IP Helper Functions are the ones used to implement the ROUTE command. Check GetIpForwardTable() and the MIB_IPFORWARDROW structure documentation and, for a ROUTE clone sample, check the IPRoute subdirectory (under the IPHelp directory) in your Microsoft Platform SDK directory.
精彩评论