How to know the local IP address

I’m using SDL and Net2 for a little client/server game.
I’d like to show the player is local IP address… any idea ?

I tryed:
NET2_ResolveHost(&ip, “localhost”, myport);
but it returns 127.0.0.1… :frowning:

Thanks!–
Bye!
Skunkguru.

I don’t know, but let me just say that it can be
amiguous.

127.0.0.1 is allways supposed to be the computer
you’re on. Multiple ethernet cards can have their own
seperate ip addresses as well (I’d know, I have 4 for
2 computers… 2 in each) as well as seperate modems.

I believe most games do this by connecting to a
metaserver (aka a server that just keeps track of meta
information, things like game servers) and then the
remote host (the metaserver) checks the ip address of
the connecting server.

Hopefully someone else has a better reply… like a
true answer to your question :).

— SkunkGuru wrote:> I’m using SDL and Net2 for a little client/server

game.
I’d like to show the player is local IP address…
any idea ?

I tryed:
NET2_ResolveHost(&ip, “localhost”, myport);
but it returns 127.0.0.1… :frowning:

Thanks!


Bye!
Skunkguru.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th

I don’t know, but let me just say that it can be
amiguous.

127.0.0.1 is allways supposed to be the computer
you’re on. Multiple ethernet cards can have their own
seperate ip addresses as well (I’d know, I have 4 for
2 computers… 2 in each) as well as seperate modems.

I believe most games do this by connecting to a
metaserver (aka a server that just keeps track of meta
information, things like game servers) and then the
remote host (the metaserver) checks the ip address of
the connecting server.

Hopefully someone else has a better reply… like a
true answer to your question :).

— SkunkGuru wrote:

I’m using SDL and Net2 for a little client/server
game.
I’d like to show the player is local IP address…
any idea ?

I tryed:
NET2_ResolveHost(&ip, “localhost”, myport);
but it returns 127.0.0.1… :frowning:

Thanks!


Bye!
Skunkguru.

Hi.
If you look to your host file you will see that localhost is 127.0.0.1 (it
is the same for all computer)
If you want an other ip you had to resolve the name.domain of your computer.
Just have a look at your host file and you will find the answer.

Good luck :wink:

----- Original Message -----
From: mrickert85@yahoo.com (Michael Rickert)
To:
Sent: Monday, April 12, 2004 3:53 AM
Subject: Re: [SDL] How to know the local IP address

Hopefully someone else has a better reply… like a
true answer to your question :).

:slight_smile:

the only way I’ve found to know my local address
is to connect to myself, and in the remote connection
event keep track of the IP address…
but I hope to find a better way! :-)–
Bye!
Skunkguru.

a platform specific way would be to run some network diagnostic tool that
showed your ip, dump that to a file and scan the file for what you want.

like in windows you could do something like this i think:

system(“ipconfig > ipinfo.txt”);

then scan for IP Address in ipinfo.txt then scan to ‘:’ then read in the ip
address (might be more complicated with multiple nic’s).

kinda a hacky solution, i only post it because of the lack of other
solutions hehe (:> ----- Original Message -----

From: skunkguru@hotmail.com (SkunkGuru)
To:
Sent: Monday, April 12, 2004 7:30 AM
Subject: Re: [SDL] How to know the local IP address

Hopefully someone else has a better reply… like a
true answer to your question :).

:slight_smile:

the only way I’ve found to know my local address
is to connect to myself, and in the remote connection
event keep track of the IP address…
but I hope to find a better way! :slight_smile:


Bye!
Skunkguru.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi,

One way of doing this on linux is to use the function getifaddrs().

This function returns a list of all network interfaces on the host
machine. The function is declared in ifaddrs.h. Be sure to free the
allocated memory with freeifaddrs() when you are done.

Best regards,
Henrik AlgestamOn Mon, 12 Apr 2004 15:41:50 -0700 “Alan Wolfe” wrote:

a platform specific way would be to run some network diagnostic tool
that showed your ip, dump that to a file and scan the file for what
you want.

like in windows you could do something like this i think:

system(“ipconfig > ipinfo.txt”);

then scan for IP Address in ipinfo.txt then scan to ‘:’ then read in
the ip address (might be more complicated with multiple nic’s).

kinda a hacky solution, i only post it because of the lack of other
solutions hehe (:

----- Original Message -----
From: “SkunkGuru”
To:
Sent: Monday, April 12, 2004 7:30 AM
Subject: Re: [SDL] How to know the local IP address

Hopefully someone else has a better reply… like a
true answer to your question :).

:slight_smile:

the only way I’ve found to know my local address
is to connect to myself, and in the remote connection
event keep track of the IP address…
but I hope to find a better way! :slight_smile:


