VirtualBox

Changeset 60501 in vbox


Ignore:
Timestamp:
Apr 14, 2016 4:17:45 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
106611
Message:

FE/VBoxManage: Added "natnetwork list [<pattern>]" for listing / filtering all defined NAT networks.

Location:
trunk/src/VBox/Frontends/VBoxManage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageHelp.cpp

    r60315 r60501  
    55
    66/*
    7  * Copyright (C) 2006-2015 Oracle Corporation
     7 * Copyright (C) 2006-2016 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    13391339                           "%s natnetwork %s      start --netname <name>\n\n"
    13401340                           "%s natnetwork %s      stop --netname <name>\n"
    1341                      "\n", SEP, SEP, SEP, SEP, SEP);
     1341                           "%s natnetwork %s      list [<pattern>]\n"
     1342                     "\n", SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP, SEP);
    13421343
    13431344
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageNATNetwork.cpp

    r57358 r60501  
    55
    66/*
    7  * Copyright (C) 2006-2013 Oracle Corporation
     7 * Copyright (C) 2006-2016 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    8383typedef std::vector<std::string>  LOOPBACK2DELETEADD;
    8484typedef LOOPBACK2DELETEADD::iterator LOOPBACK2DELETEADDITERATOR;
     85
     86static HRESULT printNATNetwork(const ComPtr<INATNetwork> &pNATNet)
     87{
     88    HRESULT rc;
     89
     90    do
     91    {
     92        Bstr strVal;
     93        CHECK_ERROR_BREAK(pNATNet, COMGETTER(NetworkName)(strVal.asOutParam()));
     94        RTPrintf("Name:        %ls\n", strVal.raw());
     95        CHECK_ERROR_BREAK(pNATNet, COMGETTER(Network)(strVal.asOutParam()));
     96        RTPrintf("Network:     %ls\n", strVal.raw());
     97        CHECK_ERROR_BREAK(pNATNet, COMGETTER(Gateway)(strVal.asOutParam()));
     98        RTPrintf("Gateway:     %ls\n", strVal.raw());
     99        BOOL fVal;
     100        CHECK_ERROR_BREAK(pNATNet, COMGETTER(IPv6Enabled)(&fVal));
     101        RTPrintf("IPv6:        %s\n",  fVal ? "Yes" : "No");
     102        if (fVal)
     103        {
     104            CHECK_ERROR_BREAK(pNATNet, COMGETTER(IPv6Prefix)(strVal.asOutParam()));
     105            RTPrintf("IPv6 Prefix: %s\n", strVal.raw());
     106        }
     107        CHECK_ERROR_BREAK(pNATNet, COMGETTER(Enabled)(&fVal));
     108        RTPrintf("Enabled:     %s\n",  fVal ? "Yes" : "No");
     109        /** @todo Add more information here. */
     110        RTPrintf("\n");
     111
     112    } while (0);
     113
     114    return rc;
     115}
     116
     117static RTEXITCODE handleList(HandlerArg *a)
     118{
     119    HRESULT rc;
     120
     121    RTPrintf("NAT Networks:\n\n");
     122
     123    const char *pszFilter = NULL;
     124    if (a->argc > 1)
     125        pszFilter = a->argv[1];
     126
     127    size_t cFound = 0;
     128
     129    com::SafeIfaceArray<INATNetwork> arrNetNets;
     130    CHECK_ERROR(a->virtualBox, COMGETTER(NATNetworks)(ComSafeArrayAsOutParam(arrNetNets)));
     131    for (size_t i = 0; i < arrNetNets.size(); ++i)
     132    {
     133        ComPtr<INATNetwork> pNATNet = arrNetNets[i];
     134
     135        if (pszFilter)
     136        {
     137            Bstr strVal;
     138            CHECK_ERROR_BREAK(pNATNet, COMGETTER(NetworkName)(strVal.asOutParam()));
     139
     140            Utf8Str strValUTF8 = Utf8Str(strVal);
     141            if (!RTStrSimplePatternMatch(pszFilter,  strValUTF8.c_str()))
     142                continue;
     143        }
     144
     145        if (i > 0)
     146            RTPrintf("\n");
     147        rc = printNATNetwork(pNATNet);
     148        if (FAILED(rc))
     149            break;
     150
     151        cFound++;
     152    }
     153
     154    if (SUCCEEDED(rc))
     155        RTPrintf("%zu %s found\n", cFound, cFound == 1 ? "network" : "networks");
     156
     157    return SUCCEEDED(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     158}
    85159
    86160static RTEXITCODE handleOp(HandlerArg *a, OPCODE enmCode)
     
    440514    else if (strcmp(a->argv[0], "stop") == 0)
    441515        rcExit = handleOp(a, OP_STOP);
     516    else if (strcmp(a->argv[0], "list") == 0)
     517        rcExit = handleList(a);
    442518    else
    443519        rcExit = errorSyntax(USAGE_NATNETWORK, "Invalid parameter '%s'", Utf8Str(a->argv[0]).c_str());
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