added org.ibex.net.IP
authoradam <adam@megacz.com>
Tue, 17 Jan 2006 02:57:45 +0000 (02:57 +0000)
committeradam <adam@megacz.com>
Tue, 17 Jan 2006 02:57:45 +0000 (02:57 +0000)
darcs-hash:20060117025745-5007d-802be268a49e3e5456ebe19b1e4a6cb41a18a918.gz

src/org/ibex/net/IP.java [new file with mode: 0644]

diff --git a/src/org/ibex/net/IP.java b/src/org/ibex/net/IP.java
new file mode 100644 (file)
index 0000000..c0e14ac
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright 2000-2005 the Contributors, as shown in the revision logs.
+// Licensed under the Apache Public Source License 2.0 ("the License").
+// You may not use this file except in compliance with the License.
+
+package org.ibex.net;
+
+import java.net.*;
+import java.io.*;
+import java.util.*;
+import org.ibex.util.*;
+
+public class IP {
+
+    /** construct an IP address from four bytes; doesn't throw an exception */
+    public static InetAddress getIP(int a, int b, int c, int d) {
+        try {
+            return InetAddress.getByAddress(new byte[] { (byte)a, (byte)b, (byte)c, (byte)d });
+        } catch (Exception e) {
+            Log.error(IP.class, e);
+            return null;
+        }
+    }
+
+    public static String toString(InetAddress pi) {
+        return
+            (pi.getAddress()[0]&0xff) + "." +
+            (pi.getAddress()[1]&0xff) + "." +
+            (pi.getAddress()[2]&0xff) + "." +
+            (pi.getAddress()[3]&0xff);
+    }
+
+}