Bye!
Skunkguru.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi,
I had found the same problem… SDL_net didn’t resolve my ip… sometimes it
gave me 0.0.0.0 and other times 127.0.0.1, I was testing with it and I found
one way to solve it…maybe it wasn’t the best way but it works :slight_smile: and you
don’t need to use system() function…

// Obtenemos IP del localhost

if(SDLNet_ResolveHost(&iServerIP,NULL,iServerPort)==-1)

{

ILogSystem.Msg(LOG_NORMAL," ? [INetwork->CreateServer(%d,%d,%d)] Error(1):
%s\n",port,passwd,dedicated,SDLNet_GetError());

return 0;

}

// Averiguamos el nombre del localhost con su ip

host=SDLNet_ResolveIP(&iServerIP);

// Abrimos socket del servidor

serversock=SDLNet_TCP_Open(&iServerIP);

if(!serversock)

{

ILogSystem.Msg(LOG_NORMAL," ? [INetwork->CreateServer(%d,%d,%d)] Error(2):
%s\n",port,passwd,dedicated,SDLNet_GetError());

return 0;

}

// Volvemos a averiguar la IP usando el nombre del host(nos da la IP de
internet)

SDLNet_ResolveHost(&iServerIP,host,iServerPort);

sorry, but I’m spanish and all comments are in spanish but it easy to
understand the code…and it works!

bye

Rober> ----- Original Message -----

From: atrix2@cox.net (atrix2)
To:
Sent: Tuesday, April 13, 2004 12:41 AM
Subject: Re: [SDL] How to know the local IP address

a platform specific way would be to run some network diagnostic tool that
showed your ip, dump that to a file and scan the file for what you want.

like in windows you could do something like this i think:

system(“ipconfig > ipinfo.txt”);

then scan for IP Address in ipinfo.txt then scan to ‘:’ then read in the
ip
address (might be more complicated with multiple nic’s).

kinda a hacky solution, i only post it because of the lack of other
solutions hehe (:

----- Original Message -----
From: “SkunkGuru”
To:
Sent: Monday, April 12, 2004 7:30 AM
Subject: Re: [SDL] How to know the local IP address

Hopefully someone else has a better reply… like a
true answer to your question :).

:slight_smile:

the only way I’ve found to know my local address
is to connect to myself, and in the remote connection
event keep track of the IP address…
but I hope to find a better way! :slight_smile:


Bye!
Skunkguru.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

— tocx wrote:>

----- Original Message -----
From: “Michael Rickert” <@Michael_Rickert>
To:
Sent: Monday, April 12, 2004 3:53 AM
Subject: Re: [SDL] How to know the local IP address

I don’t know, but let me just say that it can be
amiguous.

127.0.0.1 is allways supposed to be the computer
you’re on. Multiple ethernet cards can have their
own
seperate ip addresses as well (I’d know, I have 4
for
2 computers… 2 in each) as well as seperate
modems.

I believe most games do this by connecting to a
metaserver (aka a server that just keeps track of
meta
information, things like game servers) and then
the
remote host (the metaserver) checks the ip address
of
the connecting server.

Hopefully someone else has a better reply… like
a
true answer to your question :).

— SkunkGuru wrote:

I’m using SDL and Net2 for a little
client/server

game.
I’d like to show the player is local IP
address…

any idea ?

I tryed:
NET2_ResolveHost(&ip, “localhost”, myport);
but it returns 127.0.0.1… :frowning:

Thanks!


Bye!
Skunkguru.

Hi.
If you look to your host file you will see that
localhost is 127.0.0.1 (it
is the same for all computer)
If you want an other ip you had to resolve the
name.domain of your computer.
Just have a look at your host file and you will find
the answer.

Good luck :wink:

Windows dosnt have a host file, and it dosnt solve his
problem in any case - he needs to be able to look it
up from within his program. The name/domain of his
computer are also probably unknown to his program.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th

Hi,

One way of doing this on linux is to use the function getifaddrs().

This function returns a list of all network interfaces on the host
machine. The function is declared in ifaddrs.h. Be sure to free the
allocated memory with freeifaddrs() when you are done.

Best regards,
Henrik AlgestamOn Sun, 11 Apr 2004 18:53:34 -0700 (PDT) Michael Rickert wrote:

I don’t know, but let me just say that it can be
amiguous.

127.0.0.1 is allways supposed to be the computer
you’re on. Multiple ethernet cards can have their own
seperate ip addresses as well (I’d know, I have 4 for
2 computers… 2 in each) as well as seperate modems.

