Skip to content

Commit 326e6ea

Browse files
committed
Add ipv4 handling back
1 parent 7c6a5e1 commit 326e6ea

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/main/java/com/maxmind/db/Networks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public DatabaseRecord<T> next() {
8484
// We do this because uses of includeAliasedNetworks will get IPv4 networks
8585
// from the ::FFFF:0:0/96. We want to return the IPv4 form of the address
8686
// in that case.
87-
if (isInIpv4Subtree(ip)) {
87+
if (!this.includeAliasedNetworks && isInIpv4Subtree(ip)) {
8888
ip = Arrays.copyOfRange(ip, 12, ip.length);
8989
prefixLength -= 96;
9090
}

src/main/java/com/maxmind/db/Reader.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,15 @@ public <T> Networks<T> networksWithin(
307307
int prefixLength = network.getPrefixLength();
308308

309309
if (this.metadata.getIpVersion() == 6 && ipBytes.length == IPV4_LEN) {
310-
ipBytes = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
311-
ipBytes[0], ipBytes[1], ipBytes[2], ipBytes[3] };
310+
if (includeAliasedNetworks) {
311+
// Convert it to the IP address (in 16-byte from) of the IPv4 address.
312+
ipBytes = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
313+
-1, -1, // -1 is for 0xff.
314+
ipBytes[0], ipBytes[1], ipBytes[2], ipBytes[3]};
315+
} else {
316+
ipBytes = new byte[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
317+
ipBytes[0], ipBytes[1], ipBytes[2], ipBytes[3] };
318+
}
312319
prefixLength += 96;
313320
}
314321

src/test/java/com/maxmind/db/ReaderTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,12 @@ public networkTest(String network, int prefix,String database, String[] expecte
258258
0,
259259
"mixed",
260260
new String[]{
261-
// ::/96
262-
"1.1.1.1/32",
263-
"1.1.1.2/31",
264-
"1.1.1.4/30",
265-
"1.1.1.8/29",
266-
"1.1.1.16/28",
267-
"1.1.1.32/32",
261+
"0:0:0:0:0:0:101:101/128",
262+
"0:0:0:0:0:0:101:102/127",
263+
"0:0:0:0:0:0:101:104/126",
264+
"0:0:0:0:0:0:101:108/125",
265+
"0:0:0:0:0:0:101:110/124",
266+
"0:0:0:0:0:0:101:120/128",
268267
"0:0:0:0:0:1:ffff:ffff/128",
269268
"0:0:0:0:0:2:0:0/122",
270269
"0:0:0:0:0:2:0:40/124",

0 commit comments

Comments
 (0)