home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / browser / tonline / ie32.exe / IEXPLORE.CAB / CLASSES.ZIP / java / net / InetAddress.class (.txt) < prev    next >
Encoding:
Java Class File  |  1996-10-01  |  4.0 KB  |  180 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);
  73.          } catch (Throwable var5) {
  74.             throw var5;
  75.          }
  76.       } else {
  77.          var1 = __getAllByName(var0);
  78.       }
  79.  
  80.       return var1;
  81.    }
  82.  
  83.    static synchronized InetAddress[] __getAllByName(String var0) throws UnknownHostException {
  84.       Object var1 = null;
  85.       if (var0 == null) {
  86.          throw new UnknownHostException(var0);
  87.       } else {
  88.          SecurityManager var2 = System.getSecurityManager();
  89.          if (var2 != null && !var2.getInCheck()) {
  90.             var2.checkConnect(var0, -1);
  91.          }
  92.  
  93.          Object var3 = addressCache.get(var0);
  94.          if (var3 == null) {
  95.             try {
  96.                byte[][] var4 = lookupAllHostAddr(var0);
  97.                InetAddress[] var5 = new InetAddress[var4.length];
  98.  
  99.                for(int var6 = 0; var6 < var4.length; ++var6) {
  100.                   byte[] var7 = var4[var6];
  101.                   var5[var6] = new InetAddress(var0, var7);
  102.                   InetAddress[] var8 = new InetAddress[1];
  103.                   String var9 = new String(var5[var6].getHostAddress());
  104.                   var8[0] = new InetAddress(var9, var7);
  105.                   addressCache.put(var9, var8);
  106.                }
  107.  
  108.                var3 = var5;
  109.             } catch (UnknownHostException var11) {
  110.                var3 = unknownAddress;
  111.             }
  112.  
  113.             addressCache.put(var0, var3);
  114.          }
  115.  
  116.          if (var3 == unknownAddress) {
  117.             throw new UnknownHostException(var0);
  118.          } else {
  119.             try {
  120.                var1 = ((InetAddress[])var3).clone();
  121.             } catch (CloneNotSupportedException var10) {
  122.                ((Throwable)var10).printStackTrace();
  123.             }
  124.  
  125.             return (InetAddress[])var1;
  126.          }
  127.       }
  128.    }
  129.  
  130.    public static InetAddress getLocalHost() throws UnknownHostException {
  131.       if (localHost.equals(unknownAddress)) {
  132.          throw new UnknownHostException();
  133.       } else {
  134.          SecurityManager var0 = System.getSecurityManager();
  135.  
  136.          try {
  137.             if (var0 != null && !var0.getInCheck()) {
  138.                var0.checkConnect(localHost.getHostName(), -1);
  139.             }
  140.          } catch (SecurityException var1) {
  141.             return loopbackHost;
  142.          }
  143.  
  144.          return localHost;
  145.       }
  146.    }
  147.  
  148.    private static native String getLocalHostName() throws UnknownHostException;
  149.  
  150.    private static native void makeAnyLocalAddress(InetAddress var0);
  151.  
  152.    private static native byte[] lookupHostAddr(String var0) throws UnknownHostException;
  153.  
  154.    private static native byte[][] lookupAllHostAddr(String var0) throws UnknownHostException;
  155.  
  156.    private static native String getHostByAddr(int var0) throws UnknownHostException;
  157.  
  158.    private static native int getInetFamily();
  159.  
  160.    static {
  161.       System.loadLibrary("javart");
  162.       addressCache = new Hashtable();
  163.       unknownAddress = new InetAddress();
  164.       anyLocalAddress = new InetAddress();
  165.       makeAnyLocalAddress(anyLocalAddress);
  166.       byte[] var0 = new byte[]{127, 0, 0, 1};
  167.       loopbackHost = new InetAddress("localhost", var0);
  168.  
  169.       try {
  170.          localHost = getByName(getLocalHostName());
  171.       } catch (Exception var3) {
  172.          localHost = unknownAddress;
  173.       }
  174.  
  175.       String var1 = new String("0.0.0.0");
  176.       InetAddress[] var2 = new InetAddress[]{new InetAddress(var1, unknownAddress.getAddress())};
  177.       addressCache.put(var1, var2);
  178.    }
  179. }
  180.