private static InetAddress buildBenchmarkAddr ( ) { InetAddress tmp = null ; try { Enumeration < NetworkInterface > networkInterfaces = NetworkInterface . getNetworkInterfaces ( ) ; outer : while ( networkInterfaces . hasMoreElements ( ) ) { NetworkInterface networkInterface = networkInterfaces . nextElement ( ) ; if ( ! networkInterface . isLoopback ( ) ) { continue ; } Enumeration < NetworkInterface > subInterfaces = networkInterface . getSubInterfaces ( ) ; while ( subInterfaces . hasMoreElements ( ) ) { NetworkInterface subLoopback = subInterfaces . nextElement ( ) ; if ( subLoopback . getDisplayName ( ) . contains ( "benchmark" ) ) { tmp = subLoopback . getInetAddresses ( ) . nextElement ( ) ; System . out . println ( "\nResolved benchmark address to " + tmp + " on " + subLoopback . getDisplayName ( ) + "\n\n" ) ; break outer ; } } } } catch ( SocketException se ) { System . out . println ( "\nWARNING: Error trying to resolve benchmark interface \n" + se ) ; } if ( tmp == null ) { try { System . out . println ( "\nWARNING: Unable to resolve benchmark interface, defaulting to localhost" ) ; tmp = InetAddress . getLocalHost ( ) ; } catch ( UnknownHostException uhe ) { throw new RuntimeException ( uhe ) ; } } return tmp ; }
Resolve the address bound to the benchmark interface . Currently we assume it s a child interface of the loopback interface with the term benchmark in its name .