SDLnet: get my own IP

AFAIK, it is ISO 8601:1988 which defines the preferred way of representing
the time as
YYYYMMDD or YYYY-MM-DD.

There are several national organizations for standardization which adopted it:
European Norm: EN 28601:1992
USA Standard: ANSI X3.30-1985(R1991)
USA Standard: NIST FIPS 4-1
Japan: JIS X 0301-1992
Canada: CSA Z234.5:1989
Australia: AS 3802:1997
South Africa: ARP 010:1989

And btw, in Germany, the traditional way is DD.MM.YYYY

This thread is getting far off topic and we should stop it.On Thursday 21 March 2002 16:50, David Olofson wrote:

On Thursday 21 March 2002 13:02, James wrote:

On Thu, Mar 21, 2002 at 01:53:53PM +0300, Alexander Sabourenkov wrote:
| Martijn Melenhorst wrote:
| >personally, I favour MSB order, since humans use MSD also (Most
| >Significant Decimal): If I want to write onehundred-eighty-three, I
| > write the digits in that order: 1, 8, 3, which makes 183. So, in
| > our decimal digits standard, the most-significant-decimal is first
| > too.
|
| Now think of people who write right-to-left, mostly arabic countries.

And add to that the three ways of representing dates:

Europe: DD/MM/YYYY
US : MM/DD/YYYY
China : YYYY/MM/DD

BTW, we seem to use the chinese variant most of the time in Sweden…


Johannes Schmidt

< http://libufo.sourceforge.net > Your widget set for OpenGL

At 13:45 21.03.2002 +0100, you wrote:

And add to that the three ways of representing dates:

Europe: DD/MM/YYYY
US : MM/DD/YYYY
China : YYYY/MM/DD

Actually I always learned that Europe uses DD-MM-YYYY. (And that there’s no
such thing as DD/MM/YYYY) It’s a shame I see the confusing DD/MM/YYYY so
often nowadays :frowning:
In Germany the standard is DD.MM.YYYY … just for your information …
St0fF 64

David Olofson wrote:> On Thursday 21 March 2002 15:12, Alexander Sabourenkov wrote:

[…]

And use of word ‘server’ excludes peer-to-peer stuff, for me at least.

ICQ would be one example of a protocol where you can have both p2p and
client/server interaction going on…

That’s true, I meant that if a particular program is referred to as ‘server’,
that implies client-server model is being discussed. Not that it can’t be used
both as a client in client-server model and p2p network participant.

David Olofson wrote:

[…]

And use of word ‘server’ excludes peer-to-peer stuff, for me at least.

ICQ would be one example of a protocol where you can have both p2p and
client/server interaction going on…

That’s true, I meant that if a particular program is referred to as
’server’,
that implies client-server model is being discussed. Not that it can’t be
used
both as a client in client-server model and p2p network participant.

With so much discussion of client-server models and media coverage of it’s
use in the Quake series of games, people tend to think that’s the only
meaning ‘server’ has, but that’s not the case. In a peer to peer situation,
you still have to have one machine contact the other. Which one should it
be? It can be either one, but one of them has to do it. Once one does,
they can be considered the client, and the other computer is the server (or
host if you prefer).

Consider a different example: the game of Tennis. One person ‘serves’ the
ball to the other player. He is the server. That doesn’t imply that Tennis
is a client-server model game. It’s more of a peer to peer model game.

Exactly what this guy meant originally with his post when he mentioned
"server" won’t be known for sure unless he tells us. It doesn’t really
matter anyway I don’t think. I know I don’t care anymore, heh. :slight_smile:

----- Original Message -----
From: lxnt@caravan.ru (Alexander Sabourenkov)
To:
Sent: Thursday, March 21, 2002 12:57 PM
Subject: Re: [SDL] SDLnet: get my own IP

On Thursday 21 March 2002 15:12, Alexander Sabourenkov wrote:

James wrote:> On Thu, Mar 21, 2002 at 05:12:09PM +0300, Alexander Sabourenkov wrote:

| >You are assuming that ‘tell’ refers only to his game code communicating
| >with
| >his opponent’s computer. However, that’s completely wrong I’m sure.
| >There’s many ways he could ‘tell’ his opponent where he has to connect to,
| >including IRC, ICQ, email, a telephone call, etc. Watch out for those
| >assumptions! :slight_smile:
|
|
| Well, he states pretty clear that he wants “to show the his ip to player
| with the server”.
|
| Can’t really imagine his server telling anything anyone w/o IP connectivity
| :).

The way I read it is the following:

The game runs in two modes : “client” and “server”.
You designate one PC to be a “server”.
All other PCs that want to take part in the game are “clients”.

I.e exactly the same way webserver/browsers work and Quake III works.

On the server PC you tell the game to run as a server. It then, to be
helpful to you, prints out “My IP address is x.x.x.x” so you can then
tell this to people who want to connect to you - just like there are
lists of Quake III servers announced on IRC channels, etc.

Quick investigation of QuakeForge source revealed that it gets the local ip
by:

  1. creating an UDP socket with call " socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP); "
  2. calling gethostname()
  3. calling gethostbyname() giving it the result of p.2
  4. calling getsockname() on the created socket, supplying the buffer previously filled in p.3
  5. printing the resulting IP address (from p.3) and port (from p.4)

