VirtualBox

Ignore:
Timestamp:
Feb 5, 2021 12:33:52 AM (4 years ago)
Author:
vboxsync
Message:

NAT/Net: Factor out VBoxNetLwipNAT::getExtraData(). bugref:9929.

File:
1 edited

Legend:

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

    r87616 r87617  
    179179    int eventsInit();
    180180
     181    int getExtraData(com::Utf8Str &strValueOut, const char *pcszKey);
     182
    181183    static void reportError(const char *a_pcszFormat, ...) RT_IPRT_FORMAT_ATTR(1, 2);
    182184
     
    379381     * IPv4 source address, if configured.
    380382     */
    381     com::Bstr bstrSourceIp4;
    382     com::Bstr bstrSourceIp4Key = com::BstrFmt("NAT/%s/SourceIp4", networkName.c_str());
    383     hrc = virtualbox->GetExtraData(bstrSourceIp4Key.raw(), bstrSourceIp4.asOutParam());
    384     if (SUCCEEDED(hrc) && bstrSourceIp4.isNotEmpty())
     383    com::Utf8Str strSourceIp4;
     384    rc = getExtraData(strSourceIp4, "SourceIp4");
     385    if (RT_SUCCESS(rc) && strSourceIp4.isNotEmpty())
    385386    {
    386387        RTNETADDRIPV4 addr;
     
    406407    if (fIPv6Enabled)
    407408    {
    408         com::Bstr bstrSourceIp6;
    409         com::Bstr bstrSourceIp6Key = com::BstrFmt("NAT/%s/SourceIp6", networkName.c_str());
    410         hrc = virtualbox->GetExtraData(bstrSourceIp6Key.raw(), bstrSourceIp6.asOutParam());
    411         if (SUCCEEDED(hrc) && bstrSourceIp6.isNotEmpty())
     409        com::Utf8Str strSourceIp6;
     410        rc = getExtraData(strSourceIp6, "SourceIp6");
     411        if (RT_SUCCESS(rc) && strSourceIp6.isNotEmpty())
    412412        {
    413413            RTNETADDRIPV6 addr;
     
    14531453
    14541454
     1455/**
     1456 * Retrieve network-specific extra data item.
     1457 */
     1458int VBoxNetLwipNAT::getExtraData(com::Utf8Str &strValueOut, const char *pcszKey)
     1459{
     1460    HRESULT hrc;
     1461
     1462    AssertReturn(!virtualbox.isNull(), E_FAIL);
     1463    AssertReturn(!getNetworkName().empty(), E_FAIL);
     1464    AssertReturn(pcszKey != NULL, E_FAIL);
     1465    AssertReturn(*pcszKey != '\0', E_FAIL);
     1466
     1467    com::BstrFmt bstrKey("NAT/%s/%s", networkName.c_str(), pcszKey);
     1468    com::Bstr bstrValue;
     1469    hrc = virtualbox->GetExtraData(bstrKey.raw(), bstrValue.asOutParam());
     1470    if (FAILED(hrc))
     1471    {
     1472        reportComError(virtualbox, "GetExtraData", hrc);
     1473        return VERR_GENERAL_FAILURE;
     1474    }
     1475
     1476    strValueOut = bstrValue;
     1477    return VINF_SUCCESS;
     1478}
     1479
     1480
    14551481/* static */
    14561482HRESULT VBoxNetLwipNAT::reportComError(ComPtr<IUnknown> iface,
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