8273243: Fix indentations in java.net.InetAddress methods
Reviewed-by: dfuchs, bpb
This commit is contained in:
parent
152e66923d
commit
0c1b16b75a
@ -657,46 +657,46 @@ public class InetAddress implements java.io.Serializable {
|
|||||||
*/
|
*/
|
||||||
private static String getHostFromNameService(InetAddress addr, boolean check) {
|
private static String getHostFromNameService(InetAddress addr, boolean check) {
|
||||||
String host = null;
|
String host = null;
|
||||||
try {
|
try {
|
||||||
// first lookup the hostname
|
// first lookup the hostname
|
||||||
host = nameService.getHostByAddr(addr.getAddress());
|
host = nameService.getHostByAddr(addr.getAddress());
|
||||||
|
|
||||||
/* check to see if calling code is allowed to know
|
/* check to see if calling code is allowed to know
|
||||||
* the hostname for this IP address, ie, connect to the host
|
* the hostname for this IP address, ie, connect to the host
|
||||||
*/
|
*/
|
||||||
if (check) {
|
if (check) {
|
||||||
@SuppressWarnings("removal")
|
@SuppressWarnings("removal")
|
||||||
SecurityManager sec = System.getSecurityManager();
|
SecurityManager sec = System.getSecurityManager();
|
||||||
if (sec != null) {
|
if (sec != null) {
|
||||||
sec.checkConnect(host, -1);
|
sec.checkConnect(host, -1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now get all the IP addresses for this hostname,
|
|
||||||
* and make sure one of them matches the original IP
|
|
||||||
* address. We do this to try and prevent spoofing.
|
|
||||||
*/
|
|
||||||
|
|
||||||
InetAddress[] arr = InetAddress.getAllByName0(host, check);
|
|
||||||
boolean ok = false;
|
|
||||||
|
|
||||||
if(arr != null) {
|
|
||||||
for(int i = 0; !ok && i < arr.length; i++) {
|
|
||||||
ok = addr.equals(arr[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//XXX: if it looks a spoof just return the address?
|
|
||||||
if (!ok) {
|
|
||||||
host = addr.getHostAddress();
|
|
||||||
return host;
|
|
||||||
}
|
|
||||||
} catch (SecurityException e) {
|
|
||||||
host = addr.getHostAddress();
|
|
||||||
} catch (UnknownHostException e) {
|
|
||||||
host = addr.getHostAddress();
|
|
||||||
// let next provider resolve the hostname
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* now get all the IP addresses for this hostname,
|
||||||
|
* and make sure one of them matches the original IP
|
||||||
|
* address. We do this to try and prevent spoofing.
|
||||||
|
*/
|
||||||
|
|
||||||
|
InetAddress[] arr = InetAddress.getAllByName0(host, check);
|
||||||
|
boolean ok = false;
|
||||||
|
|
||||||
|
if (arr != null) {
|
||||||
|
for (int i = 0; !ok && i < arr.length; i++) {
|
||||||
|
ok = addr.equals(arr[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//XXX: if it looks like a spoof just return the address?
|
||||||
|
if (!ok) {
|
||||||
|
host = addr.getHostAddress();
|
||||||
|
return host;
|
||||||
|
}
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
host = addr.getHostAddress();
|
||||||
|
} catch (UnknownHostException e) {
|
||||||
|
host = addr.getHostAddress();
|
||||||
|
// let next provider resolve the hostname
|
||||||
|
}
|
||||||
return host;
|
return host;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1136,7 +1136,7 @@ public class InetAddress implements java.io.Serializable {
|
|||||||
|
|
||||||
// create name service
|
// create name service
|
||||||
nameService = createNameService();
|
nameService = createNameService();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of the NameService interface based on
|
* Create an instance of the NameService interface based on
|
||||||
@ -1510,21 +1510,19 @@ public class InetAddress implements java.io.Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static InetAddress[] getAddressesFromNameService(String host, InetAddress reqAddr)
|
static InetAddress[] getAddressesFromNameService(String host, InetAddress reqAddr)
|
||||||
throws UnknownHostException
|
throws UnknownHostException {
|
||||||
{
|
|
||||||
InetAddress[] addresses = null;
|
InetAddress[] addresses = null;
|
||||||
UnknownHostException ex = null;
|
UnknownHostException ex = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
addresses = nameService.lookupAllHostAddr(host);
|
addresses = nameService.lookupAllHostAddr(host);
|
||||||
} catch (UnknownHostException uhe) {
|
} catch (UnknownHostException uhe) {
|
||||||
if (host.equalsIgnoreCase("localhost")) {
|
if (host.equalsIgnoreCase("localhost")) {
|
||||||
addresses = new InetAddress[] { impl.loopbackAddress() };
|
addresses = new InetAddress[]{impl.loopbackAddress()};
|
||||||
}
|
} else {
|
||||||
else {
|
ex = uhe;
|
||||||
ex = uhe;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (addresses == null) {
|
if (addresses == null) {
|
||||||
throw ex == null ? new UnknownHostException(host) : ex;
|
throw ex == null ? new UnknownHostException(host) : ex;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user