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

Thread: Working with 2 Ethernet cards

  1. #1
    Join Date
    Apr 2003
    Posts
    100

    Working with 2 Ethernet cards

    Hello,
    My PC contains 2 ethernet cards each has different IP.
    I wrote a simple UDP client application that works OK on the default card.
    How can I change the application so that packets will be sent from the secondary card ?
    Thanks.

  2. #2
    Join Date
    Aug 2007
    Location
    Birmingham, UK
    Posts
    360

    Re: Working with 2 Ethernet cards

    This depends on the IP configuration of each card. When each card is part of a different subnet then Windows will automatically output the UDP packet on the correct subnet (depending on the subnet of the intended receiver). If the UDP packet is sent to an address that is not part of either local subnet then it will be sent on the first network interface with a gateway setup.

    If you've setup a gateway on both interfaces and the UDP packet is not going to a local subnet then Windows will (possibly randomly) select a network for you.

    To force a send on a particular subnet (and with that on a particular interface) then you can use bind() to bind the socket to one of your subnets. Then all outgoing traffic from that socket will be output on that subnet regardless of where it is going to.

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

    Re: Working with 2 Ethernet cards

    I'm fairly certain that the stack selects the card to use 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.

    So, even if you call bind(), the routing table is still used to route the outbound IP datagrams, based on the target IP address. As a result of this behavior, the source IP address may not be the one associated with the network adapter that is chosen to send the packets. See "Windows Socket Connection from a Multiple-Homed Computer" at http://support.microsoft.com/kb/175396

    Therefore, a call to bind will probably not make a difference in selection of the physical card over which your datagram is sent.

    Some have reported success in adding a static routing to the routing table. The MSG_DONTROUTE option won't work since the Winsock stack is known to ignore this option. See the CreateIpForwardEntry() function.

    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.

    Mike
    Last edited by MikeAThon; April 17th, 2008 at 05:37 PM.

  4. #4
    Join Date
    Aug 2007
    Location
    Birmingham, UK
    Posts
    360

    Re: Working with 2 Ethernet cards

    Quote Originally Posted by MikeAThon
    I'm fairly certain that the stack selects the card to use based sloely 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.
    You are absolutely right about that of course... No idea what I was thinking while I typed that last part of my post! Was I actually thinking? Anyway, as you say, bind() only affects the _incoming_ traffic, not the outgoing.

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)