C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 10-27-2009, 01:56 PM   #1
Registered User
 
Join Date: Oct 2009
Posts: 3
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.
dsollen is offline   Reply With Quote
Old 10-27-2009, 04:30 PM   #2
Registered User
 
valaris's Avatar
 
Join Date: Jun 2008
Location: RING 0
Posts: 462
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.
valaris is offline   Reply With Quote
Old 10-27-2009, 04:55 PM   #3
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,381
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.
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 11:24 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22