Jump to content
  • Advertisement
Sign in to follow this  
Gagyi

Determining subnet mask

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

In my LAN game, I have to determine the correct subnet mask of the largest portion of the LAN as possible. I noticed that my switch doesnt want to forward 255.255.255.255 packets. Even the computer wich sent it doesnt get it. So I send a packet with to the 192.255.255.255 address, and than to the 192.168.255.255 address and so on. When the sender computer gets the message back, I have the correct subnet mask. (this is a working algorithm) People said that this is a crappy technique. Is there a better way to do it? Or I *must* ask the user for the subnet mask?

Share this post


Link to post
Share on other sites
Advertisement
The number of addresses you need to search is covered by standard.

Quote:
The private address space specified in RFC 1918 is defined by the following address prefixes:


10.0.0.0/8 (10.0.0.0, 255.0.0.0)

Allows the following range of valid IPv4 unicast addresses: 10.0.0.1 to 10.255.255.254. The 10.0.0.0/8 address prefix has 24 host bits that can be used for any addressing scheme within the private organization.


172.16.0.0/12 (172.16.0.0, 255.240.0.0)

Allows the following range of valid IPv4 unicast addresses: 172.16.0.1 to 172.31.255.254. The 172.16.0.0/12 address prefix has 20 host bits that can be used for any addressing scheme within the private organization.


192.168.0.0/16 (192.168.0.0, 255.255.0.0)

Allows the following range of valid IPv4 unicast addresses: 192.168.0.1 to 192.168.255.254. The 192.168.0.0/16 address prefix has 16 host bits that can be used for any addressing scheme within the private organization.


So this is all you will ever need to search, unless someone is deliberately trying to break IP namespaces (not your problem, is strongly frowned upon as well).

Broadcasting over WAN outside of these address ranges is not supported by internet providers, since it's too easy to flood entire internet with nonsense.

Share this post


Link to post
Share on other sites
Sub-netting on slices other than the class A/B/C nets is done all the time; it is not "frowned upon."

If you want to broadcast to the current subnet, you can broadcast to 255.255.255.255 -- the router out from your subnet will know to not pass this packet along, but it will reach everyone on your current subnet. No searching necessary. If your switch doesn't forward 255.255.255.255, it is broken (or it's configurable, and you need to configure it).

There are, apparently, some cases where broadcasting to the configured subnet will reach other subnets on the greater LAN, but still be filtered at the WAN gateway; your best bet is to use platform specific methods to extract this configuration information if you need it (but that need is rare).

Also, make sure you turn on SO_BROADCAST -- if you don't, then you can't broadcast out the socket at all.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!