Subnet Mask & Searching ...

Miscellaneous Forums/General Discussion/Subnet Mask & Searching ...

I recently had to modify some code for a multiplayer version of Aerial Antics to scan a LAN with a subnet mask of 255.255.0.0, as opposed to the typical 255.255.255.0. The thing is that this essentially leads to a search of 65,000 ip addresses and the wait is painful. I've noticed other software capable of detecting the games on this same LAN much quicker. Does anyone have any notion of how to reduce the time needed to scan a LAN with subnet mask of 255.255.0.0?

How are you scanning it? One IP at a time, or using an IP broadcast address? If you're broadcasting, the number of hosts you're sending to shouldn't make any difference.

Incidentally 255.255.255.0 isn't a "typical" subnet mask, although it's fairly common on low-security 172.16.x.x and 192.168.x.x LANs - it depends entirely on how you have your network set up.

Well, 255.255.255.0 is the subnet mask that BlitzPlay assumes the network to have. I had to go in an modify it to compensate for the subnet maske 255.255.0.0 which two laptops I have use when connected in a wireless peer to peer network.

Well the problem is that Blitz doesn't allow you to obtain the subnet mask (unless you want to parse the output of ipconfig).

So if you could obtain the value of the subnet mask that would simplify the search?

Like I said, it depends on how you're already searching, and how the network is set up.

Obtaining the subnet mask will allow you to get the broadcast address for your current subnet. If you just want to try it out on your current network, it's fairly easy because if you know the subnet address is 255.255.0.0 then the associated broadcast IP is going to be x.x.255.255, where the two x's represent the octets in your ip address (so if your IP address is 192.168.17.22, and your subnet mask is 255.255.0.0 then the broadcast address would be 192.168.255.255).

With that broadcast ip address though, how would I find and ping the host computer any quicker with 255 * 255 possiblities still remaining?

You just send whatever packet to the broadcast address (which broadcasts the packet to all hosts on the subnet). You then listen for correct responses - the IPs that respond are the servers.

Ah! I'll see if I can get an implementation of that working. Thanks!

Right, so I need a way to pull the subnet mask as you said. So far no searches have turned anything up. Without looking in Windows (cheating) how can you pull the subnet? Is there an easy way to do this in .dll form using some windows programming? I'm sure there is.

Or ... Mark ... yes hello you there! Good sir, might you add a bit more network functionality to Blitz3D in this regard?

Of course ... then would it really be that bad to just do a broadcast for each subnet? How many networks are there with 24 bits or 32 bits of variable ip? Is the worst case scenario most likely a 255.255.0.0?

Actually the worst case scenario is 255.0.0.0 for 10.x.x.x based (A class) LANs. You could also use the general IP broadcast address of 255.255.255.255, but there's a chance that such packets will by dropped by interconnected bridges/switches, and definitely by any routers.

As for getting the subnet mask on win32 - beats me.

FlameDuck:

Thanks a million, I knew there had to be someway to do this quicker but this was the first I've heard of the reserved broadcast address. I got it working with my own C and B class networks. In order to do it right I would need a way to extract the subnet mask and I'll look into that later but I think so long as I can get it working on the typical networks without strange subnet masks such as 255.255.255.252 or something like that I'll be good to go.

To anyone using BlitzPlay or other networking libs, this is something to lookout for. Surreal's code typically blows me away but this is a clear example of something even he didn't know so I don't feel too bad ;)

BTW, the 255.255.255.255 global broadcast doesn't seem to work at all. You have to get the network portion of the ip address and then append the broadcast octets to it.

I think it's saved in the registry somewhere. Though I'm not entirely sure where, or how reliable it is...

I seem to recall an API call within Win32 as well
GetTcpAddrTable() or something like that....

If you're targetting a cross-platform deployment (which I assume not, since you said Blitz3D), I'm not sure what the equivalents are on the Mac or Posix side...


[edit]
Here ya go...
http://msdn2.microsoft.com/en-us/library/aa365949.aspx

I posted my solution to this problem in the code archives BTW:

http://blitzmax.com/codearcs/codearcs.php?code=1988

I wrote a simple .dll in Visual C++ and then a simple (could be optimized as well) getBroadcastAddress() function in Blitz. Hope other people find it useful ...

heh AWESOME. This is one thing I couldn't get working before. Nice one Jeremy, and Nice one FlameDuck! :)