| 717 | } |
| 718 | |
| 719 | static dumpcap_out_t create_output(void) |
| 720 | { |
| 721 | dumpcap_out_t ret; |
| 722 | static char tmp_path[PATH_MAX]; |
| 723 | int fd; |
| 724 | |
| 725 | /* If no filename specified make a tempfile name */ |
| 726 | if (output_name == NULL) { |
| 727 | struct interface *intf; |
| 728 | struct tm *tm; |
| 729 | time_t now; |
| 730 | char ts[32]; |
| 731 | |
| 732 | intf = TAILQ_FIRST(&interfaces); |
| 733 | now = time(NULL); |
| 734 | tm = localtime(&now); |
| 735 | if (!tm) |
| 736 | rte_panic("localtime failed\n"); |
| 737 | |
| 738 | strftime(ts, sizeof(ts), "%Y%m%d%H%M%S", tm); |
| 739 | |
| 740 | snprintf(tmp_path, sizeof(tmp_path), |
| 741 | "%s/%s_%u_%s_%s.%s", tmp_dir, |
| 742 | progname, intf->port, intf->name, ts, |
| 743 | use_pcapng ? "pcapng" : "pcap"); |
| 744 | output_name = tmp_path; |
| 745 | } |
| 746 | |
| 747 | if (strcmp(output_name, "-") == 0) |
| 748 | fd = STDOUT_FILENO; |
| 749 | else { |
| 750 | mode_t mode = group_read ? 0640 : 0600; |
| 751 | |
| 752 | fprintf(stderr, "File: %s\n", output_name); |
| 753 | fd = open(output_name, O_WRONLY | O_CREAT, mode); |
| 754 | if (fd < 0) |
| 755 | rte_exit(EXIT_FAILURE, "Can not open \"%s\": %s\n", |
| 756 | output_name, strerror(errno)); |
| 757 | } |
| 758 | |
| 759 | if (use_pcapng) { |
| 760 | struct interface *intf; |
| 761 | char *os = get_os_info(); |
| 762 | |
| 763 | ret.pcapng = rte_pcapng_fdopen(fd, os, NULL, |
| 764 | version(), capture_comment); |
| 765 | if (ret.pcapng == NULL) |
| 766 | rte_exit(EXIT_FAILURE, "pcapng_fdopen failed: %s\n", |
| 767 | strerror(rte_errno)); |
| 768 | free(os); |
| 769 | |
| 770 | TAILQ_FOREACH(intf, &interfaces, next) { |
| 771 | rte_pcapng_add_interface(ret.pcapng, intf->port, |
| 772 | intf->ifname, intf->ifdescr, |
| 773 | intf->opts.filter); |
| 774 | } |
| 775 | } else { |
| 776 | pcap_t *pcap; |
no test coverage detected