Thread: send/receive udp from specific NIC

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    4

    send/receive udp from specific NIC

    well the title sort of says it all. I have a computer with multuple ethernet ports, I want to explicitly use one of those ethernet ports. I know I could configure routing at the OS level to ensure specific port numbers go to a NIC, but is there a way I can control which NIC I use from within a C++ program without modifying the OS?

    FYI I'll be running in a linux enviroment.

    Thanks.

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    You can specify what interface you are binding to when calling bind(). That being said which ever interface gets to this port first will own it until it releases it.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    When you bind, instead of specifying INADDR_ANY, specify the actual IP address of the interface you want to bind to.

    EDIT: The answer is the same if you want to specify the interface for OUTGOING packets as well. Normally, for outgoing packets, you do not bother binding, but that doesn't mean you can't. bind to the proper IP and it should work how you want.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with UDP
    By AlexS in forum C# Programming
    Replies: 0
    Last Post: 07-07-2009, 06:21 PM
  2. Reading from UDP socket on specific interface
    By uriel in forum Networking/Device Communication
    Replies: 2
    Last Post: 11-29-2007, 11:09 PM
  3. simultaneously waiting for data on FIFO and UDP using select call
    By yogesh3073 in forum Networking/Device Communication
    Replies: 2
    Last Post: 01-05-2007, 09:53 AM
  4. Traceroute using UDP and ICMP
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 08-09-2002, 07:09 PM
  5. Traceroute using UDP + ICMP
    By Unregistered in forum Windows Programming
    Replies: 0
    Last Post: 08-05-2002, 10:50 AM