From 3b9db94ce9be1982f46be5657e53e9eebc484175 Mon Sep 17 00:00:00 2001 From: Andrew Steinborn Date: Wed, 7 Aug 2019 16:21:03 -0400 Subject: [PATCH] Explicitly parse IP addresses before using an unresolved address This allows plugins to more correctly use InetSocketAddress#getAddress(), however "gotchas" remain. --- .../java/com/velocitypowered/proxy/util/AddressUtil.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/com/velocitypowered/proxy/util/AddressUtil.java b/proxy/src/main/java/com/velocitypowered/proxy/util/AddressUtil.java index 8874509aa..033babcb9 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/util/AddressUtil.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/util/AddressUtil.java @@ -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,7 +21,12 @@ public class AddressUtil { public static InetSocketAddress parseAddress(String ip) { Preconditions.checkNotNull(ip, "ip"); URI uri = URI.create("tcp://" + ip); - return InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort()); + try { + InetAddress ia = InetAddresses.forUriString(uri.getHost()); + return new InetSocketAddress(ia, uri.getPort()); + } catch (IllegalArgumentException e) { + return InetSocketAddress.createUnresolved(uri.getHost(), uri.getPort()); + } } /**