From 08449e34ec31aac72f5b9cad388563773258bf3f Mon Sep 17 00:00:00 2001 From: genofire Date: Tue, 25 Aug 2020 18:48:50 +0200 Subject: [PATCH] fix Resolver for ip direct and invalidHostname --- .../java/eu/siacs/conversations/utils/Resolver.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/utils/Resolver.java b/src/main/java/eu/siacs/conversations/utils/Resolver.java index bd3121530..258fbdac9 100644 --- a/src/main/java/eu/siacs/conversations/utils/Resolver.java +++ b/src/main/java/eu/siacs/conversations/utils/Resolver.java @@ -81,7 +81,7 @@ public class Resolver { } } - public static Result fromHardCoded(String hostname, int port) { + public static Result fromHardCoded(final String hostname, final int port) { final Result ipResult = fromIpAddress(hostname, port); if (ipResult != null) { ipResult.connect(); @@ -94,6 +94,15 @@ public class Resolver { return port == 443 || port == 5223; } + public static boolean invalidHostname(final String hostname) { + try { + DNSName.from(hostname); + return false; + } catch (IllegalArgumentException e) { + return true; + } + } + public static Result resolve(String domain) { final Result ipResult = fromIpAddress(domain, DEFAULT_PORT_XMPP); if (ipResult != null) { @@ -163,6 +172,7 @@ public class Resolver { try { Result result = new Result(); result.ip = InetAddress.getByName(domain); + result.hostname = DNSName.from(domain); result.port = port; result.authenticated = true; return result;