diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java
index 9d7f263a1..66a6d018a 100644
--- a/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java
+++ b/smack-core/src/main/java/org/jivesoftware/smack/util/dns/HostAddress.java
@@ -75,6 +75,22 @@ public class HostAddress {
setException(e);
}
+ public String getHost() {
+ if (fqdn != null) {
+ return fqdn;
+ }
+
+ // In this case, the HostAddress(int, InetAddress) constructor must been used. We have no FQDN. And
+ // inetAddresses.size() must be exactly one.
+ assert inetAddresses.size() == 1;
+ return inetAddresses.get(0).getHostAddress();
+ }
+
+ /**
+ * Return the fully qualified domain name. This may return null
in case there host address is only numeric, i.e. an IP address.
+ *
+ * @return the fully qualified domain name or null
+ */
public String getFQDN() {
return fqdn;
}
@@ -109,7 +125,7 @@ public class HostAddress {
@Override
public String toString() {
- return fqdn + ":" + port;
+ return getHost() + ":" + port;
}
@Override
@@ -123,7 +139,7 @@ public class HostAddress {
final HostAddress address = (HostAddress) o;
- if (!fqdn.equals(address.fqdn)) {
+ if (!getHost().equals(address.getHost())) {
return false;
}
return port == address.port;
@@ -132,7 +148,7 @@ public class HostAddress {
@Override
public int hashCode() {
int result = 1;
- result = 37 * result + fqdn.hashCode();
+ result = 37 * result + getHost().hashCode();
return result * 37 + port;
}
diff --git a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java
index f38e8987b..67ea8f631 100644
--- a/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java
+++ b/smack-tcp/src/main/java/org/jivesoftware/smack/tcp/XMPPTCPConnection.java
@@ -563,7 +563,7 @@ public class XMPPTCPConnection extends AbstractXMPPConnection {
}
for (HostAddress hostAddress : hostAddresses) {
Iterator inetAddresses = null;
- String host = hostAddress.getFQDN();
+ String host = hostAddress.getHost();
int port = hostAddress.getPort();
if (proxyInfo == null) {
inetAddresses = hostAddress.getInetAddresses().iterator();