473,395 Members | 1,383 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

BSD Sockets - Selecting Source Address

158 100+
Hello Bytes,

I am using UDP BSD sockets in my program, all is working just fine until my computer has two nics or 1 nic and one virtual nic. I am running Linux x86 Debian Squeeze.

I have one nic pointed at my 10.0.0. network and another one at 10.13.0. network

My outbound packets are making it to the destination on my 10.13.0 network.

The problem is that the computer on the 10.13.0 network that im sending to tries to send an ACK back but it sees my address as being my 10.0.0. address but packets cannot route from the 10.13.0. to the 10.0.0. network. If it saw my address as being from the 10.13.0. network it would work fine.

When creating the udp sockets can I specify what source address to use?

Thanks in advance,
Adam


Here is how I am implementing the sending so far:

Expand|Select|Wrap|Line Numbers
  1.     memset(&hints, 0, sizeof hints);
  2.     hints.ai_family = AF_UNSPEC;
  3.     hints.ai_socktype = SOCK_DGRAM;
  4.  
  5.     if ((rv = getaddrinfo(host.c_str(), po, &hints, &servinfo)) != 0) {
  6.         throw "getaddrinfo failed";
  7.     }
  8.  
  9.     // loop through all the results and make a socket
  10.     for (p = servinfo; p != NULL; p = p->ai_next) {
  11.  
  12.         cout << "**Addr:" << p->ai_addr->sa_data << endl;
  13.  
  14.         if ((sockfd = socket(p->ai_family, p->ai_socktype,
  15.                 p->ai_protocol)) == -1) {
  16.             continue;
  17.         }
  18.  
  19.         break;
  20.     }
  21.  
  22.     if (p == NULL) {
  23.         throw "failed to bind to socket";
  24.     }
  25.  
  26.     if ((numbytes = sendto(sockfd, msg.c_str(), msg.length(), 0,
  27.             p->ai_addr, p->ai_addrlen)) == -1) {
  28.         return numbytes;
  29.     }
  30.  
  31.     freeaddrinfo(servinfo);
  32.     close(sockfd);
  33.  
Oct 22 '10 #1
2 2206
ashitpro
542 Expert 512MB
As a first step, lets forget about 10.0.0.x nic/network.
Say,your machine has ip 10.13.0.5 assigned to other nic.
Your target machine,to which you are sending the UDP packets,has ip 10.13.0.6. Now, if my assumptions are right then check if both these machines are able to ping each other or not? If that works well then, I don't think any good reason about why it's not receiving ack packet unless firewall is ok with udp packets.
Oct 23 '10 #2
kardon33
158 100+
Thanks for the reply ashitpro, but I don't you understand the problem I am having.

My machine can send packets to the target machine on the 10.13.0 network without a problem and the target machine can send packets/ping to my machine if it uses my 10.13.0 address. But if it uses my 10.0.0. address my network will not allow it to go.

My problem is probably due to how my network is setup but I do not have much control over that.

So my problem is that the target machine only knows my 10.0.0 address because that is what the first packet is sent by. Is there a way to make the packet I am sending have a source address of my 10.13.0. address?
Oct 25 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: mrpolitics | last post by:
So I'm working with PureIRCD (http://sourceforge.net/projects/pure-ircd) and everything was fine untill yesterday when the server crashed. So I did a cold restart and staretd the server back up...
6
by: Laxmikant Rashinkar | last post by:
Is there any way to use a C# socket in promiscuous mode? Any sample code that shows how this is done? any assistance is much appreciated! thanks LK
3
by: alex tomlinsom | last post by:
I've got a c# socket that is open and listening to incoming UDP packets on a port. When the packet comes in, I want to figure out what address it came from. The problem seems to be that while the...
0
by: Tobias Sandhaas | last post by:
Hello I have an apache webserver running with multiple VHosts bound on several public IPs. I am looking for a way to tell php that every outgoing connection (eg mysql_connect()) should use a...
4
by: MMA | last post by:
Hi All, How do I get the source IP of a packet, not knowing if NAT has taken place. Thanks In Advance
0
by: richard.charts | last post by:
Well, unfortunately, I couldn't get any answer on the msdn forums, so I'll give it a shot here. Real question at the bottom....
2
by: phiberoptick | last post by:
I am looking for a way to specify which IP or interface to use as the source when calling fsockopen on a server with multiple IP's. Any help or direction would be much appreciated. -Ronan
2
by: satya0674 | last post by:
Hi, I want to know whether is it necessery to put the sorce address in the arp request packet . as we r getting the MAC address in the datalink layer ,this is due to the broadcast of physical...
1
by: Gurur | last post by:
Hi all, I have a doubt. If I have 2 structures and one is parent of other , ie the child structure is present in the parent one . And if the child structure is declared as dynamic array in the...
0
by: Xionbox | last post by:
Hello everybody, The error I have seems very easy to solve, but for some odd reason I can't seem to solve it. Anyways, here's my "setup". I created a server running on localhost:1200 (telnet...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.