Support IPv6 addresses properly (#4225)
* Support IPv6 addresses properly support the `[ipv6]:port` and `ipv6` formats silly cat forgot that ipv6 is a thing * unnecessary self promotion * less split more substring * also display ipv6 format properly * important security fixes
This commit is contained in:
@@ -563,25 +563,32 @@ public class JoinDialog extends BaseDialog{
|
||||
transient Host lastHost;
|
||||
|
||||
void setIP(String ip){
|
||||
|
||||
//parse ip:port, if unsuccessful, use default values
|
||||
if(ip.lastIndexOf(':') != -1 && ip.lastIndexOf(':') != ip.length() - 1){
|
||||
try{
|
||||
try{
|
||||
boolean isIpv6 = Strings.count(ip, ':') > 1;
|
||||
if(isIpv6 && ip.lastIndexOf("]:") != -1 && ip.lastIndexOf("]:") != ip.length() - 1){
|
||||
int idx = ip.indexOf("]:");
|
||||
this.ip = ip.substring(1, idx);
|
||||
this.port = Integer.parseInt(ip.substring(idx + 2, ip.length()));
|
||||
}else if(!isIpv6 && ip.lastIndexOf(':') != -1 && ip.lastIndexOf(':') != ip.length() - 1){
|
||||
int idx = ip.lastIndexOf(':');
|
||||
this.ip = ip.substring(0, idx);
|
||||
this.port = Integer.parseInt(ip.substring(idx + 1));
|
||||
}catch(Exception e){
|
||||
}else{
|
||||
this.ip = ip;
|
||||
this.port = Vars.port;
|
||||
}
|
||||
}else{
|
||||
}catch(Exception e){
|
||||
this.ip = ip;
|
||||
this.port = Vars.port;
|
||||
}
|
||||
}
|
||||
|
||||
String displayIP(){
|
||||
return ip + (port != Vars.port ? ":" + port : "");
|
||||
if(Strings.count(ip, ':') > 1){
|
||||
return port != Vars.port ? "[" + ip + "]:" + port : ip;
|
||||
}else{
|
||||
return ip + (port != Vars.port ? ":" + port : "");
|
||||
}
|
||||
}
|
||||
|
||||
public Server(){
|
||||
|
||||
Reference in New Issue
Block a user