home *** CD-ROM | disk | FTP | other *** search
- package java.net;
-
- import java.io.Serializable;
- import java.util.Hashtable;
-
- public final class InetAddress implements Serializable {
- String hostName;
- int address;
- int family;
- private static final long serialVersionUID = 3286316764910316507L;
- static Hashtable addressCache;
- static InetAddress unknownAddress;
- static InetAddress anyLocalAddress;
- static InetAddress localHost;
- static InetAddress[] unknown_array;
- static InetAddressImpl impl;
- private static InetAddress loopbackHost;
-
- InetAddress() {
- this.family = impl.getInetFamily();
- }
-
- InetAddress(String var1, byte[] var2) {
- this.hostName = new String(var1);
- this.family = impl.getInetFamily();
- this.address = var2[3] & 255;
- this.address |= var2[2] << 8 & '\uff00';
- this.address |= var2[1] << 16 & 16711680;
- this.address |= var2[0] << 24 & -16777216;
- }
-
- public boolean isMulticastAddress() {
- return (this.address & -268435456) == -536870912;
- }
-
- public String getHostName() {
- if (this.hostName == null) {
- try {
- this.hostName = new String(impl.getHostByAddr(this.address));
- InetAddress[] var1 = (InetAddress[])addressCache.get(this.hostName);
- if (var1 != null) {
- for(int var2 = 0; var2 < var1.length; ++var2) {
- if (this.hostName.equalsIgnoreCase(var1[var2].hostName) && this.address != var1[var2].address) {
- this.hostName = this.getHostAddress();
- break;
- }
- }
- } else {
- var1 = new InetAddress[]{this};
- addressCache.put(this.hostName, var1);
- }
-
- SecurityManager var6 = System.getSecurityManager();
- if (var6 != null && !var6.getInCheck()) {
- var6.checkConnect(this.hostName, -1);
- }
- } catch (SecurityException var3) {
- this.hostName = this.getHostAddress();
- } catch (UnknownHostException var4) {
- this.hostName = this.getHostAddress();
- }
- }
-
- return this.hostName;
- }
-
- public byte[] getAddress() {
- byte[] var1 = new byte[]{(byte)(this.address >>> 24 & 255), (byte)(this.address >>> 16 & 255), (byte)(this.address >>> 8 & 255), (byte)(this.address & 255)};
- return var1;
- }
-
- 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 var1) {
- return var1 != null && var1 instanceof InetAddress && ((InetAddress)var1).address == this.address;
- }
-
- public String toString() {
- return this.getHostName() + "/" + this.getHostAddress();
- }
-
- public static InetAddress getByName(String var0) throws UnknownHostException {
- if (var0 != null && var0.length() != 0) {
- if (!Character.isDigit(var0.charAt(0))) {
- return getAllByName0(var0)[0];
- } else {
- int var1 = 0;
- int var2 = 0;
- char[] var3 = var0.toCharArray();
- int var4 = 0;
-
- label53:
- while(var4 < var3.length) {
- char var5 = var3[var4];
- if (var5 >= '0' && var5 <= '9') {
- int var6 = 0;
-
- while(true) {
- if (var5 != '.') {
- if (var5 < '0' || var5 > '9') {
- return getAllByName0(var0)[0];
- }
-
- var6 = var6 * 10 + var5 - 48;
- ++var4;
- if (var4 < var3.length) {
- var5 = var3[var4];
- continue;
- }
- }
-
- if (var6 > 255) {
- return getAllByName0(var0)[0];
- }
-
- var1 = (var1 << 8) + var6;
- ++var2;
- ++var4;
- continue label53;
- }
- }
-
- return getAllByName0(var0)[0];
- }
-
- if (var2 == 4 && !var0.endsWith(".")) {
- InetAddress var7 = new InetAddress();
- var7.address = var1;
- var7.hostName = null;
- return var7;
- } else {
- return getAllByName0(var0)[0];
- }
- }
- } else {
- return loopbackHost;
- }
- }
-
- public static InetAddress[] getAllByName(String var0) throws UnknownHostException {
- if (var0 != null && var0.length() != 0) {
- if (Character.isDigit(var0.charAt(0))) {
- InetAddress[] var1 = new InetAddress[]{getByName(var0)};
- return var1;
- } else {
- return getAllByName0(var0);
- }
- } else {
- throw new UnknownHostException("empty string");
- }
- }
-
- private static InetAddress[] getAllByName0(String var0) throws UnknownHostException {
- Object var1 = null;
- Object var2 = null;
- SecurityManager var3 = System.getSecurityManager();
- if (var3 != null && !var3.getInCheck()) {
- var3.checkConnect(var0, -1);
- }
-
- Hashtable var4 = addressCache;
- synchronized(var4){}
-
- try {
- var1 = addressCache.get(var0);
- if (var1 == null) {
- try {
- byte[][] var6 = impl.lookupAllHostAddr(var0);
- InetAddress[] var7 = new InetAddress[var6.length];
-
- for(int var8 = 0; var8 < var6.length; ++var8) {
- byte[] var9 = var6[var8];
- var7[var8] = new InetAddress(var0, var9);
- }
-
- var1 = var7;
- } catch (UnknownHostException var14) {
- var1 = unknown_array;
- }
-
- addressCache.put(var0, var1);
- }
- } catch (Throwable var15) {
- throw var15;
- }
-
- if (var1 == unknown_array) {
- throw new UnknownHostException(var0);
- } else {
- try {
- var2 = ((InetAddress[])var1).clone();
- if (var2 == null) {
- throw new CloneNotSupportedException();
- }
- } catch (CloneNotSupportedException var13) {
- ((Throwable)var13).printStackTrace();
- }
-
- return (InetAddress[])var2;
- }
- }
-
- public static InetAddress getLocalHost() throws UnknownHostException {
- if (localHost.equals(unknownAddress)) {
- throw new UnknownHostException();
- } else {
- try {
- if (localHost.address == -1) {
- localHost = getAllByName(localHost.hostName)[0];
- }
-
- SecurityManager var0 = System.getSecurityManager();
- if (var0 != null && !var0.getInCheck()) {
- var0.checkConnect(localHost.getHostName(), -1);
- }
-
- return localHost;
- } catch (SecurityException var1) {
- return loopbackHost;
- }
- }
- }
-
- static {
- System.loadLibrary("net");
- addressCache = new Hashtable();
- String var0 = System.getProperty("impl.prefix", "");
-
- try {
- impl = null;
- impl = (InetAddressImpl)Class.forName("java.net." + var0 + "InetAddressImpl").newInstance();
- } catch (ClassNotFoundException var5) {
- System.err.println("Class not found: java.net." + var0 + "InetAddressImpl:\ncheck impl.prefix property " + "in your properties file.");
- } catch (InstantiationException var6) {
- System.err.println("Could not instantiate: java.net." + var0 + "InetAddressImpl:\ncheck impl.prefix property " + "in your properties file.");
- } catch (IllegalAccessException var7) {
- System.err.println("Cannot access class: java.net." + var0 + "InetAddressImpl:\ncheck impl.prefix property " + "in your properties file.");
- }
-
- if (impl == null) {
- try {
- impl = (InetAddressImpl)Class.forName("java.net.InetAddressImpl").newInstance();
- } catch (Exception var4) {
- throw new Error("System property impl.prefix incorrect");
- }
- }
-
- unknownAddress = new InetAddress();
- anyLocalAddress = new InetAddress();
- impl.makeAnyLocalAddress(anyLocalAddress);
- byte[] var1 = new byte[]{127, 0, 0, 1};
- loopbackHost = new InetAddress("localhost", var1);
-
- try {
- localHost = new InetAddress();
- localHost.hostName = impl.getLocalHostName();
- localHost.address = -1;
- } catch (Exception var3) {
- localHost = unknownAddress;
- }
-
- String var2 = new String("0.0.0.0");
- unknown_array = new InetAddress[1];
- unknown_array[0] = new InetAddress(var2, unknownAddress.getAddress());
- addressCache.put(var2, unknown_array);
- }
- }
-