home *** CD-ROM | disk | FTP | other *** search
- package java.net;
-
- import java.util.Hashtable;
-
- public final class InetAddress {
- String hostName;
- int address;
- int family;
- static Hashtable addressCache;
- static InetAddress unknownAddress;
- static InetAddress anyLocalAddress;
- static InetAddress localHost;
-
- InetAddress() {
- }
-
- InetAddress(String hostName, byte[] addr) {
- this.hostName = hostName;
- this.family = getInetFamily();
- this.address = addr[3] & 255;
- this.address |= addr[2] << 8 & '\uff00';
- this.address |= addr[1] << 16 & 16711680;
- this.address |= addr[0] << 24 & -16777216;
- }
-
- public String getHostName() {
- if (this.hostName == null) {
- try {
- this.hostName = getHostByAddr(this.address);
- } catch (UnknownHostException var1) {
- this.hostName = this.getHostAddress();
- }
- }
-
- return this.hostName;
- }
-
- public byte[] getAddress() {
- byte[] addr = new byte[4];
- addr[0] = (byte)(this.address >>> 24 & 255);
- addr[1] = (byte)(this.address >>> 16 & 255);
- addr[2] = (byte)(this.address >>> 8 & 255);
- addr[3] = (byte)(this.address & 255);
- return addr;
- }
-
- public String getHostAddress() {
- return (this.address >>> 24 & 255) + "." + (this.address >>> 16 & 255) + "." + (this.address >>> 8 & 255) + "." + (this.address & 255);
- }
-
- public int hashCode() {
- return this.address;
- }
-
- public boolean equals(Object obj) {
- return obj != null && obj instanceof InetAddress && ((InetAddress)obj).address == this.address;
- }
-
- public String toString() {
- return (this.hostName != null ? this.hostName + "/" : "") + this.getHostAddress();
- }
-
- public static InetAddress getByName(String host) throws UnknownHostException {
- return host != null && host.length() != 0 ? getAllByName(host)[0] : getLocalHost();
- }
-
- public static InetAddress[] getAllByName(String host) throws UnknownHostException {
- if (host == null) {
- throw new UnknownHostException(host);
- } else {
- SecurityManager security = System.getSecurityManager();
- if (security != null && !security.getInCheck()) {
- security.checkConnect(host, -1);
- }
-
- Hashtable var3 = addressCache;
- synchronized(var3){}
-
- Object obj;
- try {
- obj = addressCache.get(host);
- if (obj == null) {
- try {
- byte[][] byte_array = lookupAllHostAddr(host);
- if (byte_array.length == 0) {
- throw new UnknownHostException(host);
- }
-
- InetAddress[] addr_array = new InetAddress[byte_array.length];
-
- for(int i = 0; i < byte_array.length; ++i) {
- byte[] addr = byte_array[i];
- addr_array[i] = new InetAddress(host, addr);
- }
-
- obj = addr_array;
- } catch (UnknownHostException var13) {
- obj = unknownAddress;
- }
-
- addressCache.put(host, obj);
- }
- } catch (Throwable var14) {
- throw var14;
- }
-
- if (obj == unknownAddress) {
- throw new UnknownHostException(host);
- } else {
- try {
- obj = ((InetAddress[])obj).clone();
- } catch (CloneNotSupportedException cnse) {
- ((Throwable)cnse).printStackTrace();
- obj = null;
- }
-
- return (InetAddress[])obj;
- }
- }
- }
-
- public static InetAddress getLocalHost() throws UnknownHostException {
- if (localHost.equals(unknownAddress)) {
- throw new UnknownHostException();
- } else {
- return localHost;
- }
- }
-
- private static native String getLocalHostName() throws UnknownHostException;
-
- private static native void makeAnyLocalAddress(InetAddress var0);
-
- private static native byte[] lookupHostAddr(String var0) throws UnknownHostException;
-
- private static native byte[][] lookupAllHostAddr(String var0) throws UnknownHostException;
-
- private static native String getHostByAddr(int var0) throws UnknownHostException;
-
- private static native int getInetFamily();
-
- static {
- SecurityManager.setScopePermission();
- System.loadLibrary("net");
- addressCache = new Hashtable();
- unknownAddress = new InetAddress();
- anyLocalAddress = new InetAddress();
- makeAnyLocalAddress(anyLocalAddress);
-
- try {
- localHost = getByName(getLocalHostName());
- } catch (Exception var0) {
- localHost = unknownAddress;
- }
- }
- }
-