⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inetaddress.java

📁 俄罗斯高人Mamaich的Pocket gcc编译器(运行在PocketPC上)的全部源代码。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// INetAddress.java -- An Internet Protocol (IP) address./* Copyright (C) 1998, 1999, 2000, 2002  Free Software Foundation   This file is part of libgcj.This software is copyrighted work licensed under the terms of theLibgcj License.  Please consult the file "LIBGCJ_LICENSE" fordetails.  */package java.net;import java.io.ObjectInputStream;import java.io.ObjectOutputStream;import java.io.IOException;import java.io.Serializable;import java.io.ObjectStreamException;/** * @author Per Bothner * @date January 6, 1999. *//* * Written using on-line Java Platform 1.2 API Specification, as well * as "The Java Class Libraries", 2nd edition (Addison-Wesley, 1998). * (The latter turns out to have some errors ...) * Status:  Believed complete and correct. * * @specnote This class is not final since JK 1.4 */public class InetAddress implements Serializable{  // The Serialized Form specifies that an int 'address' is saved/restored.  // This class uses a byte array internally so we'll just do the conversion  // at serialization time and leave the rest of the algorithm as is.  private int address;  transient byte[] addr;  String hostName;  // The field 'family' seems to be the AF_ value.  // FIXME: Much of the code in the other java.net classes does not make  // use of this family field.  A better implementation would be to make  // use of getaddrinfo() and have other methods just check the family  // field rather than examining the length of the address each time.  int family;  private static final long serialVersionUID = 3286316764910316507L;  /**   * Needed for serialization   */  private void readResolve () throws ObjectStreamException  {    // FIXME: implement this  }	    private void readObject(ObjectInputStream ois)    throws IOException, ClassNotFoundException  {    ois.defaultReadObject();    addr = new byte[4];    addr[3] = (byte) address;    for (int i = 2; i >= 0; --i)      addr[i] = (byte) (address >>= 8);    // Ignore family from serialized data.  Since the saved address is 32 bits    // the deserialized object will have an IPv4 address i.e. AF_INET family.    // FIXME: An alternative is to call the aton method on the deserialized    // hostname to get a new address.  The Serialized Form doc is silent    // on how these fields are used.    family = getFamily (addr);  }  private void writeObject(ObjectOutputStream oos) throws IOException  {    // Build a 32 bit address from the last 4 bytes of a 4 byte IPv4 address    // or a 16 byte IPv6 address.    int len = addr.length;    int i = len - 4;    for (; i < len; i++)      address = address << 8 | (((int) addr[i]) & 0xFF);    oos.defaultWriteObject();  }  private static native int getFamily (byte[] address);  InetAddress (byte[] address, String hostname)  {    addr = address;    hostName = hostname;    if (address != null)      family = getFamily (address);  }  /**   * Utility routine to check if the InetAddress is an IP multicast address   *   * @since 1.1   */  public boolean isMulticastAddress ()  {    int len = addr.length;    if (len == 4)      return (addr[0] & 0xF0) == 0xE0;    if (len == 16)      return addr[0] == (byte) 0xFF;    return false;  }  /**   * Utility routine to check if the InetAddress in a wildcard address   *    * @since 1.4   */  public boolean isAnyLocalAddress ()  {    // This is the IPv4 implementation.    // Any class derived from InetAddress should override this.    return addr == zeros;  }  /**   * Utility routine to check if the InetAddress is a loopback address   *    * @since 1.4   */  public boolean isLoopbackAddress ()  {    // This is the IPv4 implementation.    // Any class derived from InetAddress should override this.        return addr[0] == 0x7F;  }  /**   * Utility routine to check if InetAddress is a link local address   *    * @since 1.4   */  public boolean isLinkLocalAddress ()  {    // This is the IPv4 implementation.    // Any class derived from InetAddress should override this.    // XXX: This seems to not exist with IPv4 addresses    return false;  }  /**   * Utility routine to check if InetAddress is a site local address   *    * @since 1.4   */  public boolean isSiteLocalAddress ()  {    // This is the IPv4 implementation.    // Any class derived from InetAddress should override this.    // 10.0.0.0/8    if (addr[0] == 0x0A)      return true;    // XXX: Suns JDK 1.4.1 (on Linux) seems to have a bug here:    // it says 172.16.0.0 - 172.255.255.255 are site local addresses    // 172.16.0.0/12    if (addr[0] == 0xAC && (addr[1] & 0xF0) == 0x01)      return true;    // 192.168.0.0/16    if (addr[0] == 0xC0 && addr[1] == 0xA8)      return true;    // XXX: Do we need to check more addresses here ?    return false;  }  /**   * Utility routine to check if InetAddress is a global multicast address   *    * @since 1.4   */  public boolean isMCGlobal ()  {    // This is the IPv4 implementation.    // Any class derived from InetAddress should override this.    // XXX: This seems to not exist with IPv4 addresses    return false;  }  /**   * Utility reoutine to check if InetAddress is a node local multicast address   *    * @since 1.4   */  public boolean isMCNodeLocal ()  {    // This is the IPv4 implementation.    // Any class derived from InetAddress should override this.    // XXX: This seems to not exist with IPv4 addresses    return false;  }  /**   * Utility reoutine to check if InetAddress is a link local multicast address   *    * @since 1.4   */  public boolean isMCLinkLocal ()  {    // This is the IPv4 implementation.    // Any class derived from InetAddress should override this.        if (!isMulticastAddress ())      return false;    return (addr[0] == 0xE0	    && addr[1] == 0x00	    && addr[2] == 0x00);  }  /**   * Utility reoutine to check if InetAddress is a site local multicast address   *   * @since 1.4   */  public boolean isMCSiteLocal ()  {    // This is the IPv4 implementation.    // Any class derived from InetAddress should override this.    // XXX: This seems to not exist with IPv4 addresses    return false;  }  /**   * Utility reoutine to check if InetAddress is a organization local   * multicast address   *    * @since 1.4   */  public boolean isMCOrgLocal ()  {    // This is the IPv4 implementation.    // Any class derived from InetAddress should override this.    // XXX: This seems to not exist with IPv4 addresses    return false;  }  /**   * Returns the hostname represented by this InetAddress   */  public String getHostName ()  {    if (hostName == null)      lookup (null, this, false);    return hostName;  }  /**   * Returns the canonical hostname represented by this InetAddress   *    * @since 1.4   */  public String getCanonicalHostName ()  {    SecurityManager sm = System.getSecurityManager ();    if (sm != null)      {        try	  {            sm.checkConnect (hostName, -1);	  }	catch (SecurityException e)	  {	    return getHostAddress ();	  }      }    // Try to find the FDQN now    InetAddress address = new InetAddress (getAddress (), null);    return address.getHostName ();  }  /**   * Returns the IP address of this InetAddress as array of bytes   */  public byte[] getAddress ()  {    // An experiment shows that JDK1.2 returns a different byte array each    // time.  This makes sense, in terms of security.    return (byte[]) addr.clone();  }  /* Helper function due to a CNI limitation.  */  private static InetAddress[] allocArray (int count)  {    return new InetAddress[count];  }  /* Helper function due to a CNI limitation.  */  private static SecurityException checkConnect (String hostname)  {    SecurityManager s = System.getSecurityManager();    if (s == null)      return null;    try      {	s.checkConnect(hostname, -1);	return null;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -