diff --git a/doc/text2pcap.pod b/doc/text2pcap.pod index 7c41a0cfa8..7533744b20 100644 --- a/doc/text2pcap.pod +++ b/doc/text2pcap.pod @@ -19,6 +19,7 @@ S<[ B<-h> ]> S<[ B<-i> EprotoE ]> S<[ B<-l> EtypenumE ]> S<[ B<-n> ]> +S<[ B<-N> Eintf-nameE ]> S<[ B<-m> Emax-packetE ]> S<[ B<-o> hex|oct|dec ]> S<[ B<-q> ]> @@ -172,6 +173,11 @@ TCP packets. Write the file in pcapng format rather than pcap format. +=item -N Eintf-nameE + +Specify a name for the interface included when writing a pcapng format +file. By default no name is defined. + =item -o hex|oct|dec Specify the radix for the offsets (hex, octal or decimal). Defaults to diff --git a/test/suite_text2pcap.py b/test/suite_text2pcap.py index f07d0a3ec7..79bd1397fe 100644 --- a/test/suite_text2pcap.py +++ b/test/suite_text2pcap.py @@ -540,3 +540,20 @@ class case_text2pcap_i_proto(subprocesstest.SubprocessTestCase): "0010 00 00 00 00 00 00 00 00 00 00 00 03 01 00 03 03\n" + "0020 00 00 00 08\n", ("-i", "132", "-6", "::1,::1"))) + + +@fixtures.mark_usefixtures('base_env') +@fixtures.uses_fixtures +class case_text2pcap_other_options(subprocesstest.SubprocessTestCase): + '''Test other command line options''' + def test_text2pcap_option_N(self, cmd_text2pcap, cmd_tshark, capture_file): + '''Test -N option''' + testin_file = self.filename_from_id(testin_txt) + testout_file = self.filename_from_id(testout_pcapng) + + with open(testin_file, 'w') as f: + f.write("0000 00\n") + f.close() + self.assertRun((cmd_text2pcap, "-n", "-N", "your-interface-name", testin_file, testout_file)) + proc = self.assertRun((cmd_tshark, "-r", testout_file, "-Tfields", "-eframe.interface_name", "-c1")) + self.assertEqual(proc.stdout_str.rstrip(), "your-interface-name") diff --git a/text2pcap.c b/text2pcap.c index 6ffa7cf3e5..309f4704c6 100644 --- a/text2pcap.c +++ b/text2pcap.c @@ -137,6 +137,9 @@ /* File format */ static gboolean use_pcapng = FALSE; +/* Interface name */ +static char *interface_name = NULL; + /* Debug level */ static int debug = 0; /* Be quiet */ @@ -886,7 +889,7 @@ write_file_header (void) if (success) { success = pcapng_write_interface_description_block(output_file, NULL, - NULL, + interface_name, NULL, "", NULL, @@ -1389,6 +1392,7 @@ print_usage (FILE *output) " Example: -l 7 for ARCNet packets.\n" " -m max packet length in output; default is %d\n" " -n use pcapng instead of pcap as output format.\n" + " -N assign name to the interface in the pcapng file.\n" "\n" "Prepend dummy header:\n" " -e prepend dummy Ethernet II header with specified L3PID\n" @@ -1450,7 +1454,7 @@ parse_options (int argc, char *argv[]) ws_init_version_info("Text2pcap (Wireshark)", NULL, NULL, NULL); /* Scan CLI parameters */ - while ((c = getopt_long(argc, argv, "aDdhqe:i:l:m:no:u:s:S:t:T:v4:6:", long_options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "aDdhqe:i:l:m:nN:o:u:s:S:t:T:v4:6:", long_options, NULL)) != -1) { switch (c) { case 'h': show_help_header("Generate a capture file from an ASCII hexdump of packets."); @@ -1463,6 +1467,7 @@ parse_options (int argc, char *argv[]) case 'l': pcap_link_type = (guint32)strtol(optarg, NULL, 0); break; case 'm': max_offset = (guint32)strtol(optarg, NULL, 0); break; case 'n': use_pcapng = TRUE; break; + case 'N': interface_name = optarg; break; case 'o': if (optarg[0] != 'h' && optarg[0] != 'o' && optarg[0] != 'd') { fprintf(stderr, "Bad argument for '-o': %s\n", optarg);