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