Skip to content

Commit b3829e5

Browse files
committed
CLOUDSTACK-6020 ipv4 address can be a larger number then
Interger.MAX_VALUE
1 parent 3989d6c commit b3829e5

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

utils/src/com/cloud/utils/net/Ip.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public String toString() {
5656
}
5757

5858
public boolean isIp4() {
59-
return ip < Integer.MAX_VALUE;
59+
return ip <= 2L * Integer.MAX_VALUE + 1;
6060
}
6161

6262
public boolean isIp6() {
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.utils.net;
18+
19+
import static org.junit.Assert.assertEquals;
20+
21+
import org.junit.Test;
22+
23+
public class IpTest {
24+
25+
@Test
26+
public void testUltimate() {
27+
Ip max = new Ip(2L * Integer.MAX_VALUE +1 );
28+
assertEquals("Maximal address not created", "255.255.255.255", max.addr());
29+
}
30+
@Test
31+
public void testTurningOfTheCentury() {
32+
Ip eve = new Ip(Integer.MAX_VALUE);
33+
assertEquals("Minimal address not created", "127.255.255.255", eve.addr());
34+
Ip dawn = new Ip(Integer.MAX_VALUE + 1L);
35+
assertEquals("Minimal address not created", "128.0.0.0", dawn.addr());
36+
}
37+
@Test
38+
public void testStart() {
39+
Ip min = new Ip(0);
40+
assertEquals("Minimal address not created", "0.0.0.0", min.addr());
41+
}
42+
43+
}

0 commit comments

Comments
 (0)