code: public static boolean isValidNetmask(byte[] segments)
  	{
  		boolean mustBeZero = false;
  		for (int i = 0; i < segments.length; i++)
  		{
  
  			// Valid segments: 0, 128, 192, 224, 240, 248, 252, 254, 255
  			switch (segments[i])
  			{
  				case -1:
  					if (mustBeZero)
  						return false;
  					break;
  				case 0:
  					if (mustBeZero)
  					{
  						break;
  					}
  				case -2:
  				case -4:
  				case -8:
  				case -16:
  				case -32:
  				case -64:
  				case -128:
  					if (!mustBeZero)
  						mustBeZero = true;
  					else
  					{
  						return false;
  					}
  					break;
  				default:
  					return false;
  			}
  		}
  
  		return true;
  	}
docs: Validates a netmask
  
  @param segments
  byte[] A signed byte array whose binary values represent the address
  
  @return boolean True if valid, otherwise false