Hi again,

This commit updates the javadoc of InetAddress.family to make
clear that it is used only for serialization, and ensures that
it is properly set.

Cheers,
Gary
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.8516
diff -u -r1.8516 ChangeLog
--- ChangeLog   8 Sep 2006 12:58:13 -0000       1.8516
+++ ChangeLog   8 Sep 2006 14:31:25 -0000
@@ -1,3 +1,17 @@
+2006-09-08  Gary Benson  <[EMAIL PROTECTED]>
+
+       * java/net/InetAddress.java
+       (family): Updated javadoc and made private.
+       (<init>): Add an address family argument.
+       (readObject): Don't overwrite family.
+       * java/net/Inet4Address.java
+       (AF_INET): New constant.
+       (<init>): Use AF_INET as the family.
+       (writeReplace): Likewise.
+       * java/net/Inet6Address.java
+       (AF_INET6): New constant.
+       (<init>): Use AF_INET6 as the family.
+
 2006-09-08  Gary Benson  <[EMAIL PROTECTED]>
 
        * java/net/InetAddress.java
Index: java/net/InetAddress.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/InetAddress.java,v
retrieving revision 1.49
diff -u -r1.49 InetAddress.java
--- java/net/InetAddress.java   8 Sep 2006 12:58:14 -0000       1.49
+++ java/net/InetAddress.java   8 Sep 2006 14:31:25 -0000
@@ -126,13 +126,9 @@
   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.
+   * Needed for serialization.
    */
-  int family;
+  private int family;
 
   /**
    * Constructor.  Prior to the introduction of IPv6 support in 1.4,
@@ -145,13 +141,13 @@
    *
    * @param ipaddr The IP number of this address as an array of bytes
    * @param hostname The hostname of this IP address.
+   * @param family The address family of this IP address.
    */
-  InetAddress(byte[] ipaddr, String hostname)
+  InetAddress(byte[] ipaddr, String hostname, int family)
   {
     addr = (null == ipaddr) ? null : (byte[]) ipaddr.clone();
     hostName = hostname;
-    
-    family = 2; /* AF_INET */
+    this.family = family;
   }
 
   /**
@@ -607,8 +603,6 @@
 
     for (int i = 2; i >= 0; --i)
       addr[i] = (byte) (address >>= 8);
-
-    family = 2; /* AF_INET  */
   }
 
   private void writeObject(ObjectOutputStream oos) throws IOException
Index: java/net/Inet4Address.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/Inet4Address.java,v
retrieving revision 1.20
diff -u -r1.20 Inet4Address.java
--- java/net/Inet4Address.java  8 Sep 2006 11:32:34 -0000       1.20
+++ java/net/Inet4Address.java  8 Sep 2006 14:31:25 -0000
@@ -1,5 +1,5 @@
 /* Inet4Address.java --
-   Copyright (C) 2002, 2003, 2004, 2005  Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -57,11 +57,16 @@
   static final long serialVersionUID = 3286316764910316507L;
 
   /**
+   * The address family of these addresses.
+   */
+  private static final int AF_INET = 2;
+
+  /**
    * Inet4Address objects are serialized as InetAddress objects.
    */
   private Object writeReplace() throws ObjectStreamException
   {
-    return new InetAddress(addr, hostName);
+    return new InetAddress(addr, hostName, AF_INET);
   }
   
   /**
@@ -74,7 +79,7 @@
    */
   Inet4Address(byte[] addr, String host)
   {
-    super(addr, host);
+    super(addr, host, AF_INET);
   }
 
   /**
Index: java/net/Inet6Address.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/Inet6Address.java,v
retrieving revision 1.13
diff -u -r1.13 Inet6Address.java
--- java/net/Inet6Address.java  19 Jul 2006 16:21:20 -0000      1.13
+++ java/net/Inet6Address.java  8 Sep 2006 14:31:25 -0000
@@ -1,5 +1,5 @@
 /* Inet6Address.java --
-   Copyright (C) 2002, 2003, 2004  Free Software Foundation, Inc.
+   Copyright (C) 2002, 2003, 2004, 2006 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -93,6 +93,11 @@
   private transient NetworkInterface nif; 
 
   /**
+   * The address family of these addresses.
+   */
+  private static final int AF_INET6 = 10;
+
+  /**
    * Create an Inet6Address object
    *
    * @param addr The IP address
@@ -100,7 +105,7 @@
    */
   Inet6Address(byte[] addr, String host)
   {
-    super(addr, host);
+    super(addr, host, AF_INET6);
     // Super constructor clones the addr.  Get a reference to the clone.
     this.ipaddress = this.addr;
     ifname = null;

Reply via email to