[Common-dev] Re: CR Bug 14035. Fix for ipv6 Bind,DoRead.

[Common-dev] Re: CR Bug 14035. Fix for ipv6 Bind,DoRead.

Sujeet Kharkar skharkar at real.com
Thu Aug 4 15:28:19 PDT 2005


Thanks JJ for catching this.

On Solaris declaration
char* strchr( char*, int );

On Windows & Linux it
char* strchr( const char*, int )

so I removed const char* typecast.

Thanks
Sujeet

P.S :- I had tested & build this on windows & linux  and was running a 
build system build on solaris to verify before sending check-in email.




At 03:01 PM 8/4/2005 -0700, Tom Marshall wrote:
>On Thu, Aug 04, 2005 at 02:55:14PM -0700, JJ Zeng wrote:
> > This broke the build on solaris:
> >
> > "platform/posix/sockimp.cpp", line 707: Error: Cannot use const char* to
> > initialize char*.
>
>That's an easy fix -- everything should be const except the local char
>array.
>
> >
> > JJ
> > On Wed, Aug 03, 2005 at 08:19:03PM -0700, Sujeet Kharkar wrote:
> > > At 07:16 PM 8/3/2005 -0700, Tom Marshall wrote:
> > >
> > >
> > > Please find attached new diff, to take of this suggestions.
> > >
> > > Thanks
> > > Sujeet
> > >
> > >
> > > >On Wed, Aug 03, 2005 at 06:37:18PM -0700, Sujeet Kharkar wrote:
> > > >> At 09:29 AM 8/3/2005 -0700, Sujeet Kharkar wrote:
> > > >>
> > > >> Please see the attached diff. (Only included the part, which have not
> > > >yet been
> > > >> CR)
> > > >>
> > > >> This takes advantage of the fact that IPv6 addresses may only be
> > > >> HX_ADDRSTRLEN_IN6 octets as suggested by Tommy and also avoids a 
> memcpy
> > > >when no
> > > >> % is specified.
> > > >
> > > >Looks pretty good.  Just some minor comments...
> > > >
> > > >> @@ -695,14 +695,45 @@
> > > >>  STDMETHODIMP
> > > >>  CHXSockAddrIN6::SetAddr(IHXBuffer* pBuf)
> > > >>  {
> > > >> +    HX_RESULT res = HXR_OK;
> > > >>      HX_ASSERT(m_nRefCount == 1);
> > > >>      HX_ASSERT(pBuf != NULL && pBuf->GetBuffer() != NULL);
> > > >>      HX_ASSERT(*(pBuf->GetBuffer()+pBuf->GetSize()-1) == 0);
> > > >> -    if (hx_inet_pton(AF_INET6, (const char*)pBuf->GetBuffer(),
> > > >&m_addr.sin6_addr) <= 0)
> > > >> +
> > > >> +    char szBareAddr[HX_ADDRSTRLEN_IN6];
> > > >> +    char* pszBareAddr = NULL;
> > > >> +    char* pszIPV6Addr = (char*)pBuf->GetBuffer();
> > > >> +
> > > >> +    CHAR* pscopeid_delimiter = strchr((const char*)pszIPV6Addr,'%');
> > > >
> > > >What is the difference between char and CHAR?
> > > >
> > > >> +    if ( pscopeid_delimiter )
> > > >
> > > >This file uses the server coding style with no space inside the parens.
> > > >Could you match that for this change?
> > > >
> > > >> +     szBareAddr[ulBytesToCopy] = NULL;
> > > >
> > > >The rhs on this assignment should be '\0'.
> > > >
> > > >--
> > > >Paranoid Club meeting this Friday.  Now ... just try to find out where!
> >
> > >
> > > Index: platform/posix/sockimp.cpp
> > > ===================================================================
> > > RCS file: /cvsroot/common/netio/platform/posix/sockimp.cpp,v
> > > retrieving revision 1.61.2.18
> > > diff -u -r1.61.2.18 sockimp.cpp
> > > --- platform/posix/sockimp.cpp      26 Jul 2005 19:31:21 
> -0000      1.61.2.18
> > > +++ platform/posix/sockimp.cpp      4 Aug 2005 03:13:34 -0000
> > > @@ -695,14 +695,45 @@
> > >  STDMETHODIMP
> > >  CHXSockAddrIN6::SetAddr(IHXBuffer* pBuf)
> > >  {
> > > +    HX_RESULT res = HXR_OK;
> > >      HX_ASSERT(m_nRefCount == 1);
> > >      HX_ASSERT(pBuf != NULL && pBuf->GetBuffer() != NULL);
> > >      HX_ASSERT(*(pBuf->GetBuffer()+pBuf->GetSize()-1) == 0);
> > > -    if (hx_inet_pton(AF_INET6, (const char*)pBuf->GetBuffer(), 
> &m_addr.sin6_addr) <= 0)
> > > +
> > > +    char szBareAddr[HX_ADDRSTRLEN_IN6];
> > > +    char* pszBareAddr = NULL;
> > > +    char* pszIPV6Addr = (char*)pBuf->GetBuffer();
> > > +
> > > +    char* pscopeid_delimiter = strchr((const char*)pszIPV6Addr,'%');
> > > +    if (pscopeid_delimiter)
> > >      {
> > > -        return HXR_FAIL;
> > > +        res = SetScopeIDFromBuffer(pscopeid_delimiter+1);
> > > +        if (FAILED(res))
> > > +        {
> > > +            return res;
> > > +        }
> > > +
> > > +        UINT32 ulBytesToCopy = pscopeid_delimiter-pszIPV6Addr;
> > > +        if (ulBytesToCopy >= sizeof(szBareAddr))
> > > +        {
> > > +            return HXR_INVALID_PARAMETER;
> > > +        }
> > > +
> > > +        memcpy(szBareAddr, pszIPV6Addr, ulBytesToCopy);
> > > +        szBareAddr[ulBytesToCopy] = '\0';
> > > +        pszBareAddr = szBareAddr;
> > >      }
> > > -    return HXR_OK;
> > > +    else
> > > +    {
> > > +        pszBareAddr = pszIPV6Addr;
> > > +    }
> > > +
> > > +    if (hx_inet_pton(AF_INET6, (const char*)pszBareAddr, 
> &m_addr.sin6_addr) <= 0)
> > > +    {
> > > +        res = HXR_FAIL;
> > > +    }
> > > +
> > > +    return res;
> > >  }
> > >
> > >
> > > +//private function.
> > > +//Assumes that pScopeId is valid ptr(Not Null) and points to scopeid.
> > > +HX_RESULT
> > > +CHXSockAddrIN6::SetScopeIDFromBuffer(const char* pScopeId)
> > > +{
> > > +    HX_ASSERT(pScopeId);
> > >
> > > +    HX_RESULT hxr = HXR_OK;
> > > +    UINT32 uiscopeid = 0;
> > > +    char* pEnd = NULL;
> > > +    if (*pScopeId)
> > > +    {
> > > +        uiscopeid = strtol(pScopeId, &pEnd, 10);
> > > +
> > > +        if ((uiscopeid == LONG_MAX) || (uiscopeid == LONG_MIN))
> > > +        {
> > > +            //out of range.
> > > +            return HXR_FAIL;
> > > +        }
> > > +
> > > +        if (pEnd && *pEnd)
> > > +        {
> > > +            //We failed to convert pScopeId to long.
> > > +            //Check if it is a interface name.
> > > +#ifdef _UNIX
> > > +            uiscopeid = if_nametoindex(pScopeId);
> > > +            if (uiscopeid == 0)
> > > +            {
> > > +                return HXR_FAIL;
> > > +            }
> > > +#else
> > > +            return HXR_FAIL;
> > > +#endif
> > > +        }
> > > +
> > > +        hxr = SetScopeId( uiscopeid );
> > > +    }
> > > +
> > > +    return hxr;
> > > +}
> > >
> > > Index: pub/platform/posix/nettypes.h
> > > ===================================================================
> > > RCS file: /cvsroot/common/netio/pub/platform/posix/nettypes.h,v
> > > retrieving revision 1.27
> > > diff -u -r1.27 nettypes.h
> > > --- pub/platform/posix/nettypes.h   15 Nov 2004 22:38:51 -0000      1.27
> > > +++ pub/platform/posix/nettypes.h   4 Aug 2005 03:13:34 -0000
> > > @@ -50,6 +50,7 @@
> > >  #include <sys/un.h>
> > >  #include <sys/uio.h>
> > >  #include <errno.h>
> > > +#include <net/if.h>
> > >  typedef int sockobj_t;
> > >  typedef int sockerr_t;
> > >  #ifndef HX_IOV_MAX
> > > Index: pub/platform/posix/sockimp.h
> > > ===================================================================
> > > RCS file: /cvsroot/common/netio/pub/platform/posix/sockimp.h,v
> > > retrieving revision 1.30.2.2
> > > diff -u -r1.30.2.2 sockimp.h
> > > --- pub/platform/posix/sockimp.h    17 Jun 2005 20:32:03 
> -0000      1.30.2.2
> > > +++ pub/platform/posix/sockimp.h    4 Aug 2005 03:13:34 -0000
> > > @@ -147,6 +147,7 @@
> > >                              sockaddr_storage* pss,
> > >                              sockaddr_in6** psa);
> > >
> > > +    inline HX_RESULT SetScopeIDFromBuffer(const char* pScopeId);
> > >  public:
> > >      CHXSockAddrIN6(void);
> > >      CHXSockAddrIN6(const sockaddr_in6* psa);
> >
> >
>
>--
>I stayed up all night playing poker with tarot cards.  I got a full
>house and four people died.
>         -- Steven Wright




More information about the Common-dev mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.