I believe most games do this by connecting to a
metaserver (aka a server that just keeps track of meta
information, things like game servers) and then the
remote host (the metaserver) checks the ip address of
the connecting server.

Hopefully someone else has a better reply… like a
true answer to your question :).

— SkunkGuru wrote:

I’m using SDL and Net2 for a little client/server
game.
I’d like to show the player is local IP address…
any idea ?

I tryed:
NET2_ResolveHost(&ip, “localhost”, myport);
but it returns 127.0.0.1… :frowning:

Thanks!


Bye!
Skunkguru.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I’d like to show the player is local IP address… any idea ?

I’m not a networking expert, but I’m afraid there is no easy solution to
that. Unless SDL_Net contains a cross-platform way to retrieve that
information, I think you’ll have to use OS functions to get the IP
address of all local interfaces, and choose one (preferably the one
that is leading to internet :slight_smile: )… Though the IP address you get could
very possibly be a LAN IP.

You could also connect to a server which somehow returns you your IP
address. (a mere php script on your web site should be able to provide
that, maybe accessed with curl)

(note: I’ve never used SDL_Net nor curl, nor tried to use the methods I
talk about)On 10/04/2004, SkunkGuru, you wrote:


Please remove “.ARGL.invalid” from my email when replying.
Incoming HTML mails are automatically deleted.

Did you read this email? it uses SDL_net and get for you correct ip…—
Hi,
I had found the same problem… SDL_net didn’t resolve my ip… sometimes it
gave me 0.0.0.0 and other times 127.0.0.1, I was testing with it and I found
one way to solve it…maybe it wasn’t the best way but it works :slight_smile: and you
don’t need to use system() function…

// Obtenemos IP del localhost

if(SDLNet_ResolveHost(&iServerIP,NULL,iServerPort)==-1)

{

ILogSystem.Msg(LOG_NORMAL," ? [INetwork->CreateServer(%d,%d,%d)] Error(1):
%s\n",port,passwd,dedicated,SDLNet_GetError());

return 0;

}

// Averiguamos el nombre del localhost con su ip

host=SDLNet_ResolveIP(&iServerIP);

// Abrimos socket del servidor

serversock=SDLNet_TCP_Open(&iServerIP);

if(!serversock)

{

ILogSystem.Msg(LOG_NORMAL," ? [INetwork->CreateServer(%d,%d,%d)] Error(2):
%s\n",port,passwd,dedicated,SDLNet_GetError());

return 0;

}

// Volvemos a averiguar la IP usando el nombre del host(nos da la IP de
internet)

SDLNet_ResolveHost(&iServerIP,host,iServerPort);

sorry, but I’m spanish and all comments are in spanish but it easy to
understand the code…and it works!

bye

Rober

Hi,

One way of doing this on linux is to use the function getifaddrs().

This function returns a list of all network interfaces on the host
machine. The function is declared in ifaddrs.h. Be sure to free the
allocated memory with freeifaddrs() when you are done.

Best regards,
Henrik AlgestamOn Sun, 11 Apr 2004 18:53:34 -0700 (PDT) Michael Rickert wrote:

I don’t know, but let me just say that it can be
amiguous.

127.0.0.1 is allways supposed to be the computer
you’re on. Multiple ethernet cards can have their own
seperate ip addresses as well (I’d know, I have 4 for
2 computers… 2 in each) as well as seperate modems.

I believe most games do this by connecting to a
metaserver (aka a server that just keeps track of meta
information, things like game servers) and then the
remote host (the metaserver) checks the ip address of
the connecting server.

Hopefully someone else has a better reply… like a
true answer to your question :).

— SkunkGuru wrote:

I’m using SDL and Net2 for a little client/server
game.
I’d like to show the player is local IP address…
any idea ?

I tryed:
NET2_ResolveHost(&ip, “localhost”, myport);
but it returns 127.0.0.1… :frowning:

Thanks!


Bye!
Skunkguru.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

If you look to your host file you will see that localhost is 127.0.0.1 (it
is the same for all computer)

yes, I know this… :-))

If you want an other ip you had to resolve the name.domain of your
computer.
Just have a look at your host file and you will find the answer.

Where is the host file in Windows ?? :wink:

I’d like to find a standard way (if possible), to avoid having different
ways and codes with their own #ifdef…–
Bye!
Skunkguru.

Did you read this email? it uses SDL_net and get for you correct ip…

It seems there is some problem with the mailing list
(or with hotmail… :slight_smile: )

I haven’t received all the replyes… I have to look at the
message with the newsgroup… :frowning:

I will try your code… thanks! :-)–
Bye!
Skunkguru.

“SkunkGuru” wrote:

Did you read this email? it uses SDL_net and get for you correct
ip…

