| 79 | } |
| 80 | |
| 81 | int |
| 82 | graph_pcap_file_open(const char *filename) |
| 83 | { |
| 84 | int fd, ret; |
| 85 | uint16_t portid; |
| 86 | char file_name[RTE_GRAPH_PCAP_FILE_SZ]; |
| 87 | char *pcap_dir; |
| 88 | |
| 89 | if (pcapng_fd) |
| 90 | goto done; |
| 91 | |
| 92 | if (!filename || filename[0] == '\0') { |
| 93 | if (graph_pcap_default_path_get(&pcap_dir) < 0) |
| 94 | return -1; |
| 95 | snprintf(file_name, RTE_GRAPH_PCAP_FILE_SZ, "%s", pcap_dir); |
| 96 | free(pcap_dir); |
| 97 | } else { |
| 98 | snprintf(file_name, RTE_GRAPH_PCAP_FILE_SZ, "%s_XXXXXX.pcapng", |
| 99 | filename); |
| 100 | } |
| 101 | |
| 102 | fd = mkstemps(file_name, strlen(".pcapng")); |
| 103 | if (fd < 0) { |
| 104 | graph_err("mkstemps() failure"); |
| 105 | return -1; |
| 106 | } |
| 107 | |
| 108 | graph_info("pcap filename: %s", file_name); |
| 109 | |
| 110 | /* Open a capture file */ |
| 111 | pcapng_fd = rte_pcapng_fdopen(fd, NULL, NULL, "Graph pcap tracer", |
| 112 | NULL); |
| 113 | if (pcapng_fd == NULL) { |
| 114 | graph_err("Graph rte_pcapng_fdopen failed."); |
| 115 | goto error; |
| 116 | } |
| 117 | |
| 118 | /* Add the configured interfaces as possible capture ports */ |
| 119 | RTE_ETH_FOREACH_DEV(portid) { |
| 120 | ret = rte_pcapng_add_interface(pcapng_fd, portid, |
| 121 | NULL, NULL, NULL); |
| 122 | if (ret < 0) { |
| 123 | graph_err("Graph rte_pcapng_add_interface port %u failed: %d", |
| 124 | portid, ret); |
| 125 | goto error; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | done: |
| 130 | return 0; |
| 131 | error: |
| 132 | if (pcapng_fd != NULL) { |
| 133 | rte_pcapng_close(pcapng_fd); |
| 134 | pcapng_fd = NULL; |
| 135 | } |
| 136 | close(fd); |
| 137 | return -1; |
| 138 | } |
no test coverage detected