Mercurial > hg > icedtea7-forest > jdk
changeset 7627:92fd166252c2 jdk7u55-b13
8035834: InetAddress.getLocalHost() can hang after JDK-8030731 was fixed
Reviewed-by: vinnie
author | igerasim |
---|---|
date | Wed, 12 Mar 2014 12:46:11 +0400 |
parents | 51ff2df66fd5 |
children | 4a5651c84b1e |
files | src/share/classes/sun/security/provider/SeedGenerator.java |
diffstat | 1 files changed, 28 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/sun/security/provider/SeedGenerator.java Tue Mar 11 13:00:07 2014 -0700 +++ b/src/share/classes/sun/security/provider/SeedGenerator.java Wed Mar 12 12:46:11 2014 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2011, 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 @@ -173,8 +173,8 @@ 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")); @@ -212,6 +212,31 @@ 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).