如何为进程自定义路由?
在我的计算机中,有两个网络适配器,连接到不同的子网。如下:
适配器A:10.20.30.201 适配器B: 10.20.31.201
我想让一个特殊进程(例如进程A)的所有传出数据都通过适配器A。也就是说,我想让适配器A作为该进程的默认路由。
我知道,我可以修改某些特殊目的地的路由表,但我想要在这里做的事情非常不同。 进程A可能与许多不同的IP进行通信,而我事先并不知道。
Winsock2 提供LSP 作为在 TCP/IP 堆栈中放置 dll 的方法。我对LSP不熟悉,不知道LSP能否做我想做的事情。
有人可以给我一些建议吗,谢谢。
In my computer, there are two network adapters, connecting to different subnet. As below:
adapter A: 10.20.30.201
adapter B: 10.20.31.201
I want to make all outgoing data of a special process (for example Process A) through adapter A. That is I want to make adapter A as the process's default route.
I know, I can modify route table for some special destination, But what I want to do here is very different. Process A may communicate with many different IP and I don't know in advance.
Winsock2 provides LSP as a way to lay a dll in TCP/IP stack. I'm not familiar with LSP and don't know whether LSP can do what I want to do.
Can anybody give me some suggestion, Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LSP 的快速背景:
使用 Winsock2 API 的应用程序调用 WSA 前缀函数的组合,例如 WSAConnect、WSASocket、WSASend、WSARecv 等。
如果应用程序仍然使用旧的 Winsock 函数,则这些函数将映射到后面的 Winsock2无论如何,场景。例如:send()映射到WSASend(),recv()映射到WSARecv()等,
WSA前缀函数将在内部调用LSP提供的相应WSP前缀函数。例如WSASend()调用WSPSend(),WSASocket()调用WSPSocket()等。简而言之,WSAWhateverFunction()将调用WSPWhateverFunction()。它们的参数/返回值也相同(不完全相同,但有点相同)。
LSP 是一个实现了这些 WSP 前缀函数的 dll,例如修改出站/入站流量、过滤等。但是,LSP 仍然是用户空间 dll。它与其他用户空间程序一样受到限制,并且没有比其主机应用程序(例如互联网浏览器)更高的特权。它可以访问其他程序可用的同一组系统功能,例如。 winsock 等。
结论是,如果您的程序可以将传出流量定向到特定的 NIC,那么 LSP 也可以做到。如果不能,LSP 也不能。因此 LSP 与您的问题无关。
A quick background on LSP:
An application, which uses Winsock2 API, calls a combination of WSA-prefix functions, eg WSAConnect, WSASocket, WSASend, WSARecv, etc.
If an application still use old winsock functions, these functions are mapped to Winsock2 behind the scene anyway. For instances: send() is mapped to WSASend(), recv() to WSARecv(), etc
WSA-prefix functions will internally call their corresponding WSP-prefix functions provided by LSP. For instances WSASend() calls WSPSend(), WSASocket() call WSPSocket(), etc. In short, WSAWhateverFunction() will calls WSPWhateverFunction(). Their parameters/returns are also the same (Not quite, but kind of).
LSP is a dll with these WSP-prefix functions implemented, eg. modify outbound/inbound traffic, filtering, etc. However an LSP is still a userspace dll. It's as limited as other userspace programs, and has no higher privilege than its host application, eg internet browsers. It has access to same set of system functions that is available to other programs, eg. winsock etc.
Conclusion is if your program can direct out-coming traffic to specific NIC, LSP can do it too. If it can't, neither can LSP. LSP therefore is irrelevant to your problem.