| 322 | } |
| 323 | |
| 324 | static int |
| 325 | test_add_interface(void) |
| 326 | { |
| 327 | char file_name[] = "/tmp/pcapng_test_XXXXXX.pcapng"; |
| 328 | static rte_pcapng_t *pcapng; |
| 329 | int ret, tmp_fd; |
| 330 | uint64_t now = current_timestamp(); |
| 331 | |
| 332 | tmp_fd = mkstemps(file_name, strlen(".pcapng")); |
| 333 | if (tmp_fd == -1) { |
| 334 | perror("mkstemps() failure"); |
| 335 | goto fail; |
| 336 | } |
| 337 | printf("pcapng: output file %s\n", file_name); |
| 338 | |
| 339 | /* open a test capture file */ |
| 340 | pcapng = rte_pcapng_fdopen(tmp_fd, NULL, NULL, "pcapng_addif", NULL); |
| 341 | if (pcapng == NULL) { |
| 342 | fprintf(stderr, "rte_pcapng_fdopen failed\n"); |
| 343 | close(tmp_fd); |
| 344 | goto fail; |
| 345 | } |
| 346 | |
| 347 | /* Add interface to the file */ |
| 348 | ret = rte_pcapng_add_interface(pcapng, port_id, |
| 349 | NULL, NULL, NULL); |
| 350 | if (ret < 0) { |
| 351 | fprintf(stderr, "can not add port %u\n", port_id); |
| 352 | goto fail; |
| 353 | } |
| 354 | |
| 355 | /* Add interface with ifname and ifdescr */ |
| 356 | ret = rte_pcapng_add_interface(pcapng, port_id, |
| 357 | "myeth", "Some long description", NULL); |
| 358 | if (ret < 0) { |
| 359 | fprintf(stderr, "can not add port %u with ifname\n", port_id); |
| 360 | goto fail; |
| 361 | } |
| 362 | |
| 363 | /* Add interface with filter */ |
| 364 | ret = rte_pcapng_add_interface(pcapng, port_id, |
| 365 | NULL, NULL, "tcp port 8080"); |
| 366 | if (ret < 0) { |
| 367 | fprintf(stderr, "can not add port %u with filter\n", port_id); |
| 368 | goto fail; |
| 369 | } |
| 370 | |
| 371 | rte_pcapng_close(pcapng); |
| 372 | |
| 373 | ret = valid_pcapng_file(file_name, now, 0); |
| 374 | /* if test fails want to investigate the file */ |
| 375 | if (ret == 0) |
| 376 | unlink(file_name); |
| 377 | |
| 378 | return ret; |
| 379 | |
| 380 | fail: |
| 381 | rte_pcapng_close(pcapng); |
nothing calls this directly
no test coverage detected