VirtualBox

Changeset 71435 in vbox for trunk/src


Ignore:
Timestamp:
Mar 21, 2018 2:30:29 PM (7 years ago)
Author:
vboxsync
Message:

IPRT/net: RTNetStrToIPv4AddrEx - return VWRN_TRAILING_SPACES and
VWRN_TRAILING_CHARS. Adapt callers. Add more test cases to make sure
trailers are handled as before.

Location:
trunk/src/VBox/Runtime
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/net/netaddrstr2.cpp

    r69111 r71435  
    7272    if (ppszNext != NULL)
    7373        *ppszNext = pszNext;
    74     return VINF_SUCCESS;
     74    return rc;
    7575}
    7676
     
    9494    pcszAddr = RTStrStripL(pcszAddr);
    9595    rc = rtNetStrToIPv4AddrEx(pcszAddr, pAddr, &pszNext);
    96     if (rc != VINF_SUCCESS)
    97         return VERR_INVALID_PARAMETER;
    98 
    99     pszNext = RTStrStripL(pszNext);
    100     if (*pszNext != '\0')
     96    if (RT_FAILURE(rc) || rc == VWRN_TRAILING_CHARS)
    10197        return VERR_INVALID_PARAMETER;
    10298
     
    138134    pcszAddr = RTStrStripL(pcszAddr);
    139135    rc = rtNetStrToIPv4AddrEx(pcszAddr, &addrIPv4, &pszNext);
    140     if (rc != VINF_SUCCESS)
    141         return false;
    142 
    143     pszNext = RTStrStripL(pszNext);
    144     if (*pszNext != '\0')
     136    if (RT_FAILURE(rc) || rc == VWRN_TRAILING_CHARS)
    145137        return false;
    146138
  • trunk/src/VBox/Runtime/testcase/tstRTNetIPv4.cpp

    r69111 r71435  
    9797
    9898
     99#define CHECKISADDR(String, fExpected)                                  \
     100    do {                                                                \
     101        bool fRc = RTNetIsIPv4AddrStr(String);                          \
     102        if (fRc != fExpected)                                           \
     103        {                                                               \
     104            RTTestIFailed("at line %d: '%s':"                           \
     105                          " expected %RTbool got %RTbool\n",            \
     106                          __LINE__, (String), fExpected, fRc);          \
     107        }                                                               \
     108    } while (0)
     109
     110#define IS_ADDR(String)  CHECKISADDR((String), true)
     111#define NOT_ADDR(String) CHECKISADDR((String), false)
     112
     113
    99114#define CHECKANY(String, fExpected)                                     \
    100115    do {                                                                \
     
    256271     */
    257272    CHECKADDREX("1.2.3.4",  "",   VINF_SUCCESS,           0x01020304);
    258     CHECKADDREX("1.2.3.4",  " ",  VINF_SUCCESS,           0x01020304);
    259     CHECKADDREX("1.2.3.4",  "x",  VINF_SUCCESS,           0x01020304);
     273    CHECKADDREX("1.2.3.4",  " ",  VWRN_TRAILING_SPACES,   0x01020304);
     274    CHECKADDREX("1.2.3.4",  "x",  VWRN_TRAILING_CHARS,    0x01020304);
    260275    CHECKADDREX("1.2.3.444", "",  VERR_INVALID_PARAMETER,          0);
    261276
     277    /* NB: RTNetIsIPv4AddrStr does NOT allow leading/trailing whitespace */
     278    IS_ADDR("1.2.3.4");
     279    NOT_ADDR(" 1.2.3.4");
     280    NOT_ADDR("1.2.3.4 ");
     281    NOT_ADDR("1.2.3.4x");
    262282
    263283    IS_ANY("0.0.0.0");
    264     IS_ANY("\t 0.0.0.0 \t");
     284    IS_ANY("\t 0.0.0.0 \t");    /* ... but RTNetStrIsIPv4AddrAny does */
    265285
    266286    NOT_ANY("1.1.1.1");         /* good address, but not INADDR_ANY */
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