提交 d40fba14 编写于 作者: V vinnie

8035834: InetAddress.getLocalHost() can hang after JDK-8030731

Reviewed-by: wetmore, ahgross
上级 4a9342ed
/*
* Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2014, 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
......@@ -179,8 +179,8 @@ abstract class SeedGenerator {
md.update(p.getProperty(s).getBytes());
}
md.update
(InetAddress.getLocalHost().toString().getBytes());
// Include network adapter names (and a Mac address)
addNetworkAdapterInfo(md);
// The temporary dir
File f = new File(p.getProperty("java.io.tmpdir"));
......@@ -221,6 +221,31 @@ abstract class SeedGenerator {
return md.digest();
}
/*
* Include network adapter names and, if available, a Mac address
*
* See also java.util.concurrent.ThreadLocalRandom.initialSeed()
*/
private static void addNetworkAdapterInfo(MessageDigest md) {
try {
Enumeration<NetworkInterface> ifcs =
NetworkInterface.getNetworkInterfaces();
while (ifcs.hasMoreElements()) {
NetworkInterface ifc = ifcs.nextElement();
md.update(ifc.toString().getBytes());
if (!ifc.isVirtual()) { // skip fake addresses
byte[] bs = ifc.getHardwareAddress();
if (bs != null) {
md.update(bs);
break;
}
}
}
} catch (Exception ignore) {
}
}
/**
* Helper function to convert a long into a byte array (least significant
* byte first).
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册