Sign in to follow this  
KnolanCross

Recvfrom and multiple clients from the same host

Recommended Posts

KnolanCross    1974
Hi there, I am creating a small side project, it is yet another UDP with confirmation solution.
I am using C on linux, trying to remain as close to POSIX as possible, so I won't have a hard time porting it to windows.

Right now I am facing the following problems:

1) Client A and Client B are behind a router, so I receive their messages (using recvfrom) and their addr struct show the same IP. Is there any API provided information that I can use I should I implement some kind of handshake where I can give each of them a random number to identify them?

2) Whenever I receive the first message from some IP, the address returned is FFFFFFFF. Any ideas?

Thanks in advance.

Share this post


Link to post
Share on other sites
ApochPiQ    23010
For the first question, this is a natural consequence of how NAT works. If you want to uniquely identify endpoints behind NAT, you will need to assign them some kind of identifier yourself besides just address.

The second question just sounds like a bug in the way you use the APIs; if you could post some (minimal) code that reproduces the problem that'd be helpful.

Share this post


Link to post
Share on other sites
hplus0603    11348
While client A and client B will have the same IP address, they will have different source ports.
Think about it: If there was no way to tell them apart, how could the router know which return packet to send to which client?
Thus, you can simply identify the clients with their remote IP:port tuple, just like with any other clients.

Share this post


Link to post
Share on other sites
KnolanCross    1974
[quote name='hplus0603' timestamp='1354156281' post='5005176']
While client A and client B will have the same IP address, they will have different source ports.
Think about it: If there was no way to tell them apart, how could the router know which return packet to send to which client?
Thus, you can simply identify the clients with their remote IP:port tuple, just like with any other clients.
[/quote]

Lol, that was really obvious. I feel stupid now lol.
Thanks a lot hplus.

EDIT:
2nd problem solved.
In case anyone find this with the same problem I had, you need to start the addrlen with sizeof(struct <your address type); Edited by KnolanCross

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this