Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当你写这样的东西时:
s=socket(AF_INET,SOCK_STREAM) s.connect((siteIp,80)) s.send(...
当没有提供有关绑定套接字的信息时,linux内核如何知道它应该从哪个网卡发送数据包。
例如,我如何用我自己的 tun/tap 接口替换这个默认的 nic?
另外,我在哪里可以获得有关此主题的更多深入信息?
操作系统使用其内部路由表对哪个 NIC 最有可能到达您要连接的 IP 做出最佳猜测。路由与 NIC 和优先级相关联。如果出站数据包具有与给定路由匹配的目标 IP,则使用关联的 NIC。否则,将使用具有适当优先级的路由(例如网关或 VPN),因为数据包 IP 可能位于通过该路由到达的另一个网络上。
如果要指定使用哪个 NIC,则必须bind()在connect().
bind()
connect()