MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_add_interface

Function test_add_interface

dpdk/app/test/test_pcapng.c:324–383  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322}
323
324static int
325test_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
380fail:
381 rte_pcapng_close(pcapng);

Callers

nothing calls this directly

Calls 7

current_timestampFunction · 0.85
rte_pcapng_fdopenFunction · 0.85
rte_pcapng_add_interfaceFunction · 0.85
rte_pcapng_closeFunction · 0.85
valid_pcapng_fileFunction · 0.85
printfFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected