int main(int argc, char **argv) { Options options(argc, argv, "sA: dA:"); int option; if (argc < 2) { usage(argv[0]); return 1; } while ((option = options.getOption()) != -1) { if (!options) { print_error(argv[0], options.error()); return 1; } switch (option) { case SOURCE_ADDRESS: sourceAddressRange = cidrToRange(options.getArgument()); break; case DESTINATION_ADDRESS: destinationAddressRange = cidrToRange(options.getArgument()); break; } } if (options.getIndex() == argc) { usage(argv[0]); return 1; } FlatFileReader<FlowStats> reader; FlowStats flowStats; for (int fileNumber = options.getIndex(); fileNumber < argc; ++fileNumber) { if (access(argv[fileNumber], R_OK) != 0) { print_error(argv[0], argv[fileNumber], strerror(errno)); if (fileNumber < (argc - 1)) { cout << endl; } } else { if (reader.open(argv[fileNumber]) != E_SUCCESS) { cerr << "Error opening file: " << argv[fileNumber] << endl; return 1; } while (reader.read(flowStats) == E_SUCCESS) { printFlow(flowStats); } if (reader.close() != E_SUCCESS) { cerr << "Error closing reader!" << endl; return 1; } } } return 0; }
int main(int argc, char *argv[]) { Options options(argc, argv, "cA: sA:"); int option; vector <string> files; bool error = false; if (argc < 2) { usage(argv[0]); return 1; } while ((option = options.getOption()) != -1) { if (!options) { cerr << argv[0] << ": " << options.error() << endl; return 1; } switch (option) { case CLIENT_ADDRESS: clientAddressRanges.push_back(cidrToRange(options.getArgument())); break; case SERVER_ADDRESS: serverAddressRanges.push_back(cidrToRange(options.getArgument())); break; } } if (options.getIndex() == argc) { usage(argv[0]); return 1; } for (int file = options.getIndex(); file < argc; ++file) { if (access(argv[file], R_OK) != 0) { cerr << argv[0] << ": " << argv[file] << ": " << strerror(errno) << endl; error = true; } else { files.push_back(argv[file]); } } if (files.empty()) { return 1; } if (error) { cout << endl; } FlatFileReader<HTTPResponse> reader; HTTPResponse http; ErrorStatus errorStatus; for (vector<string>::iterator file(files.begin()); file != files.end(); ++file) { if (reader.open(*file) != E_SUCCESS) { cerr << "Unable to open '" << *file << "'" << endl; return 1; } while ((errorStatus = reader.read(http)) == E_SUCCESS) { printHTTPResponseRecord(http); } if (errorStatus != E_EOF) { cerr << "Error reading from '" << *file << "'" << endl; return 1; } if (reader.close() != E_SUCCESS) { cerr << "Error closing '" << *file << "'" << endl; return 1; } } return 0; }
void * PayloadSearchManager<WriterType>::hbfQueryThread(void *caller) { PayloadSearchManager<WriterType> *_this (reinterpret_cast<PayloadSearchManager<WriterType> *>(caller)); // initialize read enumerator StrftimeReadEnumerator readEnum(_this->_inputDir, "%Y/%m/%d/hbf_%H", _this->_startTime, _this->_endTime); if (!readEnum) { _this->_error = true; _this->_errorMsg.assign("StrftimeReadEnumerator: "); _this->_errorMsg.append(readEnum.error()); // lock results lock if (pthread_mutex_lock(&(_this->_resultsLock)) != 0) { // error _this->_error = true; _this->_errorMsg.assign("Unable to lock _resultsLock"); return NULL; } _this->_hbfRunning = false; // signal condition for correlator thread if (pthread_cond_signal(&(_this->_resultsCondition)) != 0) { _this->_error = true; _this->_errorMsg.assign("Unable to signal _resultsCondition"); return NULL; } // unlock results lock if (pthread_mutex_unlock(&(_this->_resultsLock)) != 0) { // error _this->_error = true; _this->_errorMsg.assign("Unable to unlock _resultsLock"); return NULL; } return NULL; } HBFQueryProcessor <FlatFileReader <ZlibCompressedHBF>, SetWriter <HBFResult> > processor; FlatFileReader <ZlibCompressedHBF> reader; std::set <HBFResult> *curResults; // for each file for (StrftimeReadEnumerator::const_iterator it(readEnum.begin()); it != readEnum.end(); ++it) { // initialize FlatFileReader if (reader.open(*it) != E_SUCCESS) { _this->_error = true; _this->_errorMsg.assign("FlatFileReader error"); // lock results lock if (pthread_mutex_lock(&(_this->_resultsLock)) != 0) { // error _this->_error = true; _this->_errorMsg.assign("Unable to lock _resultsLock"); return NULL; } _this->_hbfRunning = false; // signal condition for correlator thread if (pthread_cond_signal(&(_this->_resultsCondition)) != 0) { _this->_error = true; _this->_errorMsg.assign("Unable to signal _resultsCondition"); return NULL; } // unlock results lock if (pthread_mutex_unlock(&(_this->_resultsLock)) != 0) { // error _this->_error = true; _this->_errorMsg.assign("Unable to unlock _resultsLock"); return NULL; } return NULL; } // initialize SetWriter curResults = new std::set <HBFResult>; SetWriter <HBFResult> writer(*curResults); // initialize HBFQuery <FlatFileReader, SetWriter> processor.init(&reader, &writer, _this->_queryString, _this->_queryLength, _this->_matchLength, _this->_flowMatcher, _this->_maxMTU, _this->_maxFlows, _this->_hbfThreadCount); // hbfQuery.run() if (processor.run() != 0) { _this->_error = true; _this->_errorMsg.assign("HBFQueryProcessor: "); _this->_errorMsg.append(processor.error()); // lock results lock if (pthread_mutex_lock(&(_this->_resultsLock)) != 0) { // error _this->_error = true; _this->_errorMsg.assign("Unable to lock _resultsLock"); return NULL; } _this->_hbfRunning = false; // signal condition for correlator thread if (pthread_cond_signal(&(_this->_resultsCondition)) != 0) { _this->_error = true; _this->_errorMsg.assign("Unable to signal _resultsCondition"); return NULL; } // unlock results lock if (pthread_mutex_unlock(&(_this->_resultsLock)) != 0) { // error _this->_error = true; _this->_errorMsg.assign("Unable to unlock _resultsLock"); return NULL; } return NULL; } // lock results lock if (pthread_mutex_lock(&(_this->_resultsLock)) != 0) { // error _this->_error = true; _this->_errorMsg.assign("Unable to lock _resultsLock"); return NULL; } // push_back set into _results _this->_results.push(curResults); // signal condition for correlator thread if (pthread_cond_signal(&(_this->_resultsCondition)) != 0) { _this->_error = true; _this->_errorMsg.assign("Unable to signal _resultsCondition"); return NULL; } // unlock results lock if (pthread_mutex_unlock(&(_this->_resultsLock)) != 0) { // error _this->_error = true; _this->_errorMsg.assign("Unable to unlock _resultsLock"); return NULL; } reader.close(); } // lock results lock if (pthread_mutex_lock(&(_this->_resultsLock)) != 0) { // error _this->_error = true; _this->_errorMsg.assign("Unable to lock _resultsLock"); return NULL; } _this->_hbfRunning = false; // signal condition for correlator thread if (pthread_cond_signal(&(_this->_resultsCondition)) != 0) { _this->_error = true; _this->_errorMsg.assign("Unable to signal _resultsCondition"); return NULL; } // unlock results lock if (pthread_mutex_unlock(&(_this->_resultsLock)) != 0) { // error _this->_error = true; _this->_errorMsg.assign("Unable to unlock _resultsLock"); return NULL; } return NULL; }