Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

problems with bind() in multihomed Win2000 Pro; All NICs on same network/subnet

78 views
Skip to first unread message

Joe

unread,
Jul 1, 2002, 12:21:31 PM7/1/02
to
All,

I have been scouring all over the web and newsgroups for three days
and I have been unable to find a solution to my current problem. Here
it is in a nutshell:

I have a PC running Windows 2000 Professional with two NIC's on the
same network and subnet. I know this is an unusual configuration but
it is required for the application I am writing. I'm not trying to do
anything silly like "load balancing" or "redundant connections" on the
same subnet. I'm attempting to write a client program in which I want
to be able to use two TCP/IP sockets (1 per NIC) and selectively
choose the interface that I wish to use so I can dictate packets
alternately flowing out of each NIC.

In order to facilitate this I followed the example shown in the
Winsock FAQ and tried to use bind() to bind a different socket to
either interface. After binding each socket I attempt to connect each
of them to the same destination server (separate instances of server
program). One of the connect()'s always works and the other always
times out. When I used a network analyzer(commview) to try and figure
out what was up I noticed that Win2000 was only utilizing one of the
two NIC's, the other one was just sitting idle. The idle NIC is the
one that fails.

I used 'ipconfig' and 'route print' and both NIC's are properly set
up, both have default routes. I checked the arp cache, and only one of
them was listed, but I assume that is because one of the NIC's never
sends out a packet....so it probably never gets arped....and never
gets an entry in the local cache...this is just a guess so please
correct me if I'm wrong.

I have assumed that when Windows 2000 has two NIC's on the same
network/subnet it just routes all packets to the first default entry
in the route table, meaning all packets get routed through the first
NIC since both have the same default gateway. I tried to use
setsockopt(..., ..., SO_DONTROUTE) in order to turn off routing, but
this has no effect. The Winsock documentation says this is an optional
feature....does this mean that MS themselves haven't implemented it!?

My question to the experts is this:

Am I making the correct assumptions, and if so are there any avenues I
haven't attempted yet? If I haven't been clear on anything let me know
and I will be more specific. I really appreciate your help!

thanks,
Joe

Adrien de Croy

unread,
Jul 1, 2002, 3:53:37 PM7/1/02
to

Basically by putting 2 NICs on the same logical subnet, you are creating an
impossible task for the IP router on your system.

Say you had 2 nics, 192.168.0.1, and 192.168.0.2 each with net mask
255.255.255.0

your route table would contain the following routes

network mask interface
192.168.0.1 255.255.255.255 127.0.0.1
192.168.0.0 255.255.255.0 192.168.0.1
192.168.0.2 255.255.255.255 127.0.0.1

the second time it tried to add the route for the 192.168.0.0 subnet but
with the different interface, it would have failed, so if you look at any
packet going out, it will only go out one interface.

My first question is this. Why do you need to have the sockets bound on
different NICs? Did you know you can allocate 2 IP addresses to a single
NIC?

If you are trying to aggregate the bandwidth or something, you will need to
do it at the packet layer with an NDIS intermediate driver etc - no bind()
down there!

Also, unless you are using raw sockets, and spoofing source IPs, what can
you gain by controlling packets going out one or other socket? TCP won't
work like that - you can't have 2 sockets on one end talking to a single on
on another end - you can't share sockets on a single TCP connection...

you might conceivably be able to do something useful with UDP, but I am
doubtful..

Will need to post a bit more about exactly what you are trying to achieve
here I think.

Hope this is of some help

cheers

Adrien


"Joe" <JRUS...@email.mot.com> wrote in message
news:ba0f5f21.02070...@posting.google.com...

Joe

unread,
Jul 2, 2002, 5:15:05 PM7/2/02
to
Adrien,

Thanks for the quick response! I will try to be more specific. This is
my goal: I want to be able to bypass the route table and dictate which
interface I use. I thought I could use bind() and then the
SO_DONTROUTE option but it doesn't seem to work.

I am not trying to connect two client sockets to the same server
socket. I am trying to connect two sockets through two different
interfaces to the same server....but not the same socket on that
server. What I am trying to do is something like if you opened up two
instances of an FTP client with the same destination server. They both
are connected and running...but they are connected to different
sessions on the FTP server.

For example:

If I have two interfaces with the IP addresses 136.182.98.5 and
136.182.98.6 then then part of the contents of my route table will
look something like this:

network dest mask interface
0.0.0.0 0.0.0.0 136.182.98.5
136.182.98.0 255.255.255.0 136.182.98.5
136.182.98.5 255.255.255.255 127.0.0.1
136.182.98.6 255.255.255.255 127.0.0.1

If I understand correctly that means that my default route is
interface 136.182.98.5 and the first route for network 136.182.98.0 is
136.182.98.5.

So when Win2000 looks in the route table it always finds 136.182.98.5
first, so all packets will go through that interface. I want to be
able to bypass the routing table and tell Windows what interface to
use. Binding to a specific interface doesn't seem to work.

I am aware that you can assign more than one IP to an interface, and
that isn't an option. I am working on a custom app to do some testing
and I need the capability I have described. I know that you can
specify the interface you wish to use in Linux, but the legacy
codebase is all in MFC so porting is my last ditch option.

Is there anyway to bypass the routing table using
winsock2....SO_DONTROUTE appears not to work....Are there any third
party implementations of winsock besides trumpet (no Win2000 support)
that might perhaps implement SO_DONTROUTE?

thanks again for your help! let me know if you need more info!

-Joe Ruscio


"Adrien de Croy" <adr...@xtra.co.nz> wrote in message news:<10255530...@cereal.attica.net.nz>...

Adrien de Croy

unread,
Jul 3, 2002, 8:14:21 AM7/3/02
to
in Winsock, binding to a specific interface only seems to affect the source
IP on the packets you send out, not the interface that will be used - it
still uses the route table to choose that.

I have looked at this before to try and get some decent modem aggregation,
and/or load balancing going, and always ran up against this problem... the
outbound packets always went out one route, although the packets coming back
do actually come back in the right interface.

As far as I can tell, you would need to write an Intermediate NDIS driver
which sits between IP protocol handler and NDIS, and can do the routing
itself. Not a small task, but there are frameworks available for such
things from pcausa.com, or Ashley Laurent write one as well... it is a
kernel driver though, so you need to install the DDK for your target OS to
build the drivers.

I never had any luck with SO_DONTROUTE either.

However, it could be worth a crack at using raw sockets if you are able to
set the ethernet MAC address on your packets (I don't think it allows you to
do this though).

Maybe possible to do some sort of TDI hook as well... not sure where the
router sits in the MS stack in this respect.


"Joe" <JRUS...@email.mot.com> wrote in message

news:ba0f5f21.0207...@posting.google.com...

Joe

unread,
Jul 11, 2002, 10:21:51 AM7/11/02
to
All,

Well just as a closing to this issue, I spent an hour and a half in a
conference call with 3 M$ engineers yesterday, one of them on the
Winsock API team, and another two from the Windows 2000 networking
team and the bottom line is that this CANNOT be done on Windows
without going down to the driver level like Adrien suggested. We are
switching our project to Linux and I hope this thread saves someone
else the week I wasted searching for a solution. Thanks for the help
Adrien!

-Joe

"Adrien de Croy" <adr...@xtra.co.nz> wrote in message news:<10257029...@cereal.attica.net.nz>...

0 new messages