1 | /** |
---|
2 | * @file CapturedData.cpp |
---|
3 | * @author Tomas Urban |
---|
4 | * @version 0.3 |
---|
5 | * @date 23/07/2009 |
---|
6 | */ |
---|
7 | #include "TcpipServer.h" |
---|
8 | #include "Logger/Logger.h" |
---|
9 | #include <iostream> |
---|
10 | |
---|
11 | using namespace std; |
---|
12 | |
---|
13 | int main(int argc, char **argv) |
---|
14 | { |
---|
15 | if (argc == 2 && strcmp(argv[1], "-help") == 0) |
---|
16 | { |
---|
17 | cout << "Usage: TrafficCapture.exe [-p port_number][-Linfo][-Lerr][-Lwarn][-Lcapt]\n"; |
---|
18 | cout << " [-Ldebug][-Lall][-Lnone]\n"; |
---|
19 | cout << "-p port_number Specifies the port for TCP/IP communication. 5501 is used\n"; |
---|
20 | cout << " by default\n"; |
---|
21 | cout << "-L* Sets the log level. Log levels can be combined together.\n"; |
---|
22 | cout << " The following log levels are available:\n"; |
---|
23 | cout << " -Linfo Displays information messages\n"; |
---|
24 | cout << " -Lerr Displays errors\n"; |
---|
25 | cout << " -Lwarn Displays warnings\n"; |
---|
26 | cout << " -Ldebug Displays debugging information\n"; |
---|
27 | cout << " -Lcapt Displays capturing information\n"; |
---|
28 | cout << " -Lall Displays all information\n"; |
---|
29 | cout << " -Lnone No messages are displayed\n"; |
---|
30 | return 0; |
---|
31 | } |
---|
32 | int nLogMode = 0; |
---|
33 | bool bLogModeSet = false; |
---|
34 | bool bError = false; |
---|
35 | Logger::Instance().SetLoggingMode(Logger::LOG_ERRORS); |
---|
36 | int nPort = TcpipServer::DEFAULT_PORT; |
---|
37 | for (int i = 1; i < argc; ++i) |
---|
38 | { |
---|
39 | bool bLog = false; |
---|
40 | char * pszArg = argv[i]; |
---|
41 | if (strcmp(pszArg, "-p") == 0) |
---|
42 | { |
---|
43 | if (bError = i + 1 == argc) |
---|
44 | Logger::Instance().LogError("Port value missing"); |
---|
45 | else |
---|
46 | { |
---|
47 | pszArg = argv[++i]; |
---|
48 | nPort = atoi(pszArg); |
---|
49 | } |
---|
50 | } |
---|
51 | else if (bLog = strcmp(pszArg, "-Linfo") == 0) |
---|
52 | nLogMode |= Logger::LOG_INFO; |
---|
53 | else if (bLog = strcmp(pszArg, "-Lerr") == 0) |
---|
54 | nLogMode |= Logger::LOG_ERRORS; |
---|
55 | else if (bLog = strcmp(pszArg, "-Lwarn") == 0) |
---|
56 | nLogMode |= Logger::LOG_WARNINGS; |
---|
57 | else if (bLog = strcmp(pszArg, "-Lcapt") == 0) |
---|
58 | nLogMode |= Logger::LOG_CAPTURE; |
---|
59 | else if (bLog = strcmp(pszArg, "-Ldebug") == 0) |
---|
60 | nLogMode |= Logger::LOG_DEBUG | Logger::LOG_INFO; |
---|
61 | else if (bLog = strcmp(pszArg, "-Lall") == 0) |
---|
62 | nLogMode = Logger::LOG_ALL; |
---|
63 | else if (bLog = strcmp(pszArg, "-Lnone") == 0) |
---|
64 | nLogMode = Logger::LOG_NOTHING; |
---|
65 | else |
---|
66 | { |
---|
67 | bError = true; |
---|
68 | std::string s = "Unknown command line parameter \""; |
---|
69 | s += pszArg; |
---|
70 | s += "\""; |
---|
71 | Logger::Instance().LogError(s); |
---|
72 | } |
---|
73 | if (bLog) |
---|
74 | bLogModeSet = true; |
---|
75 | } |
---|
76 | |
---|
77 | if (bError) |
---|
78 | return 1; |
---|
79 | if (!bLogModeSet) |
---|
80 | nLogMode = Logger::LOG_INFO | Logger::LOG_ERRORS; |
---|
81 | Logger::Instance().SetLoggingMode(nLogMode); |
---|
82 | Logger::Instance().LogDebug("Command line parameters processed successfully"); |
---|
83 | |
---|
84 | #ifdef WIN32 |
---|
85 | // Initialize Winsock. |
---|
86 | WSADATA wsaData; |
---|
87 | int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); |
---|
88 | if (iResult != NO_ERROR) |
---|
89 | { |
---|
90 | Logger::Instance().LogError("Error at WSAStartup()\n"); |
---|
91 | return 2; |
---|
92 | } |
---|
93 | #endif |
---|
94 | TcpipServer::Instance().Run(nPort); |
---|
95 | #ifdef WIN32 |
---|
96 | WSACleanup(); |
---|
97 | #endif |
---|
98 | return 0; |
---|
99 | } |
---|
100 | |
---|