| 44 | static bool l_Debug; |
| 45 | |
| 46 | static int parseArguments(int ac, WCHAR **av, po::variables_map& vm, printInfoStruct& printInfo) |
| 47 | { |
| 48 | WCHAR namePath[MAX_PATH]; |
| 49 | GetModuleFileName(NULL, namePath, MAX_PATH); |
| 50 | WCHAR *progName = PathFindFileName(namePath); |
| 51 | |
| 52 | po::options_description desc; |
| 53 | |
| 54 | desc.add_options() |
| 55 | ("help,h", "Print usage message and exit") |
| 56 | ("version,V", "Print version and exit") |
| 57 | ("debug,d", "Verbose/Debug output") |
| 58 | ("host,H", po::wvalue<std::wstring>()->required(), "Target hostname or IP. If an IPv6 address is given, the '-6' option must be set") |
| 59 | (",4", "--Host is an IPv4 address or if it's a hostname: Resolve it to an IPv4 address (default)") |
| 60 | (",6", "--Host is an IPv6 address or if it's a hostname: Resolve it to an IPv6 address") |
| 61 | ("timeout,t", po::value<int>(), "Specify timeout for requests in ms (default=1000)") |
| 62 | ("packets,p", po::value<int>(), "Declare ping count (default=5)") |
| 63 | ("warning,w", po::wvalue<std::wstring>(), "Warning values: rtt,package loss") |
| 64 | ("critical,c", po::wvalue<std::wstring>(), "Critical values: rtt,package loss") |
| 65 | ; |
| 66 | |
| 67 | po::wcommand_line_parser parser(ac, av); |
| 68 | |
| 69 | try { |
| 70 | po::store( |
| 71 | parser |
| 72 | .options(desc) |
| 73 | .style( |
| 74 | po::command_line_style::unix_style | |
| 75 | po::command_line_style::allow_long_disguise & |
| 76 | ~po::command_line_style::allow_guessing |
| 77 | ) |
| 78 | .run(), |
| 79 | vm); |
| 80 | vm.notify(); |
| 81 | } catch (const std::exception& e) { |
| 82 | std::cout << e.what() << '\n' << desc << '\n'; |
| 83 | return 3; |
| 84 | } |
| 85 | |
| 86 | if (vm.count("help")) { |
| 87 | std::wcout << progName << " Help\n\tVersion: " << VERSION << '\n'; |
| 88 | wprintf( |
| 89 | L"%s is a simple program to ping an ip4 address.\n" |
| 90 | L"You can use the following options to define its behaviour:\n\n", progName); |
| 91 | std::cout << desc; |
| 92 | wprintf( |
| 93 | L"\nIt will take at least timeout times number of pings to run\n" |
| 94 | L"Then it will output a string looking something like this:\n\n" |
| 95 | L"\tPING WARNING RTA: 72ms Packet loss: 20%% | ping=72ms;40;80;71;77 pl=20%%;20;50;0;100\n\n" |
| 96 | L"\"PING\" being the type of the check, \"WARNING\" the returned status\n" |
| 97 | L"and \"RTA: 72ms Packet loss: 20%%\" the relevant information.\n" |
| 98 | L"The performance data is found behind the \"|\", in order:\n" |
| 99 | L"returned value, warning threshold, critical threshold, minimal value and,\n" |
| 100 | L"if applicable, the maximal value. \n\n" |
| 101 | L"%s' exit codes denote the following:\n" |
| 102 | L" 0\tOK,\n\tNo Thresholds were broken or the programs check part was not executed\n" |
| 103 | L" 1\tWARNING,\n\tThe warning, but not the critical threshold was broken\n" |