dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Local socket binding on multihomed host in Windows XP does not work

  1. #1
    Join Date
    May 2008
    Posts
    2

    Local socket binding on multihomed host in Windows XP does not work

    I am writing a C# application to use two or more network connections (NIC's) on a single client to a remote server application for parallel file upload - to increase upload throughput. I am using Windows XP.

    I bind one socket to one local NIC (say NIC1) and then the remote server IP and port and then another socket to NIC 2 and the same remote server and port. This works most of the time - the TCP connection gets established OK.

    However when I try to send data on NIC1, 95% of the time I get TCP checksum errors (viewed via Wireshark) on the packet at each end and hence the remote server does not respond correctly. The other NIC 2 typically functions OK with no checksum errors and data can be sent OK.

    Bizzarely, if I disconnect NIC2, I can get a perfect connection on NIC1 and no checksum errors. Even more bizzarely - sometimes (5% of the time) data can be sent on both NIC1 and NIC2 correctly.

    This does not appear to be a problem with the connection, as I never get any checksum errors with just NIC 1 connected.

    Neither NIC uses checksum offloading. Each NIC is on a different subnet - 192.168.0 and 192.168.2

    The same problem appears on a different PC and when using a simple echo client-server console program, connecting alternately to the server via NIC1 and then NIC2.

    Is it possible to local bind sockets successfully in Windows XP? If so how do I do it?

    If not, can it be done on Vista/Windows Server 2003/8 etc.?

  2. #2
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Local socket binding on multihomed host in Windows XP does not work

    Which version of Windows? On WinXP and before, it's the stack that selects the network card that is used, and there is nothing in the Winsock API that can be used to affect the stack's selection. A call to bind() will not do anything.

    The stack makes its selection based on something called the "routing table". It might be possible to change the routing table, and a change to the routing table would probably affect the way the stack selects one adapter over another.

    To change the routing table, search for the CreateIpForwardEntry() function. A quick search turned up this link, which describes how to create a routing table entry so that all IP traffic with a specified server is routed via a specified adapter: http://ce4all.blogspot.com/2007/05/r...specified.html . It describes an approach for a WinCE device, but it should work for desktop too.


    The reason you get a checksum error is that the return IP is effectively "spoofed", since the TCP packet is being sent from a NIC whose IP address doesn't match. See "Windows Socket Connection from a Multiple-Homed Computer" at http://support.microsoft.com/kb/175396

    Also see this thread, which pretty much repeats the above: "How to connect a port to a specified Networkcard? " at http://www.codeguru.com/forum/showthread.php?t=451117

    Incidentally, the issue is caused by Windows's use of a "weak end system (E/S)" model. Vista and above use strong E/S, so the issue might be resolved in Vista (i.e., the call to bind() might work).

    Mike

  3. #3
    Join Date
    May 2008
    Posts
    2

    Re: Local socket binding on multihomed host in Windows XP does not work

    Thanks, this pretty much answers my post "Strange bind behavior on multihome system".

    Is there a command to determine the outgoing device based on destination address besides deciphering the routing table?

    I'm trying to send/receive msgs while monitoring the timing via Pcap. This is hard to do when you can't predict which interface will be used for sending.

  4. #4
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: Local socket binding on multihomed host in Windows XP does not work

    Glad to help. Incidentally, for others reading here, raboyd's other post is here: http://www.codeguru.com/forum/showthread.php?t=452368

    Mike

  5. #5
    Join Date
    May 2008
    Posts
    2

    Re: Local socket binding on multihomed host in Windows XP does not work

    Thanks for the information.

    A few hours after my post, I got it working....some how...

    I changed the routing metric for the NIC (via the advanced setting of the adapters IP configuration in control panel) which was connected to the Lan so that the default gateway detailed in the routing table changed to the NIC which was getting checksum errors.

    Then it started to work!

    Why this should be I dont quite get yet - and I need to do further tests. However last night I could bind to both NIC's and stream data in parallel over both NIC's to a remote server.

    I did think about changing the routing table to add an entry for the individual server, however I need to send data concurrently from each NIC to the same server so I dont think this is an option.

    I dont find the Microsoft post very clear.
    I believe is says that;... you can bind to the separate NIC's and you can route data over them concurrently, but for data passed through the 'non-default' NIC the source IP will be changed. Do I understand this correctly??

    I get your comment about the checksum. I will have a look at the checksums on the Lan connection to see if they are 'Bad'.

    I will probably want to add more adapters to increase the speed further and this approach may then fail. So I might have a look at Vista.

    Does anyone have experience of Vista used this way??

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)