Commons Net
  1. Commons Net
  2. NET-282

Improvement to isInRange method in SubnetUtil.SubnetInfo class

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      All

      Description

      I am very pleased to see that the isInRange bug has been corrected in 2.1. I would like to suggest the additional change to the isInRange method (or perhaps some polymorphism).

      Current:

      private boolean isInRange(int address)

      { return ((address-low()) <= (high()-low())); }

      Proposed Fix (I saw in another bug ticket):

      private boolean isInRange(int address) {
          int normal = address - this.low;
          return (normal >= 0 && normal <= (this.high - this.low))
      }
      

      I would argue that the network address and the broadcast address, while not viable IPs to be assigned, are still technically in the range of the network, so I would request that the method be updated as follows (or perhaps a new method or flag you could pass to determine if you want to include the network and broadcast address):

      private boolean isInRange(int address) {
          int normal = address - this.network;
          return (normal >= 0 && normal <= (this.broadcast - this.network))
      }
      

      Polymorphism route:

      private boolean isInRange(int address) {
          return isInRange(address, false);
      }
      
      private boolean isInRange(int address, boolean fullRange) {
          int myLow;
          int myHigh;
      
          if (fullRange) {
              myLow = this.network;
              myHigh = this.broadast;
          }
          else {
              myLow = this.low;
              myHigh = this.high;
          }
      
          int normal = address - myLow;
          return (normal >= 0 && normal <= (myHigh - myLow));
      }
      

        Activity

        Sebb made changes -
        Fix Version/s 2.2 [ 12315361 ]
        Fix Version/s 2.1 [ 12313001 ]
        Rory Winston made changes -
        Status Open [ 1 ] Closed [ 6 ]
        Fix Version/s 2.1 [ 12313001 ]
        Fix Version/s 3.0 [ 12314126 ]
        Resolution Fixed [ 1 ]
        Rory Winston made changes -
        Fix Version/s 3.0 [ 12314126 ]
        Scott Davis made changes -
        Field Original Value New Value
        Priority Major [ 3 ] Minor [ 4 ]
        Scott Davis created issue -

          People

          • Assignee:
            Unassigned
            Reporter:
            Scott Davis
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development