nikunjb removed a comment on issue #41: [NET-405] Support for IPv6 in 
SubnetUtils
URL: https://github.com/apache/commons-net/pull/41#issuecomment-531968050
 
 
   Following patch fixes the IPV4 isInRange() regression reported above.
   
   `diff --git a/src/main/java/org/apache/commons/net/util/IP4Subnet.java 
b/src/main/java/org/apache/commons/net/util/IP4Subnet.java
   index 72d787d8..6f6202cc 100644
   --- a/src/main/java/org/apache/commons/net/util/IP4Subnet.java
   +++ b/src/main/java/org/apache/commons/net/util/IP4Subnet.java
   @@ -216,7 +216,7 @@ public final class IP4Subnet extends 
SubnetUtils.SubnetInfo
    
        /**
         * Returns {@code true} if the parameter {@code address} is in the 
range of usable endpoint addresses for this subnet.
   -     * This excludes the network and broadcast addresses.
   +     * This excludes the network and broadcast addresses if 
inclusiveHostCount is false.
         *
         * @param address a dot-delimited IPv4 address, e.g. "192.168.0.1"
         * @return {@code true} if in range, {@code false} otherwise
   @@ -229,7 +229,7 @@ public final class IP4Subnet extends 
SubnetUtils.SubnetInfo
    
        /**
         * Returns {@code true} if the parameter {@code address} is in the 
range of usable endpoint addresses for this subnet.
   -     * This excludes the network and broadcast addresses.
   +     * This excludes the network and broadcast addresses if 
inclusiveHostCount is false.
         *
         * @param address an IPv4 address in binary
         * @return {@code true} if in range, {@code false} otherwise
   @@ -239,7 +239,13 @@ public final class IP4Subnet extends 
SubnetUtils.SubnetInfo
        {
            long addLong = address & UNSIGNED_INT_MASK;
    
   -        return (addLong > networkLong()) && (addLong < broadcastLong());
   +        long n = networkLong();
   +        long b = broadcastLong();
   +
   +        long low = inclusiveHostCount ? n - 1: n;
   +        long high = inclusiveHostCount ? b + 1 : b;
   +        
   +        return (addLong > low) && (addLong < high);
        }
    
        /**
   diff --git a/src/main/java/org/apache/commons/net/util/SubnetUtils.java 
b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
   index 3a7093fd..ad4787b0 100644
   --- a/src/main/java/org/apache/commons/net/util/SubnetUtils.java
   +++ b/src/main/java/org/apache/commons/net/util/SubnetUtils.java
   @@ -197,7 +197,6 @@ public class SubnetUtils
    
            /**
             * Returns {@code true} if the parameter {@code address} is in the 
range of usable endpoint addresses for this subnet.
   -         * This excludes the network and broadcast addresses if the address 
is IPv4 address.
             *
             * @param address a dot-delimited IPv4 address, e.g. "192.168.0.1", 
or
             * a colon-hexadecimal IPv6 address, e.g. "2001:db8::ff00:42:8329"
   @@ -207,7 +206,6 @@ public class SubnetUtils
    
            /**
             * Returns {@code true} if the parameter {@code address} is in the 
range of usable endpoint addresses for this subnet.
   -         * This excludes the network and broadcast addresses if the address 
is IPv4 address.
             *
             * @param address the address to check
             * @return {@code true} if it is in range
   diff --git a/src/test/java/org/apache/commons/net/SubnetUtilsTest.java 
b/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
   index b93e3b10..f5d856d6 100644
   --- a/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
   +++ b/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
   @@ -203,6 +203,7 @@ public class SubnetUtilsTest extends TestCase {
            info = utils.getInfo();
            assertEquals("255.255.255.255", info.getNetmask());
            assertEquals(1, info.getAddressCount());
   +        assertTrue(info.isInRange("192.168.0.1"));
    
            new SubnetUtils("192.168.0.1/1");
        }
   `

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to