Beware: this should give unpredictable results. Espesially on multiple-interfaced systems.
Actually, linux man page on getsockname states plainly that a name will be returned, and one from
FreeBSD says that NULL will be returned for PF_INET sockets, and it does not.

Finally, i’ve messed around with Google, and it seems that Windows people use similar to the
above technique.

Summary: If you’re going to run a server on a gateway/router, bind the server to specific interfaces.
Know what you’re doing.

./lxnt

Daniel Stiefelmaier wrote:

That was not my question…
Why don’t ALL CPUs use the “correct” order, where the MSB is on the left?
(This is “correct” in my eyes because you always read numbers from left to
right…)

History, backwards compatibility, and the need to reduce hardware costs
and transister counts back in the 50s, 60s, and 70s. Back when in the
50s and 60s transistors cost a buck ($1US) each and when you figure the
value of a buck then is equivalent to between $5US or %10US now… And
then you get into the 70s and LSI and MSI parts where you only had a few
dozen to a few hundred transistors on a chip… Well, anything that made
a computer cost less or fit on a smaller number of chips was a good
thing. And putting the LSB of a number in the low address reduces the
cost of serially processing a 16 bit or 32 bit number through a 1 (yes
they did have 1 bit wide ALUs), 4 or 8 bit ALU and you can see that
there were very good reasons to do it that way.

Once locked into those choices there were good reasons to stick with
them and as transistors got cheaper and busses got wider there was no
reason to change.

As usuall, the answer to questions like this is that it made sense to do
it that way back in the bad ol’ days.

		Bob P.-- 

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

  • Bob Pendleton is seeking contract +
  • and consulting work. Find out more +
  • at http://www.jump.net/~bobp +
    ±-----------------------------------+

Alexander Sabourenkov wrote:

Martijn Melenhorst wrote:

personally, I favour MSB order, since humans use MSD also (Most
Significant Decimal): If I want to write onehundred-eighty-three, I
write the digits in that order: 1, 8, 3, which makes 183. So, in our
decimal digits standard, the most-significant-decimal is first too.

Now think of people who write right-to-left, mostly arabic countries.

IIRC, Europeans copied the Arab decimal numbering system The Arabs read
right to left and wrote their numbers least significant digit on the
right so the the low order digit is the first digit as they read right
to left. The Europeans copied the numerials and the number ordering so
they see the high order digit as they read left to right.

The whole number ordering thing in human languages is another arbitrary
accident of history. Not worth bothering about, really.

	Bob Pendleton> 

./lxnt


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


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

  • Bob Pendleton is seeking contract +
  • and consulting work. Find out more +
  • at http://www.jump.net/~bobp +
    ±-----------------------------------+

Well, he states pretty clear that he wants “to show the his ip to player
with the server”.

Yeah, it really looks like I SWAPPED BYTES when i wrote this, heh! :wink:
It shold be:
I want to show the player with the server his ip…
Or like that… Coul’nt figure out the correct grammar…

Well, perhaps you all know AoE 2.
If you start a Networkgame, then you are the “server” and there is a button
that shows your ip.
I guess the guys of ensemble use eth0, i didn’t think of lokal ip’s that are
worthless behind a router…
This is just ment for LAN-Games, so that the player with the server can tell
the others where they have to connect.

I wanted to know if there is a system independent way to get the ip of eth0,
or, if not suggest to implement this in SDL…

thanx…
Stiefel

James wrote:

Can you use the ‘normal’ network functions like gethostbyname()
and htons() with SDL_net?

Nope. There are a lot of important network functions that are not brought
out.

The following was posted last November between the releases of SDL_net 1.2.2
and 1.2.3:

Sam Lantinga wrote:

You should probably use sockets directly. They’re more or less
supported across UNIX, Windows, BeOS, and MacOS X. SDL_net was
specifically supposed to address the problem of init/cleanup and
to work on MacOS classic. I’m not especially impressed by the
result.

'nuff said … :slight_smile:

  • Randi

Regimental Command
Generic Armored Combat System
http://regcom.sourceforge.net

whee!

here is the closest you can come, but it requires gethostname and a DNS server entry for the gotten hostname…

assuming SDL and SDL_net are initialized before this:

char localhost[256];	
if((gethostname(localhostname, 256)>=0))
{
	printf("Local Host: %s\n",localhostname);
	printf("Resolving %s\n",localhostname);
	if(SDLNet_ResolveHost(&ip,localhostname,0)==-1)
		printf("Could not resolve host \"%s\"\n%s\n",localhostname,SDLNet_GetError());
	else
	{
		// perform a byte endianess correction for the next printf
		ipaddr=SDL_SwapBE32(ip.host);

		// output the IP address nicely
		printf("Local IP Address : %d.%d.%d.%d\n",
				ipaddr>>24,
				(ipaddr>>16)&0xff,
				(ipaddr>>8)&0xff,
				ipaddr&0xff);
	}
}

you could also append the domainname to the localhostname string perhaps, and try it both ways…
if one way fails try it with the domainname.
just be aware that many computers never have a domainname set (or wrongly set)–
-==-
Jon Atkins
http://jcatki.2y.net/