Handle escaping and unescaping IPv6 addresses in AddressTuple

This commit is contained in:
Cameron Gutman
2022-12-01 18:26:15 -06:00
parent 381598c5b6
commit ec57499e08

View File

@@ -20,6 +20,11 @@ public class ComputerDetails {
throw new IllegalArgumentException("Invalid port");
}
// If this was an escaped IPv6 address, remove the brackets
if (address.startsWith("[") && address.endsWith("]")) {
address = address.substring(1, address.length() - 1);
}
this.address = address;
this.port = port;
}
@@ -40,7 +45,14 @@ public class ComputerDetails {
}
public String toString() {
return address + ":" + port;
if (address.contains(":")) {
// IPv6
return "[" + address + "]:" + port;
}
else {
// IPv4 and hostnames
return address + ":" + port;
}
}
}