Changeset 50240 in vbox
- Timestamp:
- Jan 27, 2014 5:10:27 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp
r50239 r50240 127 127 128 128 static int fetchNatPortForwardRules(const ComNatPtr&, bool, VECNATSERVICEPF&); 129 130 static int vboxNetNATLogInit(int argc, char **argv); 129 131 130 132 … … 989 991 extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp) 990 992 { 993 int rc; 994 991 995 LogFlowFuncEnter(); 992 996 … … 1098 1102 } 1099 1103 1104 rc = vboxNetNATLogInit(argc, argv); 1105 // shall we bail if we failed to init logging? 1106 1100 1107 g_pLwipNat = new VBoxNetLwipNAT(icmpsock4, icmpsock6); 1101 1108 1102 1109 Log2(("NAT: initialization\n")); 1103 intrc = g_pLwipNat->parseArgs(argc - 1, argv + 1);1110 rc = g_pLwipNat->parseArgs(argc - 1, argv + 1); 1104 1111 rc = (rc == 0) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /* XXX: FIXME */ 1105 1112 … … 1116 1123 delete g_pLwipNat; 1117 1124 return 0; 1125 } 1126 1127 1128 static int vboxNetNATLogInit(int argc, char **argv) 1129 { 1130 size_t cch; 1131 int rc; 1132 1133 char szHome[RTPATH_MAX]; 1134 rc = com::GetVBoxUserHomeDirectory(szHome, sizeof(szHome), false); 1135 if (RT_FAILURE(rc)) 1136 return rc; 1137 1138 const char *pcszNetwork = NULL; 1139 1140 // XXX: This duplicates information from VBoxNetBaseService.cpp. 1141 // Perhaps option definitions should be exported as public static 1142 // member of VBoxNetBaseService? 1143 static const RTGETOPTDEF s_aOptions[] = { 1144 { "--network", 'n', RTGETOPT_REQ_STRING } 1145 }; 1146 1147 RTGETOPTSTATE GetState; 1148 RTGetOptInit(&GetState, argc, argv, s_aOptions, RT_ELEMENTS(s_aOptions), 1, 1149 RTGETOPTINIT_FLAGS_NO_STD_OPTS); 1150 1151 RTGETOPTUNION ValueUnion; 1152 int ch; 1153 while ((ch = RTGetOpt(&GetState, &ValueUnion))) 1154 { 1155 if (ch == 'n') 1156 { 1157 pcszNetwork = ValueUnion.psz; 1158 break; 1159 } 1160 } 1161 1162 if (pcszNetwork == NULL) 1163 { 1164 return VERR_MISSING; 1165 } 1166 1167 char szNetwork[RTPATH_MAX]; 1168 rc = RTStrCopy(szNetwork, sizeof(szNetwork), pcszNetwork); 1169 if (RT_FAILURE(rc)) 1170 { 1171 return rc; 1172 } 1173 1174 // sanitize network name to be usable as a path component 1175 for (char *p = szNetwork; *p != '\0'; ++p) 1176 { 1177 if (RTPATH_IS_SEP(*p)) 1178 { 1179 *p = '_'; 1180 } 1181 } 1182 1183 char szLogFile[RTPATH_MAX]; 1184 cch = RTStrPrintf(szLogFile, sizeof(szLogFile), 1185 "%s%c%s.log", szHome, RTPATH_DELIMITER, szNetwork); 1186 if (cch >= sizeof(szLogFile)) 1187 { 1188 return VERR_BUFFER_OVERFLOW; 1189 } 1190 1191 // sanitize network name some more to be usable as environment variable 1192 for (char *p = szNetwork; *p != '\0'; ++p) 1193 { 1194 if (*p != '_' 1195 && (*p < '0' || '9' < *p) 1196 && (*p < 'a' || 'z' < *p) 1197 && (*p < 'A' || 'Z' < *p)) 1198 { 1199 *p = '_'; 1200 } 1201 } 1202 1203 char szEnvVarBase[128]; 1204 cch = RTStrPrintf(szEnvVarBase, sizeof(szEnvVarBase), 1205 "VBOXNET_%s_RELEASE_LOG", szNetwork); 1206 if (cch >= sizeof(szEnvVarBase)) 1207 { 1208 return VERR_BUFFER_OVERFLOW; 1209 } 1210 1211 char szError[RTPATH_MAX + 128]; 1212 rc = com::VBoxLogRelCreate("NetNAT", 1213 szLogFile, 1214 RTLOGFLAGS_PREFIX_TIME_PROG, 1215 "all all.restrict -default.restrict", 1216 szEnvVarBase, 1217 RTLOGDEST_FILE, 1218 32768 /* cMaxEntriesPerGroup */, 1219 0 /* cHistory */, 1220 0 /* uHistoryFileTime */, 1221 0 /* uHistoryFileSize */, 1222 szError, sizeof(szError)); 1223 return rc; 1118 1224 } 1119 1225
Note:
See TracChangeset
for help on using the changeset viewer.