Uploaded image for project: 'Commons Net'
  1. Commons Net
  2. NET-260

SubnetUtils.SubnetInfo.isInRange(...) returns incorrect values

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Duplicate
    • Affects Version/s: 2.0
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None

      Description

      SubnetUtils class handles IP addresses as int (which in Java is signed).
      isInRange() method does not take this into account:

      private boolean isInRange(int address) {
          return ((address-low()) <= (high()-low()));
      }
      

      In following code snippet isInRange() returns true, when clearly 120.0.0.0 is outside the range: 192.168.12.0 - 192.168.13.255
      (see http://compnetworking.about.com/od/workingwithipaddresses/a/cidr_notation.htm)

      String cidrNotation = "192.168.12.0/23";
      SubnetUtils.SubnetInfo info = new SubnetUtils(cidrNotation).getInfo();
      assertFalse(info.isInRange("120.0.0.0")); // fails
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                drone Andris Rauda
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: