VirtualBox

Changeset 50457 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Feb 14, 2014 2:36:48 AM (11 years ago)
Author:
vboxsync
Message:

RTSocketQueryAddressStr: don't reinvent %RTnaipv4 and %RTnaipv6.
This gets rid of the only rtStrToIpAddr6Str() reference, the fact that
IPv6 address is now correctly nul-terminated is a bonus.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/socket.cpp

    r48935 r50457  
    783783    {
    784784        struct sockaddr_in const *pgrSa = (struct sockaddr_in const *)pgrResult->ai_addr;
    785         pbDummy = (uint8_t const *)&pgrSa->sin_addr;
    786         cchIpAddress = RTStrPrintf(szIpAddress, sizeof(szIpAddress), "%u.%u.%u.%u",
    787                                    pbDummy[0], pbDummy[1], pbDummy[2], pbDummy[3]);
     785        cchIpAddress = RTStrPrintf(szIpAddress, sizeof(szIpAddress),
     786                                   "%RTnaipv4", pgrSa->sin_addr.s_addr);
    788787        Assert(cchIpAddress >= 7 && cchIpAddress < sizeof(szIpAddress) - 1);
    789788        enmAddrType = RTNETADDRTYPE_IPV4;
     
    793792    {
    794793        struct sockaddr_in6 const *pgrSa6 = (struct sockaddr_in6 const *)pgrResult->ai_addr;
    795         pbDummy = (uint8_t const *) &pgrSa6->sin6_addr;
    796         char szTmp[32+1];
    797         size_t cchTmp = RTStrPrintf(szTmp, sizeof(szTmp),
    798                                     "%02x%02x%02x%02x"
    799                                     "%02x%02x%02x%02x"
    800                                     "%02x%02x%02x%02x"
    801                                     "%02x%02x%02x%02x",
    802                                     pbDummy[0],  pbDummy[1],  pbDummy[2],  pbDummy[3],
    803                                     pbDummy[4],  pbDummy[5],  pbDummy[6],  pbDummy[7],
    804                                     pbDummy[8],  pbDummy[9],  pbDummy[10], pbDummy[11],
    805                                     pbDummy[12], pbDummy[13], pbDummy[14], pbDummy[15]);
    806         Assert(cchTmp == 32);
    807         rc = rtStrToIpAddr6Str(szTmp, szIpAddress, sizeof(szIpAddress), NULL, 0, true);
    808         if (RT_SUCCESS(rc))
    809             cchIpAddress = strlen(szIpAddress);
    810         else
    811         {
    812             szIpAddress[0] = '\0';
    813             cchIpAddress = 0;
    814         }
     794        cchIpAddress = RTStrPrintf(szIpAddress, sizeof(szIpAddress),
     795                                   "%RTnaipv6", (PRTNETADDRIPV6)&pgrSa6->sin6_addr);
    815796        enmAddrType = RTNETADDRTYPE_IPV6;
     797        rc = VINF_SUCCESS;
    816798    }
    817799    else
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette