[gameprogrammer] Re: "Network Byte Order" IP's to dotted-triplet format

Hey Jake,

I'm not familiar with that networking library, but if you have a
network byte order number, you can use ntohl() to convert it to host
byte order and then pull out the numbers you want.  A snippet from my
server is:

int addr;
char* place;
...
addr = ntohl(new_saddr.sin_addr.s_addr);
sprintf(place,"%d.%d.%d.%d",(addr>>24)&0xff,(addr>>16)&0xff,(addr>>8)&0xff,(addr)&0xff);

-Jeremy

On Thu, 11 Nov 2004 09:58:41 +1300, Jake The Snake Briggs
<jacob_briggs@xxxxxxxxxxxxxxx> wrote:
> Hi all
> I need to get the IP address of a socket. I am writing a multiplayer
> game, basicly its "snake", but multiplayer. I want to write 3 programs,
> a client game, a server, and a master server. I want to be able to tell
> the master server to give me a list of all the game servers that are
> registered with it. So far i have a crappy game server written, that can
> register with the master server. I have a really crappy game client
> written. I have the simple master sever 95% finished, and thats where my
> problem lies.
> I am using this function :
> 
> IPaddress *NET2_TCPGetPeerAddress(int socket);
> 
> because i am using Bob Pendletons NET2_SDL library. This fills the
> specified IPaddress struct with the IP and Port of the socket in
> "Network Byte Order" format. So i think (after a bit of googleing) i
> understand what that is, and why its used.
> At the moment i can go
> telnet <masterserverip> <masterserverport>
> then type
> "servers"
> and i get back a list of server ip's and ports. But I want them to be
> the dotted triplet format, like 192.168.0.2 rather than 18328373673 or
> whatever it is. How would one go about transforming Network Byte Order
> to dotted format?
> 
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> 
> 


-- 
Jeremy Vanseader - Madox Labs
http://madox.ca           
madoxlabs@xxxxxxxxx


---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html


Other related posts: