mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
8277608: Address IP Addressing
Reviewed-by: dfuchs, rhalade, michaelm
This commit is contained in:
parent
ddb106be7a
commit
243c76f59f
4 changed files with 288 additions and 12 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -137,7 +137,7 @@ class HostPortrange {
|
|||
}
|
||||
this.ipv4 = this.literal = ipv4;
|
||||
if (ipv4) {
|
||||
byte[] ip = IPAddressUtil.textToNumericFormatV4(hoststr);
|
||||
byte[] ip = IPAddressUtil.validateNumericFormatV4(hoststr);
|
||||
if (ip == null) {
|
||||
throw new IllegalArgumentException("illegal IPv4 address");
|
||||
}
|
||||
|
|
|
@ -1254,7 +1254,11 @@ public sealed class InetAddress implements Serializable permits Inet4Address, In
|
|||
private byte [] createAddressByteArray(String addrStr) {
|
||||
byte[] addrArray;
|
||||
// check if IPV4 address - most likely
|
||||
addrArray = IPAddressUtil.textToNumericFormatV4(addrStr);
|
||||
try {
|
||||
addrArray = IPAddressUtil.validateNumericFormatV4(addrStr);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
return null;
|
||||
}
|
||||
if (addrArray == null) {
|
||||
addrArray = IPAddressUtil.textToNumericFormatV6(addrStr);
|
||||
}
|
||||
|
@ -1470,13 +1474,19 @@ public sealed class InetAddress implements Serializable permits Inet4Address, In
|
|||
}
|
||||
|
||||
// if host is an IP address, we won't do further lookup
|
||||
if (Character.digit(host.charAt(0), 16) != -1
|
||||
if (IPAddressUtil.digit(host.charAt(0), 16) != -1
|
||||
|| (host.charAt(0) == ':')) {
|
||||
byte[] addr = null;
|
||||
byte[] addr;
|
||||
int numericZone = -1;
|
||||
String ifname = null;
|
||||
// see if it is IPv4 address
|
||||
addr = IPAddressUtil.textToNumericFormatV4(host);
|
||||
try {
|
||||
addr = IPAddressUtil.validateNumericFormatV4(host);
|
||||
} catch (IllegalArgumentException iae) {
|
||||
var uhe = new UnknownHostException(host);
|
||||
uhe.initCause(iae);
|
||||
throw uhe;
|
||||
}
|
||||
if (addr == null) {
|
||||
// This is supposed to be an IPv6 literal
|
||||
// Check if a numeric or string zone id is present
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -468,7 +468,7 @@ public final class SocketPermission extends Permission
|
|||
if (!host.isEmpty()) {
|
||||
// see if we are being initialized with an IP address.
|
||||
char ch = host.charAt(0);
|
||||
if (ch == ':' || Character.digit(ch, 16) != -1) {
|
||||
if (ch == ':' || IPAddressUtil.digit(ch, 16) != -1) {
|
||||
byte ip[] = IPAddressUtil.textToNumericFormatV4(host);
|
||||
if (ip == null) {
|
||||
ip = IPAddressUtil.textToNumericFormatV6(host);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue