On 07/29/2011 06:50 PM, Alex Rousskov wrote:
On 07/25/2011 08:59 AM, Tsantilas Christos wrote:
I am sending a version 4 of the patch which is the same with Amos patch
but is a little smaller. IT is easier to see the changes.


  bool
  Ip::Address::IsIPv4() const
  {
-    return IsAnyAddr() || IsNoAddr() || 
IN6_IS_ADDR_V4MAPPED(&m_SocketAddr.sin6_addr );
+    return IN6_IS_ADDR_V4MAPPED(&m_SocketAddr.sin6_addr );
  }

  bool
  Ip::Address::IsIPv6() const
  {
-    return IsAnyAddr() || IsNoAddr() || 
!IN6_IS_ADDR_V4MAPPED(&m_SocketAddr.sin6_addr );
+    return !IN6_IS_ADDR_V4MAPPED(&m_SocketAddr.sin6_addr );
  }

Can we rewrite IsIPv6() as "return !IsIPv4()", to clarify the intent if
that is indeed the intent?

Also, the documentation for these two methods seems to imply a different
relationship, at least in some corner cases:

     /** Test whether content can be used as an IPv4 address
      \retval true  if content was received as an IPv4 address
      \retval true  if content was received as an IPv4-Mapped address
      \retval false if content was received as a non-mapped IPv6 native address.
      */
     bool IsIPv4() const;

     /** Test whether content can be used as an IPv6 address.
      \retval true  if --enable-ipv6 has been compiled.
      \retval false if --disable-ipv6 has been compiled.
      \retval false if --with-ipv6-split-stack has been compiled AND content is 
I
Pv4-mapped.
      */
     bool IsIPv6() const;

As far as I can tell, the above definitions make it possible for both
IsIPv4() and IsIPv6() to return true at the same time in some cases, but
the implementation does not support that. Thus, the docs or the
implementation is wrong.


I am posting a new patch which implements the IsIPv6 as you suggested, and I changed a little the documentation.





Thank you,

Alex.


=== modified file 'src/ip/Address.cc'
--- src/ip/Address.cc	2011-07-04 04:28:59 +0000
+++ src/ip/Address.cc	2011-08-01 15:25:19 +0000
@@ -173,19 +173,19 @@
 bool
 Ip::Address::IsIPv4() const
 {
-    return IsAnyAddr() || IsNoAddr() || IN6_IS_ADDR_V4MAPPED( &m_SocketAddr.sin6_addr );
+    return IN6_IS_ADDR_V4MAPPED( &m_SocketAddr.sin6_addr );
 }
 
 bool
 Ip::Address::IsIPv6() const
 {
-    return IsAnyAddr() || IsNoAddr() || !IN6_IS_ADDR_V4MAPPED( &m_SocketAddr.sin6_addr );
+    return !IN6_IS_ADDR_V4MAPPED( &m_SocketAddr.sin6_addr );
 }
 
 bool
 Ip::Address::IsAnyAddr() const
 {
-    return IN6_IS_ADDR_UNSPECIFIED( &m_SocketAddr.sin6_addr );
+    return IN6_IS_ADDR_UNSPECIFIED( &m_SocketAddr.sin6_addr ) || IN6_ARE_ADDR_EQUAL( &m_SocketAddr.sin6_addr, &v4_anyaddr); ;
 }
 
 /// NOTE: Does NOT clear the Port stored. Ony the Address and Type.
@@ -237,6 +237,11 @@
         return true;
     }
 
+    if ( IsNoAddr() ) {
+        m_SocketAddr.sin6_addr = v4_noaddr;
+        return true;
+    }
+
     if ( IsIPv4())
         return true;
 
@@ -279,7 +284,8 @@
 Ip::Address::IsNoAddr() const
 {
     // IFF the address == 0xff..ff (all ones)
-    return IN6_ARE_ADDR_EQUAL( &m_SocketAddr.sin6_addr, &v6_noaddr );
+    return IN6_ARE_ADDR_EQUAL( &m_SocketAddr.sin6_addr, &v6_noaddr )
+        || IN6_ARE_ADDR_EQUAL( &m_SocketAddr.sin6_addr, &v4_noaddr );
 }
 
 void

=== modified file 'src/ip/Address.h'
--- src/ip/Address.h	2011-07-23 08:37:52 +0000
+++ src/ip/Address.h	2011-08-01 15:50:09 +0000
@@ -123,16 +123,14 @@
     /* methods */
 
     /** Test whether content can be used as an IPv4 address
-     \retval true  if content was received as an IPv4 address
      \retval true  if content was received as an IPv4-Mapped address
      \retval false if content was received as a non-mapped IPv6 native address.
      */
     bool IsIPv4() const;
 
     /** Test whether content can be used as an IPv6 address.
-     \retval true  if --enable-ipv6 has been compiled.
-     \retval false if --disable-ipv6 has been compiled.
-     \retval false if --with-ipv6-split-stack has been compiled AND content is IPv4-mapped.
+     \retval true  if content is a non IPv4-mapped address.
+     \retval false if content is IPv4-mapped.
      */
     bool IsIPv6() const;
 

Reply via email to