1MERGECAP(1) MERGECAP(1)
2
3
4
6 mergecap - Merges two or more capture files into one
7
9 mergecap [ -a ] [ -F <file format> ] [ -h ] [ -I <IDB merge mode> ]
10 [ -s <snaplen> ] [ -v ] [ -V ] -w <outfile>|- <infile> [<infile> ...]
11
13 Mergecap is a program that combines multiple saved capture files into a
14 single output file specified by the -w argument. Mergecap knows how to
15 read pcap and pcapng capture files, including those of tcpdump,
16 Wireshark and other tools that write captures in those formats.
17
18 By default, Mergecap writes the capture file in pcapng format, and
19 writes all of the packets from the input capture files to the output
20 file.
21
22 Mergecap is able to detect, read and write the same capture files that
23 are supported by Wireshark. The input files don’t need a specific
24 filename extension; the file format and an optional gzip, zstd or lz4
25 compression will be automatically detected. Near the beginning of the
26 DESCRIPTION section of wireshark(1) or
27 https://www.wireshark.org/docs/man-pages/wireshark.html is a detailed
28 description of the way Wireshark handles this, which is the same way
29 Mergecap handles this.
30
31 Mergecap can write the file in several output formats. The -F flag can
32 be used to specify the format in which to write the capture file,
33 mergecap -F provides a list of the available output formats.
34
35 Packets from the input files are merged in chronological order based on
36 each frame’s timestamp, unless the -a flag is specified. Mergecap
37 assumes that frames within a single capture file are already stored in
38 chronological order. When the -a flag is specified, packets are copied
39 directly from each input file to the output file, independent of each
40 frame’s timestamp.
41
42 The output file frame encapsulation type is set to the type of the
43 input files if all input files have the same type. If not all of the
44 input files have the same frame encapsulation type, the output file
45 type is set to WTAP_ENCAP_PER_PACKET. Note that some capture file
46 formats, most notably pcap, do not currently support
47 WTAP_ENCAP_PER_PACKET. This combination will cause the output file
48 creation to fail.
49
51 -a
52
53 Causes the frame timestamps to be ignored, writing all packets from
54 the first input file followed by all packets from the second input
55 file. By default, when -a is not specified, the contents of the
56 input files are merged in chronological order based on each frame’s
57 timestamp.
58
59 Note: when merging, mergecap assumes that packets within a capture
60 file are already in chronological order.
61
62 -F <file format>
63
64 Sets the file format of the output capture file. Mergecap can write
65 the file in several formats; mergecap -F provides a list of the
66 available output formats. By default this is the pcapng format.
67
68 -h
69
70 Prints the version and options and exits.
71
72 -I <IDB merge mode>
73
74 Sets the Interface Description Block (IDB) merge mode to use during
75 merging. mergecap -I provides a list of the available IDB merge
76 modes.
77
78 Every input file has one or more IDBs, which describe the
79 interface(s) the capture was performed on originally. This includes
80 encapsulation type, interface name, etc. When mergecap merges
81 multiple input files, it has to merge these IDBs somehow for the
82 new merged output file. This flag controls how that is
83 accomplished. The currently available modes are:
84
85 none: No merging of IDBs is performed, and instead all IDBs are
86 copied to the merged output file.
87
88 all: IDBs are merged only if all input files have the same number
89 of IDBs, and each IDB matches their respective entry in the other
90 files. This is the default mode.
91
92 any: Any and all duplicate IDBs are merged into one IDB, regardless
93 of what file they are in.
94
95 Note that an IDB is only considered a matching duplicate if it has
96 the same encapsulation type, name, speed, time precision, comments,
97 description, etc.
98
99 -s <snaplen>
100
101 Sets the snapshot length to use when writing the data. If the -s
102 flag is used to specify a snapshot length, frames in the input file
103 with more captured data than the specified snapshot length will
104 have only the amount of data specified by the snapshot length
105 written to the output file. This may be useful if the program that
106 is to read the output file cannot handle packets larger than a
107 certain size (for example, the versions of snoop in Solaris 2.5.1
108 and Solaris 2.6 appear to reject Ethernet frames larger than the
109 standard Ethernet MTU, making them incapable of handling gigabit
110 Ethernet captures if jumbo frames were used).
111
112 -v
113
114 Causes mergecap to print a number of messages while it’s working.
115
116 -V
117
118 Print the version and exit.
119
120 -w <outfile>|-
121
122 Sets the output filename. If the name is '-', stdout will be used.
123 This setting is mandatory.
124
126 To merge two capture files together into a third capture file, in which
127 the last packet of one file arrives 100 seconds before the first packet
128 of another file, use the following sequence of commands.
129
130 First, use:
131
132 capinfos -aeS a.pcap b.pcap
133
134 to determine the start and end times of the two capture files, as
135 seconds since January 1, 1970, 00:00:00 UTC.
136
137 If a.pcap starts at 1009932757 and b.pcap ends at 873660281, then the
138 time adjustment to b.pcap that would make it end 100 seconds before
139 a.pcap begins would be 1009932757 - 873660281 - 100 = 136272376
140 seconds.
141
142 Thus, the next step would be to use:
143
144 editcap -t 136272376 b.pcap b-shifted.pcap
145
146 to generate a version of b.pcap with its time stamps shifted 136272376
147 ahead.
148
149 Then the final step would be to use :
150
151 mergecap -w compare.pcap a.pcap b-shifted.pcap
152
153 to merge a.pcap and the shifted b.pcap into compare.pcap.
154
156 pcap(3), wireshark(1), tshark(1), dumpcap(1), editcap(1), text2pcap(1),
157 pcap-filter(7) or tcpdump(8)
158
160 Mergecap is based heavily upon editcap by Richard Sharpe
161 <sharpe[AT]ns.aus.com> and Guy Harris <guy[AT]alum.mit.edu>.
162
163 This is the manual page for Mergecap 3.6.2. Mergecap is part of the
164 Wireshark distribution. The latest version of Wireshark can be found at
165 https://www.wireshark.org.
166
167 HTML versions of the Wireshark project man pages are available at
168 https://www.wireshark.org/docs/man-pages.
169
171 Original Author
172 Scott Renfro <scott[AT]renfro.org>
173
174 Contributors
175 Bill Guyton <guyton[AT]bguyton.com>
176
177
178
179 2022-02-16 MERGECAP(1)