X-Git-Url: https://git.teslayout.com/public/public/public/?a=blobdiff_plain;f=example%2Fdiameter%2FpcapDecoder%2Fmain.cpp;h=6214825cc3f8f5b59632d9235b60eb12d2567518;hb=4456556fc4cd3d24eab8d555acceae339d476c5b;hp=65681d8086b6939ef6809e056fc4295222213f3d;hpb=5b5f15c4ceaa303e2f1d577899b3afa5aff86bb8;p=anna.git diff --git a/example/diameter/pcapDecoder/main.cpp b/example/diameter/pcapDecoder/main.cpp index 65681d8..6214825 100644 --- a/example/diameter/pcapDecoder/main.cpp +++ b/example/diameter/pcapDecoder/main.cpp @@ -290,10 +290,10 @@ void my_callback(u_char *useless, const struct pcap_pkthdr* pkthdr, } bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) throw() { - // Get hex string static char buffer[8192]; std::ifstream infile(pathfile.c_str(), std::ifstream::in); + if(infile.is_open()) { infile >> buffer; std::string hexString(buffer, strlen(buffer)); @@ -304,7 +304,6 @@ bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) t msg += hexString; anna::Logger::debug(msg, ANNA_FILE_LOCATION); ); - anna::functions::fromHexString(hexString, db); // Close file infile.close(); @@ -316,10 +315,11 @@ bool getDataBlockFromHexFile(const std::string &pathfile, anna::DataBlock &db) t void _exit(const std::string &message, int resultCode = 1) { - if (resultCode) + if(resultCode) std::cerr << message << std::endl << std::endl; else std::cout << message << std::endl << std::endl; + exit(resultCode); } @@ -397,11 +397,11 @@ int main(int argc, char **argv) { // Tracing: //if (cl.exists("trace")) // anna::Logger::setLevel(anna::Logger::asLevel(cl.getValue("trace"))); - // Check hex content input file (look extension): anna::DataBlock db_aux(true); + if(isHex) { - if (!getDataBlockFromHexFile(inputFile, db_aux)) + if(!getDataBlockFromHexFile(inputFile, db_aux)) _exit("Error reading hex file provided"); try { @@ -414,17 +414,14 @@ int main(int argc, char **argv) { outputFile += ".as.xml"; std::ofstream out(outputFile, std::ifstream::out); out << G_codecMsg.asXMLString(); - // Close output file: out.close(); - std::string msg = "Open 'file.trace' in order to see process traces.\n"; msg += "Open '"; msg += outputFile; msg += "' to see decoding results."; _exit(msg, 0); } // Normal input: pcap file: - // SNIFFING //////////////////////////////////////////////////////////////////////////////////////////////7 //temporary packet buffers struct pcap_pkthdr header; // The header that pcap gives us @@ -484,7 +481,6 @@ int main(int argc, char **argv) { // Close output file: out.close(); - std::string msg = "Open 'file.trace' in order to see process traces.\n"; msg += "Open '"; msg += outputFile; msg += "' to see decoding results."; _exit(msg, 0);