Google Answers Logo
View Question
 
Q: How to determine if a connection/socket is comming in thru NAT with a socket ( No Answer,   2 Comments )
Question  
Subject: How to determine if a connection/socket is comming in thru NAT with a socket
Category: Computers > Programming
Asked by: davidlpotter-ga
List Price: $30.00
Posted: 16 Aug 2006 06:49 PDT
Expires: 15 Sep 2006 06:49 PDT
Question ID: 756565
Ok my question is,

After I do an accept is there a way to tell if a socket has come thru a NAT.
My problem is I want to do multiple connections from behind the NAT,
and I need to know the local address(192.168...)so I can tell they are
comming from different clients. I know I could send that local address
as a message after connection, but I need it at connection, can I get
that from the socket somehow?

Here is the code I use to get the ipaddress of a socket, but that
gives me back the ip address of the router, not the local address.
	
sockaddr_in addr1;
sockaddr_in *addr2 = 0;
int nVal =  0;

int len = sizeof(SOCKADDR_IN);
nVal = getpeername(nSocket,(struct sockaddr *)&addr1,&len);

return inet_ntoa(addr1.sin_addr);

Thanks
David

Request for Question Clarification by keystroke-ga on 18 Aug 2006 00:10 PDT
Do you actually need to do this?

It is the router's job to handle NAT work and IP conversions from LAN
to WAN IP addresses.

--Keystroke-ga
Answer  
There is no answer at this time.

Comments  
Subject: Re: How to determine if a connection/socket is comming in thru NAT with a socket
From: davidleepotter-ga on 22 Aug 2006 10:11 PDT
 
Yes I need to do this, my client connect to a server and creates a
client based off of the ip address.

Now if a person starts 2 clients from diff computers behind the
firewall, I will get 2 connections from the same ip address causing a
conflict.
Subject: Re: How to determine if a connection/socket is comming in thru NAT with a socket
From: zmaster_zhang-ga on 03 Sep 2006 20:36 PDT
 
Only programing in client or server is not enough.
You should see this page http://www.brynosaurus.com/pub/net/p2pnat/
If you want to soucercode you may touch me.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy