在Windows中为套接字使用特定的网络接口

在Windows中有一个可靠的方法,除了更改路由表,强制新创建的套接字使用特定的网络接口?我明白bind()到接口的IP地址不能保证这一点。
(好的第二次幸运..)

FYI还有另一个问题perform connect() on specific network adapter沿着同一行…

根据The Cable Guy

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是(某些情况除外)。

也从http://www.codeguru.com/forum/showthread.php?t=487139

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.

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.

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:

“Local socket binding on multihomed
host in Windows XP does not work” at
07003

“How to connect a port to a specified
Networkcard?” at
07004.
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.

“Working with 2 Ethernet cards” at
07005

“Strange bind behavior on multihomed
system” at
07006

希望有帮助!

相关文章

Windows2012R2备用域控搭建 前置操作 域控主域控的主dns:自...
主域控角色迁移和夺取(转载) 转载自:http://yupeizhi.blo...
Windows2012R2 NTP时间同步 Windows2012R2里没有了internet时...
Windows注册表操作基础代码 Windows下对注册表进行操作使用的...
黑客常用WinAPI函数整理之前的博客写了很多关于Windows编程的...
一个简单的Windows Socket可复用框架说起网络编程,无非是建...