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.

We should rename the IsIPv6() method to IsIpv6Only(), to avoid confusion. And then maybe implement an new IsIPv6 method, which for now will return always true (my sense is that everything can be an ipv6 address).





Thank you,

Alex.


Reply via email to