* Open the resulting pcapng file with libpcap * Would be better to use capinfos from wireshark * but that creates an unwanted dependency. */
| 288 | * but that creates an unwanted dependency. |
| 289 | */ |
| 290 | static int |
| 291 | valid_pcapng_file(const char *file_name, uint64_t started, unsigned int expected) |
| 292 | { |
| 293 | char errbuf[PCAP_ERRBUF_SIZE]; |
| 294 | struct pkt_print_ctx ctx = { }; |
| 295 | int ret; |
| 296 | |
| 297 | ctx.start_ns = started; |
| 298 | ctx.end_ns = current_timestamp(); |
| 299 | |
| 300 | ctx.pcap = pcap_open_offline_with_tstamp_precision(file_name, |
| 301 | PCAP_TSTAMP_PRECISION_NANO, |
| 302 | errbuf); |
| 303 | if (ctx.pcap == NULL) { |
| 304 | fprintf(stderr, "pcap_open_offline('%s') failed: %s\n", |
| 305 | file_name, errbuf); |
| 306 | return -1; |
| 307 | } |
| 308 | |
| 309 | ret = pcap_loop(ctx.pcap, 0, parse_pcap_packet, (u_char *)&ctx); |
| 310 | if (ret != 0) { |
| 311 | fprintf(stderr, "pcap_dispatch: failed: %s\n", |
| 312 | pcap_geterr(ctx.pcap)); |
| 313 | } else if (ctx.count != expected) { |
| 314 | printf("Only %u packets, expected %u\n", |
| 315 | ctx.count, expected); |
| 316 | ret = -1; |
| 317 | } |
| 318 | |
| 319 | pcap_close(ctx.pcap); |
| 320 | |
| 321 | return ret; |
| 322 | } |
| 323 | |
| 324 | static int |
| 325 | test_add_interface(void) |
no test coverage detected