IP without connecting to external socket [Archive] - C Board

PDA

View Full Version : IP without connecting to external socket


Hunter2
08-10-2003, 03:35 PM
Hey guys, I've been searching the boards, FAQ, and more boards for this, but I haven't found a solution yet. Basically, I'm trying to find my IP address; I've read all about these 2 methods:
a:
gethostname()
gethostbyname()

b:
getsockname()

Problem with a: gethostname() gives me "kevin", and using gethostbyname() gives me my LAN address (the one assigned to me by my router).

Problem with b: I'm trying to get my IP address so that I can display it to the user and the user can then tell other users the IP so that other users can connect to the server; if other users already know the IP and can connect to the server so that I can get the IP address, the whole thing is pointless.

So my question is, is there any way to get my external IP address without having to connect to an external client?

XSquared
08-10-2003, 03:52 PM
No.

Hunter2
08-10-2003, 05:00 PM
... ok, thanks... :(

Hunter2
08-10-2003, 06:03 PM
Shoot, I tried just connecting to www.google.ca and doing getsockname(), and I still ended up with my 192.168.a.b address. Since I'm behind a router, do I HAVE to do the connect-to-ip-broadcasting-website approach, or is there any other way?

Iamien
08-22-2003, 09:04 PM
because your behind a router, you IP is 192.168.a.b
what you could do is have the server detect the IP of the connection, and that would be your user who is loggin in's IP.

Hunter2
08-26-2003, 08:50 AM
Thanks, but... could you explain what you mean? From what I gather, you're saying that I can connect to a user and the user can find my IP and send it back or something... but I'm trying to get the IP before connecting. :confused: