3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Explicitly parse IP addresses before using an unresolved address

This allows plugins to more correctly use InetSocketAddress#getAddress(),
however "gotchas" remain.
Dieser Commit ist enthalten in:
Andrew Steinborn 2019-08-07 16:21:03 -04:00
Ursprung 2c3b30fff2
Commit 3b9db94ce9

Datei anzeigen

@ -1,6 +1,8 @@
package com.velocitypowered.proxy.util;
import com.google.common.base.Preconditions;
import com.google.common.net.InetAddresses;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
@ -19,8 +21,13 @@ public class AddressUtil {
public static InetSocketAddress parseAddress(String ip) {
Preconditions.checkNotNull(ip, "ip");
URI uri = URI.create("tcp://" + ip);
try {
InetAddress ia = InetAddresses.forUriString(uri.getHost());
return new InetSocketAddress(ia, uri.getPort());
} catch (IllegalArgumentException e) {
return InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort());
}
}
/**
* Attempts to parse an IP address of the form <code>127.0.0.1:25565</code>. The returned