diff options
| -rw-r--r-- | plugins/check_ping.c | 236 |
1 files changed, 119 insertions, 117 deletions
diff --git a/plugins/check_ping.c b/plugins/check_ping.c index 526b8618..d79a4a61 100644 --- a/plugins/check_ping.c +++ b/plugins/check_ping.c | |||
| @@ -66,18 +66,12 @@ static int max_addr = 1; | |||
| 66 | static int max_packets = -1; | 66 | static int max_packets = -1; |
| 67 | static int verbose = 0; | 67 | static int verbose = 0; |
| 68 | 68 | ||
| 69 | static float rta = UNKNOWN_TRIP_TIME; | 69 | static float round_trip_average = UNKNOWN_TRIP_TIME; |
| 70 | static int pl = UNKNOWN_PACKET_LOSS; | 70 | static int packet_loss = UNKNOWN_PACKET_LOSS; |
| 71 | 71 | ||
| 72 | static char *warn_text; | 72 | static char *warn_text; |
| 73 | 73 | ||
| 74 | int main(int argc, char **argv) { | 74 | int main(int argc, char **argv) { |
| 75 | char *cmd = NULL; | ||
| 76 | char *rawcmd = NULL; | ||
| 77 | int result = STATE_UNKNOWN; | ||
| 78 | int this_result = STATE_UNKNOWN; | ||
| 79 | int i; | ||
| 80 | |||
| 81 | setlocale(LC_ALL, ""); | 75 | setlocale(LC_ALL, ""); |
| 82 | setlocale(LC_NUMERIC, "C"); | 76 | setlocale(LC_NUMERIC, "C"); |
| 83 | bindtextdomain(PACKAGE, LOCALEDIR); | 77 | bindtextdomain(PACKAGE, LOCALEDIR); |
| @@ -106,8 +100,9 @@ int main(int argc, char **argv) { | |||
| 106 | alarm(timeout_interval); | 100 | alarm(timeout_interval); |
| 107 | #endif | 101 | #endif |
| 108 | 102 | ||
| 109 | for (i = 0; i < n_addresses; i++) { | 103 | int result = STATE_UNKNOWN; |
| 110 | 104 | char *rawcmd = NULL; | |
| 105 | for (int i = 0; i < n_addresses; i++) { | ||
| 111 | #ifdef PING6_COMMAND | 106 | #ifdef PING6_COMMAND |
| 112 | if (address_family != AF_INET && is_inet6_addr(addresses[i])) { | 107 | if (address_family != AF_INET && is_inet6_addr(addresses[i])) { |
| 113 | rawcmd = strdup(PING6_COMMAND); | 108 | rawcmd = strdup(PING6_COMMAND); |
| @@ -118,6 +113,8 @@ int main(int argc, char **argv) { | |||
| 118 | rawcmd = strdup(PING_COMMAND); | 113 | rawcmd = strdup(PING_COMMAND); |
| 119 | #endif | 114 | #endif |
| 120 | 115 | ||
| 116 | char *cmd = NULL; | ||
| 117 | |||
| 121 | /* does the host address of number of packets argument come first? */ | 118 | /* does the host address of number of packets argument come first? */ |
| 122 | #ifdef PING_PACKETS_FIRST | 119 | #ifdef PING_PACKETS_FIRST |
| 123 | # ifdef PING_HAS_TIMEOUT | 120 | # ifdef PING_HAS_TIMEOUT |
| @@ -134,18 +131,18 @@ int main(int argc, char **argv) { | |||
| 134 | } | 131 | } |
| 135 | 132 | ||
| 136 | /* run the command */ | 133 | /* run the command */ |
| 137 | this_result = run_ping(cmd, addresses[i]); | 134 | int this_result = run_ping(cmd, addresses[i]); |
| 138 | 135 | ||
| 139 | if (pl == UNKNOWN_PACKET_LOSS || rta < 0.0) { | 136 | if (packet_loss == UNKNOWN_PACKET_LOSS || round_trip_average < 0.0) { |
| 140 | printf("%s\n", cmd); | 137 | printf("%s\n", cmd); |
| 141 | die(STATE_UNKNOWN, _("CRITICAL - Could not interpret output from ping command\n")); | 138 | die(STATE_UNKNOWN, _("CRITICAL - Could not interpret output from ping command\n")); |
| 142 | } | 139 | } |
| 143 | 140 | ||
| 144 | if (pl >= cpl || rta >= crta || rta < 0) { | 141 | if (packet_loss >= cpl || round_trip_average >= crta || round_trip_average < 0) { |
| 145 | this_result = STATE_CRITICAL; | 142 | this_result = STATE_CRITICAL; |
| 146 | } else if (pl >= wpl || rta >= wrta) { | 143 | } else if (packet_loss >= wpl || round_trip_average >= wrta) { |
| 147 | this_result = STATE_WARNING; | 144 | this_result = STATE_WARNING; |
| 148 | } else if (pl >= 0 && rta >= 0) { | 145 | } else if (packet_loss >= 0 && round_trip_average >= 0) { |
| 149 | this_result = max_state(STATE_OK, this_result); | 146 | this_result = max_state(STATE_OK, this_result); |
| 150 | } | 147 | } |
| 151 | 148 | ||
| @@ -153,26 +150,28 @@ int main(int argc, char **argv) { | |||
| 153 | die(STATE_OK, "%s is alive\n", addresses[i]); | 150 | die(STATE_OK, "%s is alive\n", addresses[i]); |
| 154 | } | 151 | } |
| 155 | 152 | ||
| 156 | if (display_html == true) { | 153 | if (display_html) { |
| 157 | printf("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, addresses[i]); | 154 | printf("<A HREF='%s/traceroute.cgi?%s'>", CGIURL, addresses[i]); |
| 158 | } | 155 | } |
| 159 | if (pl == 100) { | 156 | if (packet_loss == 100) { |
| 160 | printf(_("PING %s - %sPacket loss = %d%%"), state_text(this_result), warn_text, pl); | 157 | printf(_("PING %s - %sPacket loss = %d%%"), state_text(this_result), warn_text, packet_loss); |
| 161 | } else { | 158 | } else { |
| 162 | printf(_("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms"), state_text(this_result), warn_text, pl, rta); | 159 | printf(_("PING %s - %sPacket loss = %d%%, RTA = %2.2f ms"), state_text(this_result), warn_text, packet_loss, |
| 160 | round_trip_average); | ||
| 163 | } | 161 | } |
| 164 | if (display_html == true) { | 162 | if (display_html) { |
| 165 | printf("</A>"); | 163 | printf("</A>"); |
| 166 | } | 164 | } |
| 167 | 165 | ||
| 168 | /* Print performance data */ | 166 | /* Print performance data */ |
| 169 | if (pl != 100) { | 167 | if (packet_loss != 100) { |
| 170 | printf("|%s", | 168 | printf("|%s", |
| 171 | fperfdata("rta", (double)rta, "ms", wrta > 0 ? true : false, wrta, crta > 0 ? true : false, crta, true, 0, false, 0)); | 169 | fperfdata("rta", (double)round_trip_average, "ms", (bool)(wrta > 0), wrta, (bool)(crta > 0), crta, true, 0, false, 0)); |
| 172 | } else { | 170 | } else { |
| 173 | printf("| rta=U;%f;%f;;", wrta, crta); | 171 | printf("| rta=U;%f;%f;;", wrta, crta); |
| 174 | } | 172 | } |
| 175 | printf(" %s\n", perfdata("pl", (long)pl, "%", wpl > 0 ? true : false, wpl, cpl > 0 ? true : false, cpl, true, 0, false, 0)); | 173 | |
| 174 | printf(" %s\n", perfdata("pl", (long)packet_loss, "%", (bool)(wpl > 0), wpl, (bool)(cpl > 0), cpl, true, 0, false, 0)); | ||
| 176 | 175 | ||
| 177 | if (verbose >= 2) { | 176 | if (verbose >= 2) { |
| 178 | printf("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl); | 177 | printf("%f:%d%% %f:%d%%\n", wrta, wpl, crta, cpl); |
| @@ -188,10 +187,6 @@ int main(int argc, char **argv) { | |||
| 188 | 187 | ||
| 189 | /* process command-line arguments */ | 188 | /* process command-line arguments */ |
| 190 | int process_arguments(int argc, char **argv) { | 189 | int process_arguments(int argc, char **argv) { |
| 191 | int c = 1; | ||
| 192 | char *ptr; | ||
| 193 | |||
| 194 | int option = 0; | ||
| 195 | static struct option longopts[] = {STD_LONG_OPTS, | 190 | static struct option longopts[] = {STD_LONG_OPTS, |
| 196 | {"packets", required_argument, 0, 'p'}, | 191 | {"packets", required_argument, 0, 'p'}, |
| 197 | {"nohtml", no_argument, 0, 'n'}, | 192 | {"nohtml", no_argument, 0, 'n'}, |
| @@ -204,23 +199,24 @@ int process_arguments(int argc, char **argv) { | |||
| 204 | return ERROR; | 199 | return ERROR; |
| 205 | } | 200 | } |
| 206 | 201 | ||
| 207 | for (c = 1; c < argc; c++) { | 202 | for (int index = 1; index < argc; index++) { |
| 208 | if (strcmp("-to", argv[c]) == 0) { | 203 | if (strcmp("-to", argv[index]) == 0) { |
| 209 | strcpy(argv[c], "-t"); | 204 | strcpy(argv[index], "-t"); |
| 210 | } | 205 | } |
| 211 | if (strcmp("-nohtml", argv[c]) == 0) { | 206 | if (strcmp("-nohtml", argv[index]) == 0) { |
| 212 | strcpy(argv[c], "-n"); | 207 | strcpy(argv[index], "-n"); |
| 213 | } | 208 | } |
| 214 | } | 209 | } |
| 215 | 210 | ||
| 216 | while (1) { | 211 | int option = 0; |
| 217 | c = getopt_long(argc, argv, "VvhnL46t:c:w:H:p:", longopts, &option); | 212 | while (true) { |
| 213 | int option_index = getopt_long(argc, argv, "VvhnL46t:c:w:H:p:", longopts, &option); | ||
| 218 | 214 | ||
| 219 | if (c == -1 || c == EOF) { | 215 | if (option_index == -1 || option_index == EOF) { |
| 220 | break; | 216 | break; |
| 221 | } | 217 | } |
| 222 | 218 | ||
| 223 | switch (c) { | 219 | switch (option_index) { |
| 224 | case '?': /* usage */ | 220 | case '?': /* usage */ |
| 225 | usage5(); | 221 | usage5(); |
| 226 | case 'h': /* help */ | 222 | case 'h': /* help */ |
| @@ -247,9 +243,9 @@ int process_arguments(int argc, char **argv) { | |||
| 247 | usage(_("IPv6 support not available\n")); | 243 | usage(_("IPv6 support not available\n")); |
| 248 | #endif | 244 | #endif |
| 249 | break; | 245 | break; |
| 250 | case 'H': /* hostname */ | 246 | case 'H': /* hostname */ { |
| 251 | ptr = optarg; | 247 | char *ptr = optarg; |
| 252 | while (1) { | 248 | while (true) { |
| 253 | n_addresses++; | 249 | n_addresses++; |
| 254 | if (n_addresses > max_addr) { | 250 | if (n_addresses > max_addr) { |
| 255 | max_addr *= 2; | 251 | max_addr *= 2; |
| @@ -266,7 +262,7 @@ int process_arguments(int argc, char **argv) { | |||
| 266 | break; | 262 | break; |
| 267 | } | 263 | } |
| 268 | } | 264 | } |
| 269 | break; | 265 | } break; |
| 270 | case 'p': /* number of packets to send */ | 266 | case 'p': /* number of packets to send */ |
| 271 | if (is_intnonneg(optarg)) { | 267 | if (is_intnonneg(optarg)) { |
| 272 | max_packets = atoi(optarg); | 268 | max_packets = atoi(optarg); |
| @@ -289,76 +285,72 @@ int process_arguments(int argc, char **argv) { | |||
| 289 | } | 285 | } |
| 290 | } | 286 | } |
| 291 | 287 | ||
| 292 | c = optind; | 288 | int arg_counter = optind; |
| 293 | if (c == argc) { | 289 | if (arg_counter == argc) { |
| 294 | return validate_arguments(); | 290 | return validate_arguments(); |
| 295 | } | 291 | } |
| 296 | 292 | ||
| 297 | if (addresses[0] == NULL) { | 293 | if (addresses[0] == NULL) { |
| 298 | if (!is_host(argv[c])) { | 294 | if (!is_host(argv[arg_counter])) { |
| 299 | usage2(_("Invalid hostname/address"), argv[c]); | 295 | usage2(_("Invalid hostname/address"), argv[arg_counter]); |
| 300 | } else { | 296 | } else { |
| 301 | addresses[0] = argv[c++]; | 297 | addresses[0] = argv[arg_counter++]; |
| 302 | n_addresses++; | 298 | n_addresses++; |
| 303 | if (c == argc) { | 299 | if (arg_counter == argc) { |
| 304 | return validate_arguments(); | 300 | return validate_arguments(); |
| 305 | } | 301 | } |
| 306 | } | 302 | } |
| 307 | } | 303 | } |
| 308 | 304 | ||
| 309 | if (wpl == UNKNOWN_PACKET_LOSS) { | 305 | if (wpl == UNKNOWN_PACKET_LOSS) { |
| 310 | if (!is_intpercent(argv[c])) { | 306 | if (!is_intpercent(argv[arg_counter])) { |
| 311 | printf(_("<wpl> (%s) must be an integer percentage\n"), argv[c]); | 307 | printf(_("<wpl> (%s) must be an integer percentage\n"), argv[arg_counter]); |
| 312 | return ERROR; | 308 | return ERROR; |
| 313 | } else { | 309 | } |
| 314 | wpl = atoi(argv[c++]); | 310 | wpl = atoi(argv[arg_counter++]); |
| 315 | if (c == argc) { | 311 | if (arg_counter == argc) { |
| 316 | return validate_arguments(); | 312 | return validate_arguments(); |
| 317 | } | ||
| 318 | } | 313 | } |
| 319 | } | 314 | } |
| 320 | 315 | ||
| 321 | if (cpl == UNKNOWN_PACKET_LOSS) { | 316 | if (cpl == UNKNOWN_PACKET_LOSS) { |
| 322 | if (!is_intpercent(argv[c])) { | 317 | if (!is_intpercent(argv[arg_counter])) { |
| 323 | printf(_("<cpl> (%s) must be an integer percentage\n"), argv[c]); | 318 | printf(_("<cpl> (%s) must be an integer percentage\n"), argv[arg_counter]); |
| 324 | return ERROR; | 319 | return ERROR; |
| 325 | } else { | 320 | } |
| 326 | cpl = atoi(argv[c++]); | 321 | cpl = atoi(argv[arg_counter++]); |
| 327 | if (c == argc) { | 322 | if (arg_counter == argc) { |
| 328 | return validate_arguments(); | 323 | return validate_arguments(); |
| 329 | } | ||
| 330 | } | 324 | } |
| 331 | } | 325 | } |
| 332 | 326 | ||
| 333 | if (wrta < 0.0) { | 327 | if (wrta < 0.0) { |
| 334 | if (is_negative(argv[c])) { | 328 | if (is_negative(argv[arg_counter])) { |
| 335 | printf(_("<wrta> (%s) must be a non-negative number\n"), argv[c]); | 329 | printf(_("<wrta> (%s) must be a non-negative number\n"), argv[arg_counter]); |
| 336 | return ERROR; | 330 | return ERROR; |
| 337 | } else { | 331 | } |
| 338 | wrta = atof(argv[c++]); | 332 | wrta = atof(argv[arg_counter++]); |
| 339 | if (c == argc) { | 333 | if (arg_counter == argc) { |
| 340 | return validate_arguments(); | 334 | return validate_arguments(); |
| 341 | } | ||
| 342 | } | 335 | } |
| 343 | } | 336 | } |
| 344 | 337 | ||
| 345 | if (crta < 0.0) { | 338 | if (crta < 0.0) { |
| 346 | if (is_negative(argv[c])) { | 339 | if (is_negative(argv[arg_counter])) { |
| 347 | printf(_("<crta> (%s) must be a non-negative number\n"), argv[c]); | 340 | printf(_("<crta> (%s) must be a non-negative number\n"), argv[arg_counter]); |
| 348 | return ERROR; | 341 | return ERROR; |
| 349 | } else { | 342 | } |
| 350 | crta = atof(argv[c++]); | 343 | crta = atof(argv[arg_counter++]); |
| 351 | if (c == argc) { | 344 | if (arg_counter == argc) { |
| 352 | return validate_arguments(); | 345 | return validate_arguments(); |
| 353 | } | ||
| 354 | } | 346 | } |
| 355 | } | 347 | } |
| 356 | 348 | ||
| 357 | if (max_packets == -1) { | 349 | if (max_packets == -1) { |
| 358 | if (is_intnonneg(argv[c])) { | 350 | if (is_intnonneg(argv[arg_counter])) { |
| 359 | max_packets = atoi(argv[c++]); | 351 | max_packets = atoi(argv[arg_counter++]); |
| 360 | } else { | 352 | } else { |
| 361 | printf(_("<max_packets> (%s) must be a non-negative number\n"), argv[c]); | 353 | printf(_("<max_packets> (%s) must be a non-negative number\n"), argv[arg_counter]); |
| 362 | return ERROR; | 354 | return ERROR; |
| 363 | } | 355 | } |
| 364 | } | 356 | } |
| @@ -369,9 +361,13 @@ int process_arguments(int argc, char **argv) { | |||
| 369 | int get_threshold(char *arg, float *trta, int *tpl) { | 361 | int get_threshold(char *arg, float *trta, int *tpl) { |
| 370 | if (is_intnonneg(arg) && sscanf(arg, "%f", trta) == 1) { | 362 | if (is_intnonneg(arg) && sscanf(arg, "%f", trta) == 1) { |
| 371 | return OK; | 363 | return OK; |
| 372 | } else if (strpbrk(arg, ",:") && strstr(arg, "%") && sscanf(arg, "%f%*[:,]%d%%", trta, tpl) == 2) { | 364 | } |
| 365 | |||
| 366 | if (strpbrk(arg, ",:") && strstr(arg, "%") && sscanf(arg, "%f%*[:,]%d%%", trta, tpl) == 2) { | ||
| 373 | return OK; | 367 | return OK; |
| 374 | } else if (strstr(arg, "%") && sscanf(arg, "%d%%", tpl) == 1) { | 368 | } |
| 369 | |||
| 370 | if (strstr(arg, "%") && sscanf(arg, "%d%%", tpl) == 1) { | ||
| 375 | return OK; | 371 | return OK; |
| 376 | } | 372 | } |
| 377 | 373 | ||
| @@ -380,25 +376,32 @@ int get_threshold(char *arg, float *trta, int *tpl) { | |||
| 380 | } | 376 | } |
| 381 | 377 | ||
| 382 | int validate_arguments() { | 378 | int validate_arguments() { |
| 383 | float max_seconds; | ||
| 384 | int i; | ||
| 385 | |||
| 386 | if (wrta < 0.0) { | 379 | if (wrta < 0.0) { |
| 387 | printf(_("<wrta> was not set\n")); | 380 | printf(_("<wrta> was not set\n")); |
| 388 | return ERROR; | 381 | return ERROR; |
| 389 | } else if (crta < 0.0) { | 382 | } |
| 383 | |||
| 384 | if (crta < 0.0) { | ||
| 390 | printf(_("<crta> was not set\n")); | 385 | printf(_("<crta> was not set\n")); |
| 391 | return ERROR; | 386 | return ERROR; |
| 392 | } else if (wpl == UNKNOWN_PACKET_LOSS) { | 387 | } |
| 388 | |||
| 389 | if (wpl == UNKNOWN_PACKET_LOSS) { | ||
| 393 | printf(_("<wpl> was not set\n")); | 390 | printf(_("<wpl> was not set\n")); |
| 394 | return ERROR; | 391 | return ERROR; |
| 395 | } else if (cpl == UNKNOWN_PACKET_LOSS) { | 392 | } |
| 393 | |||
| 394 | if (cpl == UNKNOWN_PACKET_LOSS) { | ||
| 396 | printf(_("<cpl> was not set\n")); | 395 | printf(_("<cpl> was not set\n")); |
| 397 | return ERROR; | 396 | return ERROR; |
| 398 | } else if (wrta > crta) { | 397 | } |
| 398 | |||
| 399 | if (wrta > crta) { | ||
| 399 | printf(_("<wrta> (%f) cannot be larger than <crta> (%f)\n"), wrta, crta); | 400 | printf(_("<wrta> (%f) cannot be larger than <crta> (%f)\n"), wrta, crta); |
| 400 | return ERROR; | 401 | return ERROR; |
| 401 | } else if (wpl > cpl) { | 402 | } |
| 403 | |||
| 404 | if (wpl > cpl) { | ||
| 402 | printf(_("<wpl> (%d) cannot be larger than <cpl> (%d)\n"), wpl, cpl); | 405 | printf(_("<wpl> (%d) cannot be larger than <cpl> (%d)\n"), wpl, cpl); |
| 403 | return ERROR; | 406 | return ERROR; |
| 404 | } | 407 | } |
| @@ -407,12 +410,12 @@ int validate_arguments() { | |||
| 407 | max_packets = DEFAULT_MAX_PACKETS; | 410 | max_packets = DEFAULT_MAX_PACKETS; |
| 408 | } | 411 | } |
| 409 | 412 | ||
| 410 | max_seconds = crta / 1000.0 * max_packets + max_packets; | 413 | float max_seconds = (crta / 1000.0 * max_packets) + max_packets; |
| 411 | if (max_seconds > timeout_interval) { | 414 | if (max_seconds > timeout_interval) { |
| 412 | timeout_interval = (int)max_seconds; | 415 | timeout_interval = (unsigned int)max_seconds; |
| 413 | } | 416 | } |
| 414 | 417 | ||
| 415 | for (i = 0; i < n_addresses; i++) { | 418 | for (int i = 0; i < n_addresses; i++) { |
| 416 | if (!is_host(addresses[i])) { | 419 | if (!is_host(addresses[i])) { |
| 417 | usage2(_("Invalid hostname/address"), addresses[i]); | 420 | usage2(_("Invalid hostname/address"), addresses[i]); |
| 418 | } | 421 | } |
| @@ -426,10 +429,6 @@ int validate_arguments() { | |||
| 426 | } | 429 | } |
| 427 | 430 | ||
| 428 | int run_ping(const char *cmd, const char *addr) { | 431 | int run_ping(const char *cmd, const char *addr) { |
| 429 | char buf[MAX_INPUT_BUFFER]; | ||
| 430 | int result = STATE_UNKNOWN; | ||
| 431 | int match; | ||
| 432 | |||
| 433 | if ((child_process = spopen(cmd)) == NULL) { | 432 | if ((child_process = spopen(cmd)) == NULL) { |
| 434 | die(STATE_UNKNOWN, _("Could not open pipe: %s\n"), cmd); | 433 | die(STATE_UNKNOWN, _("Could not open pipe: %s\n"), cmd); |
| 435 | } | 434 | } |
| @@ -439,8 +438,9 @@ int run_ping(const char *cmd, const char *addr) { | |||
| 439 | printf(_("Cannot open stderr for %s\n"), cmd); | 438 | printf(_("Cannot open stderr for %s\n"), cmd); |
| 440 | } | 439 | } |
| 441 | 440 | ||
| 441 | char buf[MAX_INPUT_BUFFER]; | ||
| 442 | int result = STATE_UNKNOWN; | ||
| 442 | while (fgets(buf, MAX_INPUT_BUFFER - 1, child_process)) { | 443 | while (fgets(buf, MAX_INPUT_BUFFER - 1, child_process)) { |
| 443 | |||
| 444 | if (verbose >= 3) { | 444 | if (verbose >= 3) { |
| 445 | printf("Output: %s", buf); | 445 | printf("Output: %s", buf); |
| 446 | } | 446 | } |
| @@ -448,37 +448,39 @@ int run_ping(const char *cmd, const char *addr) { | |||
| 448 | result = max_state(result, error_scan(buf, addr)); | 448 | result = max_state(result, error_scan(buf, addr)); |
| 449 | 449 | ||
| 450 | /* get the percent loss statistics */ | 450 | /* get the percent loss statistics */ |
| 451 | match = 0; | 451 | int match = 0; |
| 452 | if ((sscanf(buf, "%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss%n", &pl, &match) && match) || | 452 | if ((sscanf(buf, "%*d packets transmitted, %*d packets received, +%*d errors, %d%% packet loss%n", &packet_loss, &match) && |
| 453 | (sscanf(buf, "%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss%n", &pl, &match) && match) || | 453 | match) || |
| 454 | (sscanf(buf, "%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss%n", &pl, &match) && match) || | 454 | (sscanf(buf, "%*d packets transmitted, %*d packets received, +%*d duplicates, %d%% packet loss%n", &packet_loss, &match) && |
| 455 | (sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% packet loss%n", &pl, &match) && match) || | 455 | match) || |
| 456 | (sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% loss, time%n", &pl, &match) && match) || | 456 | (sscanf(buf, "%*d packets transmitted, %*d received, +%*d duplicates, %d%% packet loss%n", &packet_loss, &match) && match) || |
| 457 | (sscanf(buf, "%*d packets transmitted, %*d received, %d%% loss, time%n", &pl, &match) && match) || | 457 | (sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% packet loss%n", &packet_loss, &match) && match) || |
| 458 | (sscanf(buf, "%*d packets transmitted, %*d received, %d%% packet loss, time%n", &pl, &match) && match) || | 458 | (sscanf(buf, "%*d packets transmitted, %*d packets received, %d%% loss, time%n", &packet_loss, &match) && match) || |
| 459 | (sscanf(buf, "%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss%n", &pl, &match) && match) || | 459 | (sscanf(buf, "%*d packets transmitted, %*d received, %d%% loss, time%n", &packet_loss, &match) && match) || |
| 460 | (sscanf(buf, "%*d packets transmitted %*d received, +%*d errors, %d%% packet loss%n", &pl, &match) && match) || | 460 | (sscanf(buf, "%*d packets transmitted, %*d received, %d%% packet loss, time%n", &packet_loss, &match) && match) || |
| 461 | (sscanf(buf, "%*[^(](%d%% %*[^)])%n", &pl, &match) && match)) { | 461 | (sscanf(buf, "%*d packets transmitted, %*d received, +%*d errors, %d%% packet loss%n", &packet_loss, &match) && match) || |
| 462 | (sscanf(buf, "%*d packets transmitted %*d received, +%*d errors, %d%% packet loss%n", &packet_loss, &match) && match) || | ||
| 463 | (sscanf(buf, "%*[^(](%d%% %*[^)])%n", &packet_loss, &match) && match)) { | ||
| 462 | continue; | 464 | continue; |
| 463 | } | 465 | } |
| 464 | 466 | ||
| 465 | /* get the round trip average */ | 467 | /* get the round trip average */ |
| 466 | else if ((sscanf(buf, "round-trip min/avg/max = %*f/%f/%*f%n", &rta, &match) && match) || | 468 | if ((sscanf(buf, "round-trip min/avg/max = %*f/%f/%*f%n", &round_trip_average, &match) && match) || |
| 467 | (sscanf(buf, "round-trip min/avg/max/mdev = %*f/%f/%*f/%*f%n", &rta, &match) && match) || | 469 | (sscanf(buf, "round-trip min/avg/max/mdev = %*f/%f/%*f/%*f%n", &round_trip_average, &match) && match) || |
| 468 | (sscanf(buf, "round-trip min/avg/max/sdev = %*f/%f/%*f/%*f%n", &rta, &match) && match) || | 470 | (sscanf(buf, "round-trip min/avg/max/sdev = %*f/%f/%*f/%*f%n", &round_trip_average, &match) && match) || |
| 469 | (sscanf(buf, "round-trip min/avg/max/stddev = %*f/%f/%*f/%*f%n", &rta, &match) && match) || | 471 | (sscanf(buf, "round-trip min/avg/max/stddev = %*f/%f/%*f/%*f%n", &round_trip_average, &match) && match) || |
| 470 | (sscanf(buf, "round-trip min/avg/max/std-dev = %*f/%f/%*f/%*f%n", &rta, &match) && match) || | 472 | (sscanf(buf, "round-trip min/avg/max/std-dev = %*f/%f/%*f/%*f%n", &round_trip_average, &match) && match) || |
| 471 | (sscanf(buf, "round-trip (ms) min/avg/max = %*f/%f/%*f%n", &rta, &match) && match) || | 473 | (sscanf(buf, "round-trip (ms) min/avg/max = %*f/%f/%*f%n", &round_trip_average, &match) && match) || |
| 472 | (sscanf(buf, "round-trip (ms) min/avg/max/stddev = %*f/%f/%*f/%*f%n", &rta, &match) && match) || | 474 | (sscanf(buf, "round-trip (ms) min/avg/max/stddev = %*f/%f/%*f/%*f%n", &round_trip_average, &match) && match) || |
| 473 | (sscanf(buf, "rtt min/avg/max/mdev = %*f/%f/%*f/%*f ms%n", &rta, &match) && match) || | 475 | (sscanf(buf, "rtt min/avg/max/mdev = %*f/%f/%*f/%*f ms%n", &round_trip_average, &match) && match) || |
| 474 | (sscanf(buf, "%*[^=] = %*fms, %*[^=] = %*fms, %*[^=] = %fms%n", &rta, &match) && match)) { | 476 | (sscanf(buf, "%*[^=] = %*fms, %*[^=] = %*fms, %*[^=] = %fms%n", &round_trip_average, &match) && match)) { |
| 475 | continue; | 477 | continue; |
| 476 | } | 478 | } |
| 477 | } | 479 | } |
| 478 | 480 | ||
| 479 | /* this is needed because there is no rta if all packets are lost */ | 481 | /* this is needed because there is no rta if all packets are lost */ |
| 480 | if (pl == 100) { | 482 | if (packet_loss == 100) { |
| 481 | rta = crta; | 483 | round_trip_average = crta; |
| 482 | } | 484 | } |
| 483 | 485 | ||
| 484 | /* check stderr, setting at least WARNING if there is output here */ | 486 | /* check stderr, setting at least WARNING if there is output here */ |
