home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / java / net / InetAddress.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-27  |  4.0 KB  |  182 lines

  1. package java.net;
  2.  
  3. import java.util.Hashtable;
  4.  
  5. public final class InetAddress {
  6.    private static boolean inCheck;
  7.    String hostName;
  8.    int address;
  9.    int family;
  10.    static Hashtable addressCache;
  11.    static InetAddress unknownAddress;
  12.    static InetAddress anyLocalAddress;
  13.    static InetAddress localHost;
  14.    private static InetAddress loopbackHost;
  15.  
  16.    InetAddress() {
  17.    }
  18.  
  19.    InetAddress(String var1, byte[] var2) {
  20.       this.hostName = new String(var1);
  21.       this.family = getInetFamily();
  22.       this.address = var2[3] & 255;
  23.       this.address |= var2[2] << 8 & '\uff00';
  24.       this.address |= var2[1] << 16 & 16711680;
  25.       this.address |= var2[0] << 24 & -16777216;
  26.    }
  27.  
  28.    public String getHostName() {
  29.       if (this.hostName == null) {
  30.          try {
  31.             this.hostName = getHostByAddr(this.address);
  32.          } catch (UnknownHostException var1) {
  33.             this.hostName = this.getHostAddress();
  34.          }
  35.       }
  36.  
  37.       return this.hostName;
  38.    }
  39.  
  40.    public byte[] getAddress() {
  41.       byte[] var1 = new byte[]{(byte)(this.address >>> 24 & 255), (byte)(this.address >>> 16 & 255), (byte)(this.address >>> 8 & 255), (byte)(this.address & 255)};
  42.       return var1;
  43.    }
  44.  
  45.    public String getHostAddress() {
  46.       return (this.address >>> 24 & 255) + "." + (this.address >>> 16 & 255) + "." + (this.address >>> 8 & 255) + "." + (this.address & 255);
  47.    }
  48.  
  49.    public int hashCode() {
  50.       return this.address;
  51.    }
  52.  
  53.    public boolean equals(Object var1) {
  54.       return var1 != null && var1 instanceof InetAddress && ((InetAddress)var1).address == this.address;
  55.    }
  56.  
  57.    public String toString() {
  58.       return (this.hostName != null ? this.hostName + "/" : "") + this.getHostAddress();
  59.    }
  60.  
  61.    public static InetAddress getByName(String var0) throws UnknownHostException {
  62.       return var0 != null && var0.length() != 0 ? getAllByName(var0)[0] : loopbackHost;
  63.    }
  64.  
  65.    public static InetAddress[] getAllByName(String var0) throws UnknownHostException {
  66.       InetAddress var1 = null;
  67.       SecurityManager var2 = System.getSecurityManager();
  68.       if (var2 != null) {
  69.          synchronized(var2){}
  70.  
  71.          try {
  72.             var1 = __getAllByName(var0, false);
  73.          } catch (Throwable var5) {
  74.             throw var5;
  75.          }
  76.       } else {
  77.          var1 = __getAllByName(var0, false);
  78.       }
  79.  
  80.       return var1;
  81.    }
  82.  
  83.    private static synchronized InetAddress[] __getAllByName(String var0, boolean var1) throws UnknownHostException {
  84.       Object var2 = null;
  85.       if (var0 == null) {
  86.          throw new UnknownHostException(var0);
  87.       } else {
  88.          if (!var1) {
  89.             SecurityManager var3 = System.getSecurityManager();
  90.             if (var3 != null && !var3.getInCheck()) {
  91.                var3.checkConnect(var0, -1);
  92.             }
  93.          }
  94.  
  95.          Object var12 = addressCache.get(var0);
  96.          if (var12 == null) {
  97.             try {
  98.                byte[][] var4 = lookupAllHostAddr(var0);
  99.                InetAddress[] var5 = new InetAddress[var4.length];
  100.  
  101.                for(int var6 = 0; var6 < var4.length; ++var6) {
  102.                   byte[] var7 = var4[var6];
  103.                   var5[var6] = new InetAddress(var0, var7);
  104.                   InetAddress[] var8 = new InetAddress[1];
  105.                   String var9 = new String(var5[var6].getHostAddress());
  106.                   var8[0] = new InetAddress(var9, var7);
  107.                   addressCache.put(var9, var8);
  108.                }
  109.  
  110.                var12 = var5;
  111.             } catch (UnknownHostException var11) {
  112.                var12 = unknownAddress;
  113.             }
  114.  
  115.             addressCache.put(var0, var12);
  116.          }
  117.  
  118.          if (var12 == unknownAddress) {
  119.             throw new UnknownHostException(var0);
  120.          } else {
  121.             try {
  122.                var2 = ((InetAddress[])var12).clone();
  123.             } catch (CloneNotSupportedException var10) {
  124.                ((Throwable)var10).printStackTrace();
  125.             }
  126.  
  127.             return (InetAddress[])var2;
  128.          }
  129.       }
  130.    }
  131.  
  132.    public static InetAddress getLocalHost() throws UnknownHostException {
  133.       if (localHost.equals(unknownAddress)) {
  134.          throw new UnknownHostException();
  135.       } else {
  136.          SecurityManager var0 = System.getSecurityManager();
  137.  
  138.          try {
  139.             if (var0 != null && !var0.getInCheck()) {
  140.                var0.checkConnect(localHost.getHostName(), -1);
  141.             }
  142.          } catch (SecurityException var1) {
  143.             return loopbackHost;
  144.          }
  145.  
  146.          return localHost;
  147.       }
  148.    }
  149.  
  150.    private static native String getLocalHostName() throws UnknownHostException;
  151.  
  152.    private static native void makeAnyLocalAddress(InetAddress var0);
  153.  
  154.    private static native byte[] lookupHostAddr(String var0) throws UnknownHostException;
  155.  
  156.    private static native byte[][] lookupAllHostAddr(String var0) throws UnknownHostException;
  157.  
  158.    private static native String getHostByAddr(int var0) throws UnknownHostException;
  159.  
  160.    private static native int getInetFamily();
  161.  
  162.    static {
  163.       System.loadLibrary("javart");
  164.       addressCache = new Hashtable();
  165.       unknownAddress = new InetAddress();
  166.       anyLocalAddress = new InetAddress();
  167.       makeAnyLocalAddress(anyLocalAddress);
  168.       byte[] var0 = new byte[]{127, 0, 0, 1};
  169.       loopbackHost = new InetAddress("localhost", var0);
  170.  
  171.       try {
  172.          localHost = __getAllByName(getLocalHostName(), true)[0];
  173.       } catch (Exception var3) {
  174.          localHost = unknownAddress;
  175.       }
  176.  
  177.       String var1 = new String("0.0.0.0");
  178.       InetAddress[] var2 = new InetAddress[]{new InetAddress(var1, unknownAddress.getAddress())};
  179.       addressCache.put(var1, var2);
  180.    }
  181. }
  182.