[Common-dev] Re: [Common-cvs] util netbyte.cpp,1.9,1.10

[Common-dev] Re: [Common-cvs] util netbyte.cpp,1.9,1.10

Dean Collins dcollins at real.com
Sat Sep 18 08:40:21 PDT 2004


This check-in caused a build-buster for the server so I ifdef'd out the
routine that is causing the problem.

netbyte.cpp: In function `int NetAddressToAscii(const sockaddr*, IHXBuffer*)':
netbyte.cpp:544: error: 'const struct in_addr' has no member named 'S_un'
netbyte.cpp:555: error: 'const struct in6_addr' has no member named 'u'


Dean


On Sat, Sep 18, 2004 at 12:32:29AM +0000, ping at helixcommunity.org wrote:
> Update of /cvsroot/common/util
> In directory cvs-new:/tmp/cvs-serv29590
> 
> Modified Files:
> 	netbyte.cpp 
> Log Message:
> added utility functions for IPv6
> 
> 
> 
> Index: netbyte.cpp
> ===================================================================
> RCS file: /cvsroot/common/util/netbyte.cpp,v
> retrieving revision 1.9
> retrieving revision 1.10
> diff -u -d -r1.9 -r1.10
> --- netbyte.cpp	9 Jul 2004 18:23:51 -0000	1.9
> +++ netbyte.cpp	18 Sep 2004 00:32:27 -0000	1.10
> @@ -485,3 +485,88 @@
>      return str;
>  }
>  
> +UINT32
> +CalculateIPv4Prefix(UINT8* pin)
> +{
> +    BOOL   bDone = FALSE;
> +    UINT32 i, j = 0;
> +    UINT32 ulResult = 0;
> +    
> +    if (pin)
> +    {
> +        for (i = 0; i < 4; i++)
> +        {
> +            if (255 == pin[i])
> +            {
> +                ulResult+=8;
> +            }
> +            else
> +            {
> +                for (j = 0; j < 8; j++)
> +                {
> +                    if ((0x80 >> j) & pin[i])
> +                    {
> +                        ulResult++;
> +                    }
> +                    else
> +                    {
> +                        bDone = TRUE;
> +                        break;
> +                    }
> +                }
> +            }
> +
> +            if (bDone)
> +            {
> +                break;
> +            }
> +        }
> +    }
> +
> +    return ulResult;
> +}
> +
> +int
> +NetAddressToAscii(const struct sockaddr* pAddr, IHXBuffer* pBuffer)
> +{
> +    int result = -1;
> +
> +    if (pBuffer && pAddr)
> +    {
> +        char szAddress[40] = {0}; // max. IPv6 address length
> +
> +        struct sockaddr* pa = (struct sockaddr*)pAddr;
> +        switch (pa->sa_family)
> +        {
> +        case AF_INET:
> +            {
> +                const struct sockaddr_in* psa = reinterpret_cast<const struct sockaddr_in*>(pa);
> +                const u_char* pin = &psa->sin_addr.S_un.S_un_b.s_b1;
> +
> +                sprintf(szAddress, "%u.%u.%u.%u", pin[0], pin[1], pin[2], pin[3]);
> +                pBuffer->Set((const unsigned char*)szAddress, strlen(szAddress) + 1);
> +        
> +                result = 0;
> +            }
> +            break;
> +        case AF_INET6:
> +            {
> +                const struct sockaddr_in6* psa = reinterpret_cast<const struct sockaddr_in6*>(pa);
> +                const u_short* pin = psa->sin6_addr.u.Word;
> +
> +                sprintf(szAddress, "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n", 
> +                    WToHost(pin[0]), WToHost(pin[1]), WToHost(pin[2]), WToHost(pin[3]), 
> +                    WToHost(pin[4]), WToHost(pin[5]), WToHost(pin[6]), WToHost(pin[7]));
> +                pBuffer->Set((const unsigned char*)szAddress, strlen(szAddress) + 1);
> +
> +                result = 0;
> +            }
> +            break;
> +        default:
> +            HX_ASSERT(FALSE);
> +            break;
> +        }
> +    }
> +
> +    return result;
> +}
> 
> 
> _______________________________________________
> Common-cvs mailing list
> Common-cvs at lists.helixcommunity.org
> http://lists.helixcommunity.org/mailman/listinfo/common-cvs

-- 
Dean Collins
Server Technical Lead, RealNetworks, Inc. -- http://www.realnetworks.com
Helix Server Project Owner -- http://helix-server.helixcommunity.org



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.