}
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));
msg += hexString;
anna::Logger::debug(msg, ANNA_FILE_LOCATION);
);
-
anna::functions::fromHexString(hexString, db);
// Close file
infile.close();
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);
}
//-------------------------------------------------------------------
int main(int argc, char **argv) {
std::string exec = argv[0];
+ std::string execBN = exec.substr(exec.find_last_of("/") + 1);
+ std::string filetrace = execBN + ".trace";
std::cout << std::endl;
//check command line arguments
<< (ignoreFlags ? "non strict" : "strict") << std::endl;
// Logger and engines:
Logger::setLevel(Logger::Debug);
- Logger::initialize("pcapDecoder", new TraceWriter("file.trace", 2048000));
+ Logger::initialize(execBN.c_str(), new TraceWriter(filetrace.c_str(), 2048000));
anna::diameter::codec::Engine *codecEngine =
new anna::diameter::codec::Engine();
anna::diameter::stack::Engine &stackEngine =
// 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 {
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";
+ std::string msg = "Open '"; msg += filetrace; msg += "' 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
// Close output file:
out.close();
-
- std::string msg = "Open 'file.trace' in order to see process traces.\n";
+ std::string msg = "Open '"; msg += filetrace; msg += "' in order to see process traces.\n";
msg += "Open '"; msg += outputFile; msg += "' to see decoding results.";
_exit(msg, 0);
}