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:
@@ -112,3 +112,4 @@ Catchears
|
|||||||
younggam
|
younggam
|
||||||
simba-fs
|
simba-fs
|
||||||
RedRadiation
|
RedRadiation
|
||||||
|
Marko Zajc
|
||||||
|
|||||||
@@ -563,25 +563,32 @@ public class JoinDialog extends BaseDialog{
|
|||||||
transient Host lastHost;
|
transient Host lastHost;
|
||||||
|
|
||||||
void setIP(String ip){
|
void setIP(String ip){
|
||||||
|
try{
|
||||||
//parse ip:port, if unsuccessful, use default values
|
boolean isIpv6 = Strings.count(ip, ':') > 1;
|
||||||
if(ip.lastIndexOf(':') != -1 && ip.lastIndexOf(':') != ip.length() - 1){
|
if(isIpv6 && ip.lastIndexOf("]:") != -1 && ip.lastIndexOf("]:") != ip.length() - 1){
|
||||||
try{
|
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(':');
|
int idx = ip.lastIndexOf(':');
|
||||||
this.ip = ip.substring(0, idx);
|
this.ip = ip.substring(0, idx);
|
||||||
this.port = Integer.parseInt(ip.substring(idx + 1));
|
this.port = Integer.parseInt(ip.substring(idx + 1));
|
||||||
}catch(Exception e){
|
}else{
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
this.port = Vars.port;
|
this.port = Vars.port;
|
||||||
}
|
}
|
||||||
}else{
|
}catch(Exception e){
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
this.port = Vars.port;
|
this.port = Vars.port;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String displayIP(){
|
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(){
|
public Server(){
|
||||||
|
|||||||
Reference in New Issue
Block a user