# 2 Networking questions

This topic is 5067 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I have two networking questions, the first is much easier then the second. I've been looking through documentation but because of the .net framework help getting in the way of basic socket programming my search has been less then fruitful. 1- I'm looking for a function(or set of functions) that can receive a hostname or socket_addr and convert it into a string of characters representing an IP address. example:
// something like
char my_ip_string[256];
hosttoip("www.gamedev.net", &my_ip_string)
// my_ip_string = "123.45.67.8910"


2- This one I beleive will be more difficult if not impossible. I would like to enumerate (fill a list) will the IP's of all the computers on a windows network. To be honest I have no idea where to begin. All I really need is a push in the right direction, so if you would rather post a tutorial then code that's perfectly fine. Thanks.

##### Share on other sites
gethostbyname() iirc is the function for 1.

For 2, there's possibly a nice windows function to do such a thing, but more than likely there's various nasty ways. I will search for the easy way. [edit: ah, msdn has the NetBIOS SDK documentation. It jogged my memory that NetBIOS is transport independant, so a host on the windows network is not guaranteed to have an IP address.]

##### Share on other sites
http://www.gamedev.net/community/forums/topic.asp?topic_id=159255

-cb

##### Share on other sites
After doing some research last night I realized that I didn't really ask the right question. The function I was looking for in question 1 was inet_toa().

For the second question, I really don't need the IP's of all the other comps on the network, just the hostname. In my 'Join Multiplayer Game' window, I would like to supply a list of hosts on the local network to join to save the user the time to type in the hostname or IP themselves. The nmap.org site looks promissing but seems like overkill for my simple problem. I was hoping that a simple windows control existed that would enumerate other comps on the network, but I guess not?

##### Share on other sites
On the same line of questions,

If I use gethostbyname() on my computer I get something like "computername.telus.net" but if I use it on other people's machine I just get "computername". How do I make sure I get the complete name?

##### Share on other sites
So essentially you are looking to set up a way for players to play over LAN?

There must be a way since almost every commercial game that supports multiplayer has a LAN option where you can see all the games hosted over the LAN.

I am interested in this too, if anybody has a tutorial for this :P since i suppose its quite a common thing to do.

##### Share on other sites
You don't want a list of ALL MACHINES, right? You only want a list of all machines running your game (and, potentially, only those that have started to Host a Game).

The way this is done in a LAN is by using UDP broadcast. When hosting a game, send a broadcast packet every 4 seconds containing the game name and other stats. On the browse screen for the clients, listen to all broadcasts on whatever port you're using, and use the address you get from ::recvfrom() to identify the hosting machine, and the data in the packet to identify the name and stats of the game.

• 18
• 11
• 16
• 9
• 51
• ### Forum Statistics

• Total Topics
631396
• Total Posts
2999790
×