text2pcap: allow to set interface name

When generating a capture file from a text file it can be helpfull
to be able to set the capture interface name in the generated IDB.
This can be especially true if later on the generated captures are
merged and the individual IDB's have to be compared. Without a name
every IDB of the same datalink type will be equal and subject to
merge. Also it keeps the individual streams identifiable for the
end user.

Change-Id: I70224379d88f516a0a356bf0b46aebafb69665f0
Signed-off-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Reviewed-on: https://code.wireshark.org/review/31015
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
This commit is contained in:
Jaap Keuter 2018-12-11 23:45:36 +01:00 committed by Peter Wu
parent a87e56aa79
commit 5bf37f63a8
3 changed files with 30 additions and 2 deletions

View File

@ -19,6 +19,7 @@ S<[ B<-h> ]>
S<[ B<-i> E<lt>protoE<gt> ]>
S<[ B<-l> E<lt>typenumE<gt> ]>
S<[ B<-n> ]>
S<[ B<-N> E<lt>intf-nameE<gt> ]>
S<[ B<-m> E<lt>max-packetE<gt> ]>
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 E<lt>intf-nameE<gt>
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

View File

@ -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 <intf-name> 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")

View File

@ -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> max packet length in output; default is %d\n"
" -n use pcapng instead of pcap as output format.\n"
" -N <intf-name> assign name to the interface in the pcapng file.\n"
"\n"
"Prepend dummy header:\n"
" -e <l3pid> 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);