You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "SeHun Shin (Jira)" <ji...@apache.org> on 2020/02/17 16:27:00 UTC
[jira] [Created] (NET-679) SubnetUtils.SubnetInfo doesn't represent
lowAddress and highAddress.
SeHun Shin created NET-679:
------------------------------
Summary: SubnetUtils.SubnetInfo doesn't represent lowAddress and highAddress.
Key: NET-679
URL: https://issues.apache.org/jira/browse/NET-679
Project: Commons Net
Issue Type: Bug
Affects Versions: 3.6
Environment: JDK 1.8
Gradle
MacOS Mojave
Reporter: SeHun Shin
This is my test case.
CIDR '10.213.160.0/16' should be contain 10.213.0.0 and 10,213.255.255, but shouldn't.
{code:java}
// 코드 자리 표시자
@Test
void when16bitIsGiven_thenReturnTrue() {
// GIVEN
final String CIDR = "10.213.160.0/16";
SubnetInfo subnetInfo = new SubnetUtils(CIDR).getInfo();
final String[] givenIPs = {"10.213.0.0", "10.213.160.0", "10.213.255.255"};
// WHEN and THEN
assertThat(subnetInfo.getLowAddress()).isEqualTo(givenIPs[0]);
assertThat(subnetInfo.getHighAddress()).isEqualTo(givenIPs[2]);
Stream.of(givenIPs).forEach(ip -> {
assertThat(subnetInfo.isInRange(ip)).isTrue();
});
}
{code}
{panel}
CIDR to IP Range{panel}
{panel}
h3. Result
||CIDR Range|10.213.160.0/16|
||Netmask|255.255.0.0|
||Wildcard Bits|0.0.255.255|
||First IP|10.213.0.0|
||Last IP|10.213.255.255|
||Total Host|65536|
{panel}
I think we should care about 'SubnetInfo.low' and 'SubnetInfo.high'.
{code:java}
// 코드 자리 표시자
public final class SubnetInfo { ...
private int low() {
return (isInclusiveHostCount() ? network() :
broadcastLong() - networkLong() > 1 ? network() + 1 : 0);
} private int high() {
return (isInclusiveHostCount() ? broadcast() :
broadcastLong() - networkLong() > 1 ? broadcast() -1 : 0);
} public boolean isInRange(int address) {
long addLong = address & UNSIGNED_INT_MASK;
long lowLong = low() & UNSIGNED_INT_MASK;
long highLong = high() & UNSIGNED_INT_MASK;
return addLong >= lowLong && addLong <= highLong;
}
...
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)