VirtualBox

Changeset 45115 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 21, 2013 8:01:54 AM (12 years ago)
Author:
vboxsync
Message:

RT/net: rt-network-str2ipv4.patch from xTRacker/5894 with applyed recommendations in comment 90.
introduces RTNetStrToIPv4Addr: char* -> RTNETADDRIP4.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/getopt.cpp

    r44528 r45115  
    9393 * Converts an stringified IPv4 address into the RTNETADDRIPV4 representation.
    9494 *
    95  * @todo This should be move to some generic part of the runtime.
    96  *
    9795 * @returns VINF_SUCCESS on success, VERR_GETOPT_INVALID_ARGUMENT_FORMAT on
    9896 *          failure.
     
    103101static int rtgetoptConvertIPv4Addr(const char *pszValue, PRTNETADDRIPV4 pAddr)
    104102{
    105     char *pszNext;
    106     int rc = RTStrToUInt8Ex(RTStrStripL(pszValue), &pszNext, 10, &pAddr->au8[0]);
    107     if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
    108         return VERR_GETOPT_INVALID_ARGUMENT_FORMAT;
    109     if (*pszNext++ != '.')
    110         return VERR_GETOPT_INVALID_ARGUMENT_FORMAT;
    111 
    112     rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[1]);
    113     if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
    114         return VERR_GETOPT_INVALID_ARGUMENT_FORMAT;
    115     if (*pszNext++ != '.')
    116         return VERR_GETOPT_INVALID_ARGUMENT_FORMAT;
    117 
    118     rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[2]);
    119     if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
    120         return VERR_GETOPT_INVALID_ARGUMENT_FORMAT;
    121     if (*pszNext++ != '.')
    122         return VERR_GETOPT_INVALID_ARGUMENT_FORMAT;
    123 
    124     rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[3]);
    125     if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_SPACES)
    126         return VERR_GETOPT_INVALID_ARGUMENT_FORMAT;
    127     pszNext = RTStrStripL(pszNext);
    128     if (*pszNext)
    129         return VERR_GETOPT_INVALID_ARGUMENT_FORMAT;
    130 
     103    if (RT_FAILURE(RTNetStrToIPv4Addr(pszValue, pAddr)))
     104        return VERR_GETOPT_INVALID_ARGUMENT_FORMAT;
    131105    return VINF_SUCCESS;
    132106}
  • trunk/src/VBox/Runtime/common/net/netaddrstr.cpp

    r43221 r45115  
    12851285RT_EXPORT_SYMBOL(RTNetIsIPv4AddrStr);
    12861286
     1287RTDECL(int) RTNetStrToIPv4Addr(const char *pszAddr, PRTNETADDRIPV4 pAddr)
     1288{
     1289    char *pszNext;
     1290    AssertPtrReturn(pszAddr, VERR_INVALID_PARAMETER);
     1291    AssertPtrReturn(pAddr, VERR_INVALID_PARAMETER);
     1292
     1293    int rc = RTStrToUInt8Ex(RTStrStripL(pszAddr), &pszNext, 10, &pAddr->au8[0]);
     1294    if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
     1295        return VERR_INVALID_PARAMETER;
     1296    if (*pszNext++ != '.')
     1297        return VERR_INVALID_PARAMETER;
     1298
     1299    rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[1]);
     1300    if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
     1301        return VERR_INVALID_PARAMETER;
     1302    if (*pszNext++ != '.')
     1303        return VERR_INVALID_PARAMETER;
     1304
     1305    rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[2]);
     1306    if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_CHARS)
     1307        return VERR_INVALID_PARAMETER;
     1308    if (*pszNext++ != '.')
     1309        return VERR_INVALID_PARAMETER;
     1310
     1311    rc = RTStrToUInt8Ex(pszNext, &pszNext, 10, &pAddr->au8[3]);
     1312    if (rc != VINF_SUCCESS && rc != VWRN_TRAILING_SPACES)
     1313        return VERR_INVALID_PARAMETER;
     1314    pszNext = RTStrStripL(pszNext);
     1315    if (*pszNext)
     1316        return VERR_INVALID_PARAMETER;
     1317
     1318    return VINF_SUCCESS;
     1319}
     1320RT_EXPORT_SYMBOL(RTNetStrToIPv4Addr);
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