From eb236438be9d2dcc7a605ef3dbb98d0350a7c51c Mon Sep 17 00:00:00 2001 From: adam Date: Tue, 17 Jan 2006 02:57:45 +0000 Subject: [PATCH] added org.ibex.net.IP darcs-hash:20060117025745-5007d-802be268a49e3e5456ebe19b1e4a6cb41a18a918.gz --- src/org/ibex/net/IP.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/org/ibex/net/IP.java diff --git a/src/org/ibex/net/IP.java b/src/org/ibex/net/IP.java new file mode 100644 index 0000000..c0e14ac --- /dev/null +++ b/src/org/ibex/net/IP.java @@ -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); + } + +} -- 1.7.10.4