From 67685213309a3e4aaa76a2f3173af5dd0ffa3eec Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Mon, 30 Nov 2015 13:10:22 -0800 Subject: Ton of uPnP work and adding NAT-PMP support, still testing... --- ext/libnatpmp/JavaTest.java | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 ext/libnatpmp/JavaTest.java (limited to 'ext/libnatpmp/JavaTest.java') diff --git a/ext/libnatpmp/JavaTest.java b/ext/libnatpmp/JavaTest.java new file mode 100644 index 00000000..0379c182 --- /dev/null +++ b/ext/libnatpmp/JavaTest.java @@ -0,0 +1,42 @@ +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; + +import fr.free.miniupnp.libnatpmp.NatPmp; +import fr.free.miniupnp.libnatpmp.NatPmpResponse; + +class JavaTest { + public static void main(String[] args) { + NatPmp natpmp = new NatPmp(); + + natpmp.sendPublicAddressRequest(); + NatPmpResponse response = new NatPmpResponse(); + + int result = -1; + do{ + result = natpmp.readNatPmpResponseOrRetry(response); + try { + Thread.sleep(4000); + } catch (InterruptedException e) { + //fallthrough + } + } while (result != 0); + + byte[] bytes = intToByteArray(response.addr); + + try { + InetAddress inetAddress = InetAddress.getByAddress(bytes); + System.out.println("Public address is " + inetAddress); + } catch (UnknownHostException e) { + throw new RuntimeException(e); + } + } + + public static final byte[] intToByteArray(int value) { + return new byte[] { + (byte)value, + (byte)(value >>> 8), + (byte)(value >>> 16), + (byte)(value >>> 24)}; + } +} -- cgit v1.2.3