diff --git a/source/org/jivesoftware/smack/XMPPConnection.java b/source/org/jivesoftware/smack/XMPPConnection.java index d6d3e5f76..d0cd0c2aa 100644 --- a/source/org/jivesoftware/smack/XMPPConnection.java +++ b/source/org/jivesoftware/smack/XMPPConnection.java @@ -34,6 +34,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.net.Socket; import java.net.UnknownHostException; +import java.net.InetAddress; import java.util.Collection; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; @@ -532,6 +533,19 @@ public class XMPPConnection { return isUsingTLS(); } + /** + * Returns the local network address of the socket used to connect to the server, or + * null if not currently connected to the server. + * + * @return the local address for the socket used to connect to the server. + */ + public InetAddress getLocalNetworkAddress() { + if (socket == null || !socket.isConnected()) { + return null; + } + return socket.getLocalAddress(); + } + /** * Returns true if currently authenticated by successfully calling the login method. *