Changeset 45559 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Apr 16, 2013 6:11:59 AM (12 years ago)
- Location:
- trunk/src/VBox/Frontends/VBoxManage
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VBoxManage/Makefile.kmk
r45156 r45559 56 56 VBoxManageStorageController.cpp \ 57 57 VBoxManageUSB.cpp \ 58 $(if $(VBOX_WITH_NAT_SERVICE),VBoxManageNATNetwork.cpp,) 58 $(if $(VBOX_WITH_NAT_SERVICE),VBoxManageNATNetwork.cpp,) \ 59 $(if $(VBOX_WITH_NAT_SERVICE),../../NetworkServices/NetLib/VBoxNetPortForwardString.cpp,) 59 60 VBoxManage_LIBS += $(LIB_DDU) 60 61 … … 82 83 $(if $(VBOX_WITH_NAT_SERVICE),VBOX_WITH_NAT_SERVICE) 83 84 85 # VBoxNetPortForwardString.h 86 VBoxManageNATNetwork.cpp_INCS += ../../NetworkServices/NetLib/ 87 84 88 ifneq ($(KBUILD_TARGET),win) 85 89 # Workaround for buggy gcc-4.3 compilers, see -
trunk/src/VBox/Frontends/VBoxManage/VBoxManageNATNetwork.cpp
r45356 r45559 20 20 *******************************************************************************/ 21 21 #ifndef VBOX_ONLY_DOCS 22 23 22 24 #include <VBox/com/com.h> 23 25 #include <VBox/com/array.h> … … 29 31 #endif /* !VBOX_ONLY_DOCS */ 30 32 33 #include <netinet/in.h> 34 35 #define IPv6 36 37 #include <iprt/cdefs.h> 31 38 #include <iprt/cidr.h> 32 39 #include <iprt/param.h> … … 40 47 #include <VBox/log.h> 41 48 49 #include <vector> 50 42 51 #include "VBoxManage.h" 52 #include "VBoxPortForwardString.h" 43 53 44 54 #ifndef VBOX_ONLY_DOCS 55 45 56 using namespace com; 46 57 … … 62 73 { "--enable", 'e', RTGETOPT_REQ_NOTHING }, 63 74 { "--disable", 'd', RTGETOPT_REQ_NOTHING }, 64 75 { "--port-forward-4", 'p', RTGETOPT_REQ_STRING }, 76 { "--port-forward-6", 'P', RTGETOPT_REQ_STRING }, 65 77 }; 78 79 typedef struct PFNAME2DELETE 80 { 81 char aszName[PF_NAMELEN]; 82 bool fIPv6; 83 } PFNAME2DELETE, *PPFNAME2DELETE; 84 85 typedef std::vector<PFNAME2DELETE> VPF2DELETE; 86 typedef VPF2DELETE::const_iterator VPF2DELETEITERATOR; 87 88 typedef std::vector<PORTFORWARDRULE> VPF2ADD; 89 typedef VPF2ADD::const_iterator VPF2ADDITERATOR; 90 66 91 67 92 static int handleOp(HandlerArg *a, OPCODE enmCode, int iStart, int *pcProcessed) … … 79 104 int ipv6 = -1; 80 105 106 VPF2DELETE vPfName2Delete; 107 VPF2ADD vPf2Add; 108 81 109 int c; 82 110 RTGETOPTUNION ValueUnion; 83 111 RTGETOPTSTATE GetState; 112 84 113 RTGetOptInit(&GetState, 85 114 a->argc, … … 101 130 } 102 131 break; 132 103 133 case 'n': // --network 104 134 if(pNetworkCidr) … … 109 139 } 110 140 break; 141 111 142 case 'e': // --enable 112 143 if(enable >= 0) … … 117 148 } 118 149 break; 150 119 151 case 'd': // --disable 120 152 if(enable >= 0) … … 125 157 } 126 158 break; 127 case VINF_GETOPT_NOT_OPTION: 128 return errorSyntax(USAGE_NATNETWORK, "unhandled parameter: %s", ValueUnion.psz); 129 break; 159 130 160 case 'h': 131 161 if (dhcp != -1) … … 133 163 dhcp = ValueUnion.f; 134 164 break; 165 135 166 case '6': 136 167 if (ipv6 != -1) … … 138 169 ipv6 = ValueUnion.f; 139 170 break; 171 172 case 'P': /* ipv6 portforwarding*/ 173 case 'p': /* ipv4 portforwarding */ 174 { 175 if (RTStrCmp(ValueUnion.psz, "delete") != 0) 176 { 177 PORTFORWARDRULE Pfr; 178 179 /* netPfStrToPf will clean up the Pfr */ 180 int irc = netPfStrToPf(ValueUnion.psz, (c == 'P'), &Pfr); 181 if (RT_FAILURE(irc)) 182 return errorSyntax(USAGE_NATNETWORK, 183 "Invalid port-forward rule %s\n", 184 ValueUnion.psz); 185 186 vPf2Add.push_back(Pfr); 187 } 188 else 189 { 190 int vrc; 191 RTGETOPTUNION NamePf2DeleteUnion; 192 PFNAME2DELETE Name2Delete; 193 194 if (enmCode != OP_MODIFY) 195 return errorSyntax(USAGE_NATNETWORK, 196 "Port-forward could be deleted on modify \n"); 197 198 vrc = RTGetOptFetchValue(&GetState, 199 &NamePf2DeleteUnion, 200 RTGETOPT_REQ_STRING); 201 if (RT_FAILURE(vrc)) 202 return errorSyntax(USAGE_NATNETWORK, 203 "Not enough parmaters\n"); 204 205 if (strlen(NamePf2DeleteUnion.psz) > PF_NAMELEN) 206 return errorSyntax(USAGE_NATNETWORK, 207 "Port-forward rule name is too long\n"); 208 209 RT_ZERO(Name2Delete); 210 RTStrCopy(Name2Delete.aszName, 211 PF_NAMELEN, 212 NamePf2DeleteUnion.psz); 213 Name2Delete.fIPv6 = (c == 'P'); 214 215 vPfName2Delete.push_back(Name2Delete); 216 } 217 break; 218 } 219 220 case VINF_GETOPT_NOT_OPTION: 221 return errorSyntax(USAGE_NATNETWORK, 222 "unhandled parameter: %s", 223 ValueUnion.psz); 224 break; 225 140 226 default: 141 227 if (c > 0) 142 228 { 143 229 if (RT_C_IS_GRAPH(c)) 144 return errorSyntax(USAGE_NATNETWORK, "unhandled option: -%c", c); 230 return errorSyntax(USAGE_NATNETWORK, 231 "unhandled option: -%c", c); 145 232 else 146 return errorSyntax(USAGE_NATNETWORK, "unhandled option: %i", c); 233 return errorSyntax(USAGE_NATNETWORK, 234 "unhandled option: %i", c); 147 235 } 148 236 else if (c == VERR_GETOPT_UNKNOWN_OPTION) 149 return errorSyntax(USAGE_NATNETWORK, "unknown option: %s", ValueUnion.psz); 237 return errorSyntax(USAGE_NATNETWORK, 238 "unknown option: %s", ValueUnion.psz); 150 239 else if (ValueUnion.pDef) 151 return errorSyntax(USAGE_NATNETWORK, "%s: %Rrs", ValueUnion.pDef->pszLong, c); 240 return errorSyntax(USAGE_NATNETWORK, 241 "%s: %Rrs", ValueUnion.pDef->pszLong, c); 152 242 else 153 243 return errorSyntax(USAGE_NATNETWORK, "%Rrs", c); … … 218 308 if(FAILED(rc)) 219 309 return errorArgument("Failed to set configuration"); 310 } 311 312 if (!vPfName2Delete.empty()) 313 { 314 VPF2DELETEITERATOR it; 315 for (it = vPfName2Delete.begin(); it != vPfName2Delete.end(); ++it) 316 { 317 CHECK_ERROR(net, RemovePortForwardRule((BOOL)(*it).fIPv6, 318 Bstr((*it).aszName).raw())); 319 if(FAILED(rc)) 320 return errorArgument("Failed to delete pf"); 321 322 } 323 } 324 325 if (!vPf2Add.empty()) 326 { 327 VPF2ADDITERATOR it; 328 for(it = vPf2Add.begin(); it != vPf2Add.end(); ++it) 329 { 330 NATProtocol_T proto = NATProtocol_TCP; 331 if ((*it).iPfrProto == IPPROTO_TCP) 332 proto = NATProtocol_TCP; 333 else if ((*it).iPfrProto == IPPROTO_UDP) 334 proto = NATProtocol_UDP; 335 else 336 continue; /* XXX: warning here. */ 337 338 CHECK_ERROR(net, AddPortForwardRule( 339 (BOOL)(*it).fPfrIPv6, 340 Bstr((*it).aszPfrName).raw(), 341 proto, 342 Bstr((*it).aszPfrHostAddr).raw(), 343 (*it).u16PfrHostPort, 344 Bstr((*it).aszPfrGuestAddr).raw(), 345 (*it).u16PfrGuestPort)); 346 if(FAILED(rc)) 347 return errorArgument("Failed to add pf"); 348 349 } 220 350 } 221 351
Note:
See TracChangeset
for help on using the changeset viewer.