I'm trying to get client's ip by my sockaddr_in but this ip always 192.168.1.1(router ip).How can i get WAN ip correctly?
Asked
Active
Viewed 249 times
0
-
2Who is connecting to whom ? Show some code. – cnicutar Mar 02 '13 at 09:47
-
My client program connects to my my server program. 'accept( listener ,(sockaddr * ) &infos , &size); ip=inet_ntoa(infos.sin_addr);' – Atakan Erbaş Mar 02 '13 at 09:56
-
Where is the client and where is the server ? (nat, internet) You shouldn't normally get `192.168.1.1`. – cnicutar Mar 02 '13 at 09:58
-
In internet. I opened my port. The clients can connect me by my internet ip adress. – Atakan Erbaş Mar 02 '13 at 10:00
-
If you mentioned "I opened my port" then you're likely behind the NAT. – cnicutar Mar 02 '13 at 10:01
-
Yes, i am behind the NAT. – Atakan Erbaş Mar 02 '13 at 10:04
-
2@AtakanErbaş This is impossible. You cannot, in any way, get the IP address of a NAT gateway that's between your machine and the peer from an sockaddr_in. You'd have to get that info from somewhere else, either someone manually providing it to your program, or you'll have to come up with a protocol where the clients send you the internet IP they're connecting to. – nos Mar 02 '13 at 11:23
-
@nos: Why not post your comment as an answer? – alk Mar 02 '13 at 13:39
1 Answers
-1
Sounds like you have some kind of reverse proxy running on the router. It may have added the client IP somewhere e.g. as an X-Forwarded-For header for HTTP.

Frank
- 403
- 2
- 5