diff options
| author | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-11-30 15:17:31 -0800 |
|---|---|---|
| committer | Adam Ierymenko <adam.ierymenko@gmail.com> | 2015-11-30 15:17:31 -0800 |
| commit | 7e28161638a3c64754f55fe84d88917741b49019 (patch) | |
| tree | d6debc90b571e0d32e4d8f30a0803a47b0762eaa /ext/libnatpmp/JavaTest.java | |
| parent | ef4472e1857b86b5a45493a3c3566c7761260dad (diff) | |
| parent | 40a4ba6e39bbc59b320eef2f6839cf30c3f7c8b1 (diff) | |
| download | infinitytier-7e28161638a3c64754f55fe84d88917741b49019.tar.gz infinitytier-7e28161638a3c64754f55fe84d88917741b49019.zip | |
Merge dev
Diffstat (limited to 'ext/libnatpmp/JavaTest.java')
| -rw-r--r-- | ext/libnatpmp/JavaTest.java | 42 |
1 files changed, 42 insertions, 0 deletions
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)}; + } +} |