It seems there is some problem with the mailing list
(or with hotmail… :slight_smile: )

I haven’t received all the replyes… I have to look at the
message with the newsgroup… :frowning:

the list is somehow fscked lately. some mails take days to show up on
the list or to get delivered. :frowning:

clemens

Clemens Kirchgatterer wrote:

“SkunkGuru” wrote:
the list is somehow fscked lately. some mails take days to show up on
the list or to get delivered. :frowning:

I’ve noticed that as well, but I’ve had some local delivery problems as
well…

Shawn Lindberg

the list is somehow fscked lately. some mails take days to show up on
the list or to get delivered. :frowning:
I’ve noticed that as well, but I’ve had some local delivery problems as
well…

I’d be happy to host the SDL list here on Synthcom. I even have spam
rejection capabilites that work really well. Sam, let me know if you’d
like me to host it on Synthcom. I’ve been doing mailing lists for a bit
over 10 years.

–>Neil-------------------------------------------------------------------------------
Neil Bradley "Your mistletoe is no match for my T.O.W. missile!"
Synthcom Systems, Inc. - Santabot - Futurama
ICQ #29402898

I’d like to show the player is local IP address… any idea ?

I’m not a networking expert, but I’m afraid there is no easy solution to
that. Unless SDL_Net contains a cross-platform way to retrieve that
information, I think you’ll have to use OS functions to get the IP
address of all local interfaces, and choose one (preferably the one
that is leading to internet :slight_smile: )… Though the IP address you get could
very possibly be a LAN IP.

This is a good point that needs to be emphasized. Now days it seems that
half the world is using NAT (Network Address Translation) so even if you
get your IP address, it isn’t going to be the actual IP address needed
to reach your computer. And, even if you use a server to echo back the
real IP address of your network you might find that there are hundreds
of other computers with the same IP address. I have about 8 PCs here all
using a single IP address through a NAT box. I know I can have ~250
machines behind one IP address. I believe that with a little creativity
you can get thousands of machines behind a single IP address.

I don’t know what you want the IP address for. But, it might not be as
useful as you think it is.

	Bob PendletonOn Sat, 2004-04-10 at 14:19, Olivier Fabre wrote:

On 10/04/2004, SkunkGuru, you wrote:

You could also connect to a server which somehow returns you your IP
address. (a mere php script on your web site should be able to provide
that, maybe accessed with curl)

(note: I’ve never used SDL_Net nor curl, nor tried to use the methods I
talk about)

±--------------------------------------+

SkunkGuru wrote:

If you want an other ip you had to resolve the name.domain of your

computer.

Just have a look at your host file and you will find the answer.

Where is the host file in Windows ?? :wink:

It won’t do you no good. Even on Linux, the computer can work without
having itself in the hosts file (for example, if DNS is installed on it,
or it uses DHCP, or it connects to Internet with modem, so IP and
hostname are different every time…)

The thing you must know that each network interface (eth, ppp, lo, etc.)
in computer can have IP address of it’s own. So, one computer can have
multiple addresses, meaning that you must know what interface you wish
to query. AFAIK, Each OS has some API functions to get the list of
interfaces and their IP addresses.

For Win9x, it’s in Windows instalation directory, for 2000, XP, it in
Windows/System/Drivers/etc or something like that.

I’d like to find a standard way (if possible), to avoid having different
ways and codes with their own #ifdef

AFAIK, it is not possible. This looks like a typical #ifdef type of problem.–
Milan Babuskov
http://fbexport.sourceforge.net

well… my little game is made up by a player that start up the game in
server mode (waiting for the connection) and the other player that
start up the game in client mode (connecting to the other computer).

I would like to show the player with the server version, which
public IP address is using… so he can tell this IP to the other
player that needs to connect… I think that not all the people
is able to see his IP address… and this can be more useful
than some txt file that says "open command prompt, type ipconfig…"
or “open a console, type ifconfig…”

I know that a possible solution could be a public web server…
where all the players can meet… so the server can estabilish
a connection between the players… (like The Microsoft Zone)…
but I don’t have a web server or a static IP addess… :slight_smile:

and I can’t set up a server for a little game… but if a player
wants to play via Internet and he don’t knows how to retrieve
is public IP address… so I’d like to show it…

I hope it’s a bit more clear, now…
Sorry for my bad English… I hope you understand me… :-)> On Sat, 2004-04-10 at 14:19, Olivier Fabre wrote:

On 10/04/2004, SkunkGuru, you wrote:

I’d like to show the player is local IP address… any idea ?

I don’t know what you want the IP address for. But, it might not be as
useful as you think it is.


Bye!
Skunkguru.