tls-psk: reformat getIPAddress method
This commit is contained in:
@@ -404,25 +404,23 @@ public class KeyTransferInteractor {
|
||||
*/
|
||||
private static String getIPAddress(boolean useIPv4) {
|
||||
try {
|
||||
List<NetworkInterface> interfaces = Collections.list(NetworkInterface.
|
||||
getNetworkInterfaces());
|
||||
List<NetworkInterface> interfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
|
||||
for (NetworkInterface intf : interfaces) {
|
||||
List<InetAddress> addrs = Collections.list(intf.getInetAddresses());
|
||||
for (InetAddress addr : addrs) {
|
||||
if (!addr.isLoopbackAddress()) {
|
||||
String sAddr = addr.getHostAddress();
|
||||
boolean isIPv4 = sAddr.indexOf(':') < 0;
|
||||
|
||||
if (useIPv4) {
|
||||
if (isIPv4)
|
||||
return sAddr;
|
||||
} else {
|
||||
if (!isIPv4) {
|
||||
int delim = sAddr.indexOf('%'); // drop ip6 zone suffix
|
||||
return delim < 0 ? sAddr.toUpperCase() : sAddr.substring(0, delim).
|
||||
toUpperCase();
|
||||
}
|
||||
if (addr.isLoopbackAddress()) {
|
||||
continue;
|
||||
}
|
||||
String sAddr = addr.getHostAddress();
|
||||
boolean isIPv4 = sAddr.indexOf(':') < 0;
|
||||
if (isIPv4 && useIPv4) {
|
||||
return sAddr;
|
||||
} else if (!isIPv4) {
|
||||
int delimIndex = sAddr.indexOf('%'); // drop ip6 zone suffix
|
||||
if (delimIndex >= 0) {
|
||||
sAddr = sAddr.substring(0, delimIndex);
|
||||
}
|
||||
return sAddr.toUpperCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user