1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include "ostprotolib.h"
#include "pcapfileformat.h"
#include "protocol.pb.h"
#include "protocolmanager.h"
#include "settings.h"
#include <QCoreApplication>
#include <QFile>
#include <QSettings>
#include <QString>
extern ProtocolManager *OstProtocolManager;
QSettings *appSettings;
#if defined(Q_OS_WIN32)
QString kGzipPathDefaultValue;
QString kDiffPathDefaultValue;
QString kAwkPathDefaultValue;
#endif
/*
* Dummy Stuff for successful linking
*/
const char *version = "";
const char *revision = "";
quint64 getDeviceMacAddress(
int /*portId*/,
int /*streamId*/,
int /*frameIndex*/)
{
return 0;
}
quint64 getNeighborMacAddress(
int /*portId*/,
int /*streamId*/,
int /*frameIndex*/)
{
return 0;
}
int usage(int /*argc*/, char* argv[])
{
printf("usage:\n");
printf("%s <command>\n", argv[0]);
printf("command -\n");
printf(" importpcap\n");
return 255;
}
/* End of dummy stuff */
int testImportPcap(int argc, char* argv[])
{
bool isOk;
QString error;
if (argc != 3)
{
printf("usage:\n");
printf("%s importpcap <pcapfile>\n", argv[0]);
return 255;
}
OstProto::StreamConfigList streams;
QString inFile(argv[2]);
isOk = pcapFileFormat.open(inFile, streams, error);
if (!error.isEmpty())
{
printf("%s: %s\n",
qPrintable(inFile), qPrintable(error));
}
if (!isOk)
return 1;
return 0;
}
int main(int argc, char* argv[])
{
QCoreApplication app(argc, argv);
int exitCode = 0;
// app init starts ...
#if defined(Q_OS_WIN32)
kGzipPathDefaultValue = app.applicationDirPath() + "/gzip.exe";
kDiffPathDefaultValue = app.applicationDirPath() + "/diff.exe";
kAwkPathDefaultValue = app.applicationDirPath() + "/gawk.exe";
#endif
app.setApplicationName("Ostinato");
app.setOrganizationName("Ostinato");
OstProtocolManager = new ProtocolManager();
/* (Portable Mode) If we have a .ini file in the same directory as the
executable, we use that instead of the platform specific location
and format for the settings */
QString portableIni = QCoreApplication::applicationDirPath()
+ "/ostinato.ini";
if (QFile::exists(portableIni))
appSettings = new QSettings(portableIni, QSettings::IniFormat);
else
appSettings = new QSettings();
OstProtoLib::setExternalApplicationPaths(
appSettings->value(kTsharkPathKey, kTsharkPathDefaultValue).toString(),
appSettings->value(kGzipPathKey, kGzipPathDefaultValue).toString(),
appSettings->value(kDiffPathKey, kDiffPathDefaultValue).toString(),
appSettings->value(kAwkPathKey, kAwkPathDefaultValue).toString());
// ... app init finished
//
// identify and run specified test
//
if (argc < 2)
exitCode = usage(argc, argv);
else if (strcmp(argv[1],"importpcap") == 0)
exitCode = testImportPcap(argc, argv);
else
exitCode = usage(argc, argv);
delete appSettings;
return exitCode;
}
|