使用特定的网络接口,在Windows套接字 [英] Using a specific network interface for a socket in windows

查看:135
本文介绍了使用特定的网络接口,在Windows套接字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有窗户的可靠方法,除了改变路由表,强制新建的插座使用特定的网络接口(据我所知,bind()的对接口的IP地址,并不能保证这一点)?

Is there a reliable way in windows, apart from changing the routing table, to force a newly created socket to use a specific network interface (I understand that bind() to the interface's IP address does not guarantee this)?

推荐答案

(好吧第二次幸运..)

(Ok second time lucky..)

FYI还有另外一个问题在这里<一个href=\"http://stackoverflow.com/questions/1237679/perform-connect-on-specific-network-adapter\">perform在特定的网络适配器连接()沿着相同的路线...

FYI there's another question here perform connect() on specific network adapter along the same lines...

根据网络专家

的Windows XP和WindowsServer®2003
  使用弱主机模型发送和
  接收所有I​​Pv4接口和
  对于强主机模式发送和
  接收所有I​​Pv6接口。您
  不能配置此行为。该
  下一代TCP / IP堆栈
  Windows Vista和Windows Server 2008中
  支持强大的主机发送和
  通过接收IPv4和IPv6
  默认情况下,除所有接口
  Teredo隧道接口的
  特定于Teredo主机的中继。

Windows XP and Windows Server® 2003 use the weak host model for sends and receives for all IPv4 interfaces and the strong host model for sends and receives for all IPv6 interfaces. You cannot configure this behavior. The Next Generation TCP/IP stack in Windows Vista and Windows Server 2008 supports strong host sends and receives for both IPv4 and IPv6 by default on all interfaces except the Teredo tunneling interface for a Teredo host-specific relay.

因此​​,要回答你的Windows XP中的问题(得当,这个时间)和Windows Server 2003 IP4没有,但对于IP6肯定。和Windows Vista和Windows 2008是(除了某些情况下)。

So to answer your question (properly, this time) in Windows XP and Windows Server 2003 IP4 no, but for IP6 yes. And for Windows Vista and Windows 2008 yes (except for certain circumstances).

另外从 HTTP://www.$c$cguru。 COM /论坛/ showthread.php?T = 487139

在Windows中,调用bind()时影响
  卡选择只传入流量
  没有传出通信。因此,在一
  客户在一个多穴系统运行
  (即,多于一个接口卡),
  它是选择网络堆栈
  该卡的使用,并且它使得其
  选择仅基于
  目的地IP,这又是基于
  上的路由表。调用bind()时
  不会影响卡的选择
  以任何方式。

On Windows, a call to bind() affects card selection only incoming traffic, not outgoing traffic. Thus, on a client running in a multi-homed system (i.e., more than one interface card), it's the network stack that selects the card to use, and it makes its selection based solely on the destination IP, which in turn is based on the routing table. A call to bind() will not affect the choice of the card in any way.

它有事做
  所谓弱端系统
  (弱E / S)的模式。 Vista中更改为
  强大的E / S模式,所以问题可能
  在Vista下
不会出现。但是,所有之前
  Windows版本使用弱E / S
  模型。

It's got something to do with something called a "Weak End System" ("Weak E/S") model. Vista changed to a strong E/S model, so the issue might not arise under Vista. But all prior versions of Windows used the weak E/S model.

通过弱E / S模式,它的
  决定哪些卡路由表
  用于传出流量在
  多宿主系统。

With a weak E/S model, it's the routing table that decides which card is used for outgoing traffic in a multihomed system.

看看这些线程提供了一些
  深入了解:

See if these threads offer some insight:

本地插槽上的多宿主结合
  主机在Windows XP中不起作用在
   HTTP://www.$c$cguru.com/forum/showthread的.php?T = 452337

"Local socket binding on multihomed host in Windows XP does not work" at http://www.codeguru.com/forum/showthread.php?t=452337

如何将一个端口连接到指定的
  Networkcard?在
   HTTP://www.$c$cguru.com/forum/showthread的.php?T = 451117
  此线程提到
  CreateIpForwardEntry()函数,它
  (我认为),可用于创建
  在路由表条目,以便所有
  传出IP流量与指定
  服务器经由指定的路由
  适配器。

"How to connect a port to a specified Networkcard?" at http://www.codeguru.com/forum/showthread.php?t=451117. This thread mentions the CreateIpForwardEntry() function, which (I think) can be used to create an entry in the routing table so that all outgoing IP traffic with a specified server is routed via a specified adapter.

有2个以太网卡工作的
   HTTP://www.$c$cguru.com/forum/showthread的.php?T = 448863

"Working with 2 Ethernet cards" at http://www.codeguru.com/forum/showthread.php?t=448863

奇怪的绑定行为
  系统在
   HTTP://www.$c$cguru.com/forum/showthread的.php?T = 452368

希望帮助!

这篇关于使用特定的网络接口,在Windows套接字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