diff --git a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUN.java b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUN.java index bab56abec..ff6418a59 100644 --- a/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUN.java +++ b/jingle/extension/source/org/jivesoftware/smackx/jingle/nat/STUN.java @@ -35,6 +35,10 @@ import org.xmlpull.v1.XmlPullParser; import java.util.Iterator; import java.util.List; import java.util.ArrayList; +import java.util.Enumeration; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.InetAddress; /** * STUN IQ Packet used to request and retrieve a STUN server and port to make p2p connections easier. STUN is usually used by Jingle Media Transmission between two parties that are behind NAT. @@ -49,6 +53,8 @@ public class STUN extends IQ { private List servers = new ArrayList(); + private String publicIp = null; + /** * Element name of the packet extension. */ @@ -83,6 +89,24 @@ public class STUN extends IQ { return servers; } + /** + * Get Public Ip returned from the XMPP server + * + * @return + */ + public String getPublicIp() { + return publicIp; + } + + /** + * Set Public Ip returned from the XMPP server + * + * @param publicIp + */ + private void setPublicIp(String publicIp) { + this.publicIp = publicIp; + } + /** * Get the Child Element XML of the Packet * @@ -138,6 +162,15 @@ public class STUN extends IQ { if (host != null && port != null) iq.servers.add(new StunServerAddress(host, port)); } + else if (elementName.equals("publicip")) { + String host = null; + for (int i = 0; i < parser.getAttributeCount(); i++) { + if (parser.getAttributeName(i).equals("ip")) + host = parser.getAttributeValue(i); + } + if (host != null && !host.equals("")) + iq.setPublicIp(host); + } } else if (eventType == XmlPullParser.END_TAG) { if (parser.getName().equals(ELEMENT_NAME)) { diff --git a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/STUNResolverTest.java b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/STUNResolverTest.java index e996ea1c0..90ec9f523 100644 --- a/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/STUNResolverTest.java +++ b/jingle/extension/test/org/jivesoftware/smackx/jingle/nat/STUNResolverTest.java @@ -171,7 +171,9 @@ public class STUNResolverTest extends SmackTestCase { STUN stun = STUN.getSTUNServer(getConnection(0)); for (STUN.StunServerAddress stunServerAddress : stun.getServers()) System.out.println(stunServerAddress.getServer() + ":" + stunServerAddress.getPort()); - + + System.out.println(stun.getPublicIp()); + } /**