VirtualBox

Changeset 87549 in vbox for trunk/src


Ignore:
Timestamp:
Feb 3, 2021 2:12:36 AM (4 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
142576
Message:

NAT/Net: Plagiarize (but paraphrase) COM error reporting code from
VBoxManage. Don't assert we are passed an existing network, report
that we failed to find it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp

    r87450 r87549  
    173173
    174174private:
     175    static void reportError(const char *a_pcszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
     176
     177    static HRESULT reportComError(ComPtr<IUnknown> iface,
     178                                  const com::Utf8Str &strContext,
     179                                  HRESULT hrc);
     180    static void reportErrorInfoList(const com::ErrorInfo &info,
     181                                    const com::Utf8Str &strContext);
     182    static void reportErrorInfo(const com::ErrorInfo &info);
     183
    175184    void createRawSock4();
    176185    void createRawSock6();
     
    308317int VBoxNetLwipNAT::init()
    309318{
     319    HRESULT hrc;
     320    int rc;
     321
    310322    LogFlowFuncEnter();
    311323
    312324    /* virtualbox initialized in the superclass */
    313     int rc = ::VBoxNetBaseService::init();
    314     AssertRCReturn(rc, rc);
    315 
    316     std::string networkName = getNetworkName();
    317     rc = findNatNetwork(virtualbox, networkName, m_net);
    318     AssertRCReturn(rc, rc);
     325    rc = VBoxNetBaseService::init();
     326    if (RT_FAILURE(rc))
     327        return rc;
     328
     329    const std::string &networkName = getNetworkName();
     330    hrc = virtualbox->FindNATNetworkByName(com::Bstr(networkName.c_str()).raw(),
     331                                           m_net.asOutParam());
     332    if (FAILED(hrc))
     333    {
     334        reportComError(virtualbox, "FindNATNetworkByName", hrc);
     335        return VERR_NOT_FOUND;
     336    }
     337
    319338
    320339    {
     
    329348    // resolver changes are reported on vbox but are retrieved from
    330349    // host so stash a pointer for future lookups
    331     HRESULT hrc = virtualbox->COMGETTER(Host)(m_host.asOutParam());
     350    hrc = virtualbox->COMGETTER(Host)(m_host.asOutParam());
    332351    AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
    333352
     
    13151334
    13161335
     1336/* static */
     1337HRESULT VBoxNetLwipNAT::reportComError(ComPtr<IUnknown> iface,
     1338                                       const com::Utf8Str &strContext,
     1339                                       HRESULT hrc)
     1340{
     1341    const com::ErrorInfo info(iface, COM_IIDOF(IUnknown));
     1342    if (info.isFullAvailable() || info.isBasicAvailable())
     1343    {
     1344        reportErrorInfoList(info, strContext);
     1345    }
     1346    else
     1347    {
     1348        if (strContext.isNotEmpty())
     1349            reportError("%s: %Rhra", strContext.c_str(), hrc);
     1350        else
     1351            reportError("%Rhra", hrc);
     1352    }
     1353
     1354    return hrc;
     1355}
     1356
     1357
     1358/* static */
     1359void VBoxNetLwipNAT::reportErrorInfoList(const com::ErrorInfo &info,
     1360                                         const com::Utf8Str &strContext)
     1361{
     1362    if (strContext.isNotEmpty())
     1363        reportError("%s", strContext.c_str());
     1364
     1365    bool fFirst = true;
     1366    for (const com::ErrorInfo *pInfo = &info;
     1367         pInfo != NULL;
     1368         pInfo = pInfo->getNext())
     1369    {
     1370        if (fFirst)
     1371            fFirst = false;
     1372        else
     1373            reportError("--------");
     1374
     1375        reportErrorInfo(*pInfo);
     1376    }
     1377}
     1378
     1379
     1380/* static */
     1381void VBoxNetLwipNAT::reportErrorInfo(const com::ErrorInfo &info)
     1382{
     1383#if defined (RT_OS_WIN)
     1384    bool haveResultCode = info.isFullAvailable();
     1385    bool haveComponent = true;
     1386    bool haveInterfaceID = true;
     1387#else /* !RT_OS_WIN */
     1388    bool haveResultCode = true;
     1389    bool haveComponent = info.isFullAvailable();
     1390    bool haveInterfaceID = info.isFullAvailable();
     1391#endif
     1392    com::Utf8Str message;
     1393    if (info.getText().isNotEmpty())
     1394        message = info.getText();
     1395
     1396    const char *pcszDetails = "Details: ";
     1397    const char *pcszComma = ", ";
     1398    const char *pcszSeparator = pcszDetails;
     1399
     1400    if (haveResultCode)
     1401    {
     1402        message.appendPrintf("%s" "code %Rhrc (0x%RX32)",
     1403            pcszSeparator, info.getResultCode(), info.getResultCode());
     1404        pcszSeparator = pcszComma;
     1405    }
     1406
     1407    if (haveComponent)
     1408    {
     1409        message.appendPrintf("%s" "component %ls",
     1410            pcszSeparator, info.getComponent().raw());
     1411        pcszSeparator = pcszComma;
     1412    }
     1413
     1414    if (haveInterfaceID)
     1415    {
     1416        message.appendPrintf("%s" "interface %ls",
     1417            pcszSeparator, info.getInterfaceName().raw());
     1418        pcszSeparator = pcszComma;
     1419    }
     1420
     1421    if (info.getCalleeName().isNotEmpty())
     1422    {
     1423        message.appendPrintf("%s" "callee %ls",
     1424            pcszSeparator, info.getCalleeName().raw());
     1425        pcszSeparator = pcszComma;
     1426    }
     1427
     1428    reportError("%s", message.c_str());
     1429}
     1430
     1431
     1432/* static */
     1433void VBoxNetLwipNAT::reportError(const char *a_pcszFormat, ...)
     1434{
     1435    va_list ap;
     1436
     1437    va_start(ap, a_pcszFormat);
     1438    com::Utf8Str message(a_pcszFormat, ap);
     1439    va_end(ap);
     1440
     1441    RTMsgError("%s", message.c_str());
     1442    LogRel(("%s", message.c_str()));
     1443}
     1444
     1445
     1446
    13171447/**
    13181448 * Create release logger.
Note: See TracChangeset for help on using the changeset viewer.

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