#include "libndiff.h" #include "parser.h" #include "ndiff_config.h" #include "ndiff.h" #include using namespace std; void usage(){ cerr << "Usage: ndiff [OPTIONS] FILES" << endl << endl; cerr << "Processing:" << endl; // cerr << " -t: Attempt to track a host when it changes IP's but not the services it hosts." << endl << endl; cerr << " -h: Display hostnames beside IP's - when available." << endl << endl; cerr << "Output:" << endl; cerr << " -X : Output difference in a XML format, use '-' to output to stdout." << endl; cerr << " -N : Output difference in a text format, use '-' to output to stdout." << endl; cerr << " '-N -' is assumed if nothing is specified." << endl; cerr << endl; cerr << "Examples:"; cerr << " ndiff.pl -X - firstweek.xml secondweek.xml" << endl; exit(2); } int main(int argc, char **argv){ string xmlName="", normName=""; fstream xFile, nFile; vector intputs; bool dispHost=false; libndiff n; int c; opterr = 0; while ((c = getopt (argc, argv, "X:N:ht")) != -1){ switch (c) { case 'X': xmlName = optarg; break; case 'N': normName = optarg; break; case 'h': dispHost=true; break; case '?': usage(); default: usage(); } } n.showNames(dispHost); //there has to be SOME form of output if(xmlName=="" && normName==""){ normName="-"; } if(xmlName!="-" && !xmlName.empty()){ xFile.open(xmlName.c_str(), fstream::out | fstream::app); } if(normName!="-" && !normName.empty()){ nFile.open(normName.c_str(), fstream::out | fstream::app); } for (int index = optind; index < argc; index++){ intputs.push_back(argv[index]); } while(intputs.size()>1){ n.setPath(intputs[0], intputs[1]); if(!xmlName.empty()){ if(xmlName=="-"){ cout << n.getXML(); }else{ xFile << n.getXML(); } } if(!normName.empty()){ if(normName=="-"){ cout << n.getSimple(); }else{ nFile << n.getSimple(); } } intputs.erase(intputs.begin()); n.purge(); } if(xmlName!="-" && !xmlName.empty()){ xFile.close(); } if(normName!="-" && !normName.empty()){ nFile.close(); } return 0; }