Getting internet address (as opposed to local address)

Started by
6 comments, last by griffenjam 22 years, 10 months ago
O.k. on my computer (and many other peoples) my local address is NOT my internet address. I want to write in the ability to type in an internet address to connect to a game on that computer, but in order to do that I have to know the local internet address, which can be different from the local macine address. How do I get what I am looking for? Jason Mickela ICQ : 873518 E-Mail: jmickela@pacbell.net ------------------------------ "Evil attacks from all sides but the greatest evil attacks from within." Me ------------------------------
"The paths of glory lead but to the grave." - Thomas GrayMy Stupid BlogMy Online Photo Gallery
Advertisement
Are you talking about the loop back address 127.0.0.1? That is provided by the MS loopback driver. When connecting to another computer you do not need to bind the socket to an address. You just call connect() and it should work. If you computer has multiple network cards (multi-homed) it should still work. If you call gethostbyname() to get back a hostent structure and enumerate through the IP address it returns.

If your computer happens to be behind a DSL/cable modem sharing router (software or hardware) then things become more difficult. Your packets get sent to the router (which becomes your default gateway) and get sent to the remote computer. Before sending the data, the router modifies the IP header and replaces your internal IP (from your computer) with the IP address assigned to the cable modem (which normally goes to your computer if you weren''t using a NAT/sharing system). When the remote computer receives data it can send data back, which the router receives. The router remembers where the data came from and sends it back to your computer.

Now, in this situation it becomes nearly impossible to figure out your internet IP address. In reality you don''t need the IP address because the router automatically handles things. You may need to forward a port on the router if it acts as a firewall too.

If this doesn''t answer your question can you explain what you mean between your ''local address'' and your internet address. If you only have one network card and are attached directly to your DSL/cable modem then your local address is the same as your internet address.



Dire Wolf
www.digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
I have DSL that feeds into my Linux server, it acts as a gateway to my Win box. It''s address it 90.0.0.2, it only knows it''s gateway address. The problem is, if I am behind a gateway, and the other computer is behind a gateway, I can''t for a connection because I don''t know the internet address of either computer.
I just need something like a server that you can connect to that tells you where you are connecting from, or a way to find out my address.



Jason Mickela
ICQ : 873518
E-Mail: jmickela@pacbell.net
------------------------------
"Evil attacks from all sides
but the greatest evil attacks
from within." Me
------------------------------
"The paths of glory lead but to the grave." - Thomas GrayMy Stupid BlogMy Online Photo Gallery
Dire Wolf is right, you can''t get the IP address of a machine behind a proxy server/firewall (which is the whole point of such a device). Forwarding a specific port is your best bet, as previously stated.
Okay, so, I know that when you visit web-sites your ip addy is sent as an environment variable. Is there any way to take advantage of this?
"The paths of glory lead but to the grave." - Thomas GrayMy Stupid BlogMy Online Photo Gallery
One "duct-tape" method is to do a page scrape from http://www.whatismyipaddress.com

Your program could grab the page via a HTTP request and then parse through the results for your Internet IP address.

LostLogic
www.lostlogic.com
Author, Multiplayer Game Programming



Edited by - LostLogic on June 9, 2001 11:44:47 PM

LostLogicwww.GamerOutfit.comXBox 360 Community Games Reviews and NewsExisled - 2D/3D Shooter for XBox 360

you wont be able to use the address even if you get it as the only address that is really on the internet is the linux machine. the machine behind it has no real internet address.
alchemar is correct if you are talking about an IP behind a firewall.

If you have NAT working then you could do the screen-scrape method I talked about about and specify the port. That would direct you to the proper machine.




LostLogic
www.lostlogic.com
Author, Multiplayer Game Programming

LostLogicwww.GamerOutfit.comXBox 360 Community Games Reviews and NewsExisled - 2D/3D Shooter for XBox 360

This topic is closed to new replies.

Advertisement