| 383 | } |
| 384 | |
| 385 | static int |
| 386 | test_write_packets(void) |
| 387 | { |
| 388 | char file_name[] = "/tmp/pcapng_test_XXXXXX.pcapng"; |
| 389 | static rte_pcapng_t *pcapng; |
| 390 | int ret, tmp_fd, count; |
| 391 | uint64_t now = current_timestamp(); |
| 392 | |
| 393 | tmp_fd = mkstemps(file_name, strlen(".pcapng")); |
| 394 | if (tmp_fd == -1) { |
| 395 | perror("mkstemps() failure"); |
| 396 | goto fail; |
| 397 | } |
| 398 | printf("pcapng: output file %s\n", file_name); |
| 399 | |
| 400 | /* open a test capture file */ |
| 401 | pcapng = rte_pcapng_fdopen(tmp_fd, NULL, NULL, "pcapng_test", NULL); |
| 402 | if (pcapng == NULL) { |
| 403 | fprintf(stderr, "rte_pcapng_fdopen failed\n"); |
| 404 | close(tmp_fd); |
| 405 | goto fail; |
| 406 | } |
| 407 | |
| 408 | /* Add interface to the file */ |
| 409 | ret = rte_pcapng_add_interface(pcapng, port_id, |
| 410 | NULL, NULL, NULL); |
| 411 | if (ret < 0) { |
| 412 | fprintf(stderr, "can not add port %u\n", port_id); |
| 413 | goto fail; |
| 414 | } |
| 415 | |
| 416 | count = fill_pcapng_file(pcapng, TOTAL_PACKETS); |
| 417 | if (count < 0) |
| 418 | goto fail; |
| 419 | |
| 420 | /* write a statistics block */ |
| 421 | ret = rte_pcapng_write_stats(pcapng, port_id, |
| 422 | count, 0, "end of test"); |
| 423 | if (ret <= 0) { |
| 424 | fprintf(stderr, "Write of statistics failed\n"); |
| 425 | goto fail; |
| 426 | } |
| 427 | |
| 428 | rte_pcapng_close(pcapng); |
| 429 | |
| 430 | ret = valid_pcapng_file(file_name, now, count); |
| 431 | /* if test fails want to investigate the file */ |
| 432 | if (ret == 0) |
| 433 | unlink(file_name); |
| 434 | |
| 435 | return ret; |
| 436 | |
| 437 | fail: |
| 438 | rte_pcapng_close(pcapng); |
| 439 | return -1; |
| 440 | } |
| 441 | |
| 442 | static void |
nothing calls this directly
no test coverage detected