VirtualBox

Changeset 48096 in vbox


Ignore:
Timestamp:
Aug 27, 2013 5:00:31 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
88471
Message:

VBoxManage/NATNetwork: adds -l(--loopback-4) and -L(--loopback-6)
usage

VBoxManage natnetwork modify -t nat-test-1 -l "127.0.1.3;8"

adds mapping 127.0.1.3 to network id (of nat-test-1) +8

-L adds offset for IPv6 case.

File:
1 edited

Legend:

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

    r47704 r48096  
    4848
    4949#include <vector>
     50#include <string>
    5051
    5152#include "VBoxManage.h"
     
    7576        { "--port-forward-4",   'p', RTGETOPT_REQ_STRING },
    7677        { "--port-forward-6",   'P', RTGETOPT_REQ_STRING },
     78        { "--loopback-4",       'l', RTGETOPT_REQ_STRING },
     79        { "--loopback-6",       'L', RTGETOPT_REQ_STRING },
     80
    7781      };
    7882
     
    8993typedef VPF2ADD::const_iterator VPF2ADDITERATOR;
    9094
     95typedef std::vector<std::string>  LOOPBACK2DELETEADD;
     96typedef LOOPBACK2DELETEADD::iterator LOOPBACK2DELETEADDITERATOR;
    9197
    9298static int handleOp(HandlerArg *a, OPCODE enmCode, int iStart, int *pcProcessed)
     
    106112    VPF2DELETE vPfName2Delete;
    107113    VPF2ADD vPf2Add;
     114
     115    LOOPBACK2DELETEADD vLoopback2Delete;
     116    LOOPBACK2DELETEADD vLoopback2Add;
     117
     118    LONG loopback6Offset = 0; /* ignore me */
    108119
    109120    int c;
     
    169180                ipv6 = ValueUnion.f;
    170181                break;
     182
     183            case 'L': /* ipv6 loopback */
     184            case 'l': /* ipv4 loopback */
     185                if (RTStrCmp(ValueUnion.psz, "delete") == 0)
     186                {
     187                    /* deletion */
     188                    if (enmCode != OP_MODIFY)
     189                      errorSyntax(USAGE_NATNETWORK,
     190                                  "loopback couldn't be deleted on modified\n");
     191                    if (c == 'L')
     192                      loopback6Offset = -1;
     193                    else
     194                    {
     195                        int vrc;
     196                        RTGETOPTUNION Addr2Delete;
     197                        vrc = RTGetOptFetchValue(&GetState,
     198                                                 &Addr2Delete,
     199                                                 RTGETOPT_REQ_STRING);
     200                        if (RT_FAILURE(vrc))
     201                          return errorSyntax(USAGE_NATNETWORK,
     202                                             "Not enough parmaters\n");
     203
     204                        vLoopback2Delete.push_back(std::string(Addr2Delete.psz));
     205                    }
     206                }
     207                else /* addition */
     208                {
     209                    if (c == 'L')
     210                      loopback6Offset = ValueUnion.u32;
     211                    else
     212                      vLoopback2Add.push_back(std::string(ValueUnion.psz));
     213                }
     214                break;
    171215
    172216            case 'P': /* ipv6 portforwarding*/
     
    349393            }
    350394        }
     395       
     396        if (loopback6Offset)
     397        {
     398            if (loopback6Offset == -1)
     399                loopback6Offset = 0; /* deletion */
     400           
     401            CHECK_ERROR_RET(net, COMSETTER(LoopbackIp6)(loopback6Offset), rc);
     402        }
     403       
     404        /* addLocalMapping (hostid, offset) */
     405        if (!vLoopback2Add.empty())
     406        {
     407            /* we're expecting stings 127.0.0.1;5 */
     408            LOOPBACK2DELETEADDITERATOR it;
     409            for (it = vLoopback2Add.begin();
     410                 it != vLoopback2Add.end();
     411                 ++it)
     412            {
     413                std::string address, strOffset;
     414                int pos = it->find(';');
     415                LONG lOffset = 0;
     416                Bstr bstrAddress;
     417
     418                AssertReturn(pos != -1, errorArgument("invalid loopback string"));
     419
     420                address = it->substr(0, pos);
     421                strOffset = it->substr(pos + 1);
     422               
     423                lOffset = RTStrToUInt32(strOffset.c_str());
     424                AssertReturn(lOffset > 0, errorArgument("invalid loopback string"));
     425               
     426                bstrAddress = Bstr(address.c_str());
     427
     428                CHECK_ERROR_RET(net, AddLocalMapping(bstrAddress.raw(), lOffset), rc);
     429            }
     430        }
     431
     432        if (!vLoopback2Delete.empty())
     433        {
     434            /* we're expecting stings 127.0.0.1 */
     435            LOOPBACK2DELETEADDITERATOR it;
     436            for (it = vLoopback2Add.begin();
     437                 it != vLoopback2Add.end();
     438                 ++it)
     439            {
     440                Bstr bstrAddress;
     441                bstrAddress = Bstr(it->c_str());
     442
     443                CHECK_ERROR_RET(net, AddLocalMapping(bstrAddress.raw(), 0), rc);
     444            }
     445        }
     446
    351447       
    352448        if(enable >= 0)
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