Skip to content

Commit 6655daf

Browse files
author
Rory Winston
committed
NET-262: Throw an exception if netmask bits are not in (0,x]
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/net/branches/NET_2_0@761980 13f79535-47bb-0310-9956-ffa450edef68
1 parent e9a769f commit 6655daf

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/main/java/examples/SubnetUtilsExample.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
public class SubnetUtilsExample {
3131

3232
public static void main(String[] args) {
33-
String subnet = "192.168.0.1/29";
33+
String subnet = "192.168.0.3/31";
3434
SubnetUtils utils = new SubnetUtils(subnet);
3535
SubnetInfo info = utils.getInfo();
3636

@@ -48,9 +48,9 @@ public static void main(String[] args) {
4848
Integer.toBinaryString(info.asInteger(info.getNetworkAddress())));
4949
System.out.printf("Broadcast Address:\t\t%s\t[%s]\n", info.getBroadcastAddress(),
5050
Integer.toBinaryString(info.asInteger(info.getBroadcastAddress())));
51-
System.out.printf("First Usable Address:\t\t%s\t[%s]\n", info.getLowAddress(),
51+
System.out.printf("Low Address:\t\t\t%s\t[%s]\n", info.getLowAddress(),
5252
Integer.toBinaryString(info.asInteger(info.getLowAddress())));
53-
System.out.printf("Last Usable Address:\t\t%s\t[%s]\n", info.getHighAddress(),
53+
System.out.printf("High Address:\t\t\t%s\t[%s]\n", info.getHighAddress(),
5454
Integer.toBinaryString(info.asInteger(info.getHighAddress())));
5555

5656
System.out.printf("Total usable addresses: \t%d\n", info.getAddressCount());

src/main/java/org/apache/commons/net/util/SubnetUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private String format(int[] octets) {
199199
* Convenience function to check integer boundaries
200200
*/
201201
private int rangeCheck(int value, int begin, int end) {
202-
if (value >= begin && value <= end)
202+
if (value > begin && value <= end) // (0,nbits]
203203
return value;
204204

205205
throw new IllegalArgumentException("Value out of range: [" + value + "]");

0 commit comments

Comments
 (0)