1EDITCAP(1)              The Wireshark Network Analyzer              EDITCAP(1)
2
3
4

NAME

6       editcap - Edit and/or translate the format of capture files
7

SYNOPSIS

9       editcap [ -a <frame:comment> ] [ -A <start time> ] [ -B <stop time> ]
10       [ -c <packets per file> ] [ -C [offset:]<choplen> ]
11       [ -E <error probability> ] [ -F <file format> ] [ -h ]
12       [ -i <seconds per file> ] [ -o <change offset> ] [ -L ] [ -r ]
13       [ -s <snaplen> ] [ -S <strict time adjustment> ]
14       [ -t <time adjustment> ] [ -T <encapsulation type> ] [ -v ]
15       [ --inject-secrets <secrets type>,<file> ] [ --discard-all-secrets ]
16       infile outfile [ packet#[-packet#] ... ]
17
18       editcap  -d  |  -D <dup window>  |  -w <dup time window>  [ -v ]
19       [ -I <bytes to ignore> ] [ --skip-radiotap-header ] infile outfile
20
21       editcap [ -V ]
22

DESCRIPTION

24       Editcap is a program that reads some or all of the captured packets
25       from the infile, optionally converts them in various ways and writes
26       the resulting packets to the capture outfile (or outfiles).
27
28       By default, it reads all packets from the infile and writes them to the
29       outfile in pcapng file format.
30
31       An optional list of packet numbers can be specified on the command
32       tail; individual packet numbers separated by whitespace and/or ranges
33       of packet numbers can be specified as start-end, referring to all
34       packets from start to end.  By default the selected packets with those
35       numbers will not be written to the capture file.  If the -r flag is
36       specified, the whole packet selection is reversed; in that case only
37       the selected packets will be written to the capture file.
38
39       Editcap can also be used to remove duplicate packets.  Several
40       different options (-d, -D and -w) are used to control the packet window
41       or relative time window to be used for duplicate comparison.
42
43       Editcap can be used to assign comment strings to frame numbers.
44
45       Editcap is able to detect, read and write the same capture files that
46       are supported by Wireshark.  The input file doesn't need a specific
47       filename extension; the file format and an optional gzip compression
48       will be automatically detected.  Near the beginning of the DESCRIPTION
49       section of wireshark(1) or
50       <https://www.wireshark.org/docs/man-pages/wireshark.html> is a detailed
51       description of the way Wireshark handles this, which is the same way
52       Editcap handles this.
53
54       Editcap can write the file in several output formats. The -F flag can
55       be used to specify the format in which to write the capture file;
56       editcap -F provides a list of the available output formats.
57

OPTIONS

59       -a  <framenum:comment>
60           For the specificed frame number, assign the given comment string.
61           Can be repeated for multiple frames.  Quotes should be used with
62           comment strings that include spaces.
63
64       -A  <start time>
65           Saves only the packets whose timestamp is on or after start time.
66           The time is given in the following format YYYY-MM-DD HH:MM:SS
67
68       -B  <stop time>
69           Saves only the packets whose timestamp is before stop time.  The
70           time is given in the following format YYYY-MM-DD HH:MM:SS
71
72       -c  <packets per file>
73           Splits the packet output to different files based on uniform packet
74           counts with a maximum of <packets per file> each. Each output file
75           will be created with a suffix -nnnnn, starting with 00000. If the
76           specified number of packets is written to the output file, the next
77           output file is opened. The default is to use a single output file.
78
79       -C  [offset:]<choplen>
80           Sets the chop length to use when writing the packet data. Each
81           packet is chopped by <choplen> bytes of data. Positive values chop
82           at the packet beginning while negative values chop at the packet
83           end.
84
85           If an optional offset precedes the <choplen>, then the bytes
86           chopped will be offset from that value. Positive offsets are from
87           the packet beginning, while negative offsets are from the packet
88           end.
89
90           This is useful for chopping headers for decapsulation of an entire
91           capture, removing tunneling headers, or in the rare case that the
92           conversion between two file formats leaves some random bytes at the
93           end of each packet. Another use is for removing vlan tags.
94
95           NOTE: This option can be used more than once, effectively allowing
96           you to chop bytes from up to two different areas of a packet in a
97           single pass provided that you specify at least one chop length as a
98           positive value and at least one as a negative value.  All positive
99           chop lengths are added together as are all negative chop lengths.
100
101       -d  Attempts to remove duplicate packets.  The length and MD5 hash of
102           the current packet are compared to the previous four (4) packets.
103           If a match is found, the current packet is skipped.  This option is
104           equivalent to using the option -D 5.
105
106       -D  <dup window>
107           Attempts to remove duplicate packets.  The length and MD5 hash of
108           the current packet are compared to the previous <dup window> - 1
109           packets.  If a match is found, the current packet is skipped.
110
111           The use of the option -D 0 combined with the -v option is useful in
112           that each packet's Packet number, Len and MD5 Hash will be printed
113           to standard out.  This verbose output (specifically the MD5 hash
114           strings) can be useful in scripts to identify duplicate packets
115           across trace files.
116
117           The <dup window> is specified as an integer value between 0 and
118           1000000 (inclusive).
119
120           NOTE: Specifying large <dup window> values with large tracefiles
121           can result in very long processing times for editcap.
122
123       -E  <error probability>
124           Sets the probability that bytes in the output file are randomly
125           changed.  Editcap uses that probability (between 0.0 and 1.0
126           inclusive) to apply errors to each data byte in the file.  For
127           instance, a probability of 0.02 means that each byte has a 2%
128           chance of having an error.
129
130           This option is meant to be used for fuzz-testing protocol
131           dissectors.
132
133       -F  <file format>
134           Sets the file format of the output capture file.  Editcap can write
135           the file in several formats, editcap -F provides a list of the
136           available output formats. The default is the pcapng format.
137
138       -h  Prints the version and options and exits.
139
140       -i  <seconds per file>
141           Splits the packet output to different files based on uniform time
142           intervals using a maximum interval of <seconds per file> each.
143           Floating point values (e.g. 0.5) are allowed. Each output file will
144           be created with a suffix -nnnnn, starting with 00000. If packets
145           for the specified time interval are written to the output file, the
146           next output file is opened. The default is to use a single output
147           file.
148
149       -I  <bytes to ignore>
150           Ignore the specified number of bytes at the beginning of the frame
151           during MD5 hash calculation, unless the frame is too short, then
152           the full frame is used.  Useful to remove duplicated packets taken
153           on several routers (different mac addresses for example) e.g. -I 26
154           in case of Ether/IP will ignore ether(14) and IP header(20 - 4(src
155           ip) - 4(dst ip)).  The default value is 0.
156
157       -L  Adjust the original frame length accordingly when chopping and/or
158           snapping (in addition to the captured length, which is always
159           adjusted regardless of whether -L is specified or not).  See also
160           -C <choplen> and -s <snaplen>.
161
162       -o  <change offset>
163           When used in conjunction with -E, skip some bytes from the
164           beginning of the packet from being changed. In this way some
165           headers don't get changed, and the fuzzer is more focused on a
166           smaller part of the packet. Keeping a part of the packet fixed the
167           same dissector is triggered, that make the fuzzing more precise.
168
169       -r  Reverse the packet selection.  Causes the packets whose packet
170           numbers are specified on the command line to be written to the
171           output capture file, instead of discarding them.
172
173       -s  <snaplen>
174           Sets the snapshot length to use when writing the data.  If the -s
175           flag is used to specify a snapshot length, packets in the input
176           file with more captured data than the specified snapshot length
177           will have only the amount of data specified by the snapshot length
178           written to the output file.
179
180           This may be useful if the program that is to read the output file
181           cannot handle packets larger than a certain size (for example, the
182           versions of snoop in Solaris 2.5.1 and Solaris 2.6 appear to reject
183           Ethernet packets larger than the standard Ethernet MTU, making them
184           incapable of handling gigabit Ethernet captures if jumbo packets
185           were used).
186
187       --seed  <seed>
188           When used in conjunction with -E, set the seed for the pseudo-
189           random number generator.  This is useful for recreating a
190           particular sequence of errors.
191
192       --skip-radiotap-header
193           Skip the readiotap header of each frame when checking for packet
194           duplicates. This is useful when processing a caputure created by
195           combining outputs of multiple capture devices on the same channel
196           in the vicinity of each other.
197
198       -S  <strict time adjustment>
199           Time adjust selected packets to ensure strict chronological order.
200
201           The <strict time adjustment> value represents relative seconds
202           specified as [-]seconds[.fractional seconds].
203
204           As the capture file is processed each packet's absolute time is
205           possibly adjusted to be equal to or greater than the previous
206           packet's absolute timestamp depending on the <strict time
207           adjustment> value.
208
209           If <strict time adjustment> value is 0 or greater (e.g. 0.000001)
210           then only packets with a timestamp less than the previous packet
211           will adjusted.  The adjusted timestamp value will be set to be
212           equal to the timestamp value of the previous packet plus the value
213           of the <strict time adjustment> value.  A <strict time adjustment>
214           value of 0 will adjust the minimum number of timestamp values
215           necessary to ensure that the resulting capture file is in strict
216           chronological order.
217
218           If <strict time adjustment> value is specified as a negative value,
219           then the timestamp values of all packets will be adjusted to be
220           equal to the timestamp value of the previous packet plus the
221           absolute value of the <lt>strict time adjustment<gt> value. A
222           <strict time adjustment> value of -0 will result in all packets
223           having the timestamp value of the first packet.
224
225           This feature is useful when the trace file has an occasional packet
226           with a negative delta time relative to the previous packet.
227
228       -t  <time adjustment>
229           Sets the time adjustment to use on selected packets.  If the -t
230           flag is used to specify a time adjustment, the specified adjustment
231           will be applied to all selected packets in the capture file.  The
232           adjustment is specified as [-]seconds[.fractional seconds].  For
233           example, -t 3600 advances the timestamp on selected packets by one
234           hour while -t -0.5 reduces the timestamp on selected packets by
235           one-half second.
236
237           This feature is useful when synchronizing dumps collected on
238           different machines where the time difference between the two
239           machines is known or can be estimated.
240
241       -T  <encapsulation type>
242           Sets the packet encapsulation type of the output capture file.  If
243           the -T flag is used to specify an encapsulation type, the
244           encapsulation type of the output capture file will be forced to the
245           specified type.  editcap -T provides a list of the available types.
246           The default type is the one appropriate to the encapsulation type
247           of the input capture file.
248
249           Note: this merely forces the encapsulation type of the output file
250           to be the specified type; the packet headers of the packets will
251           not be translated from the encapsulation type of the input capture
252           file to the specified encapsulation type (for example, it will not
253           translate an Ethernet capture to an FDDI capture if an Ethernet
254           capture is read and '-T fddi' is specified). If you need to
255           remove/add headers from/to a packet, you will need
256           od(1)/text2pcap(1).
257
258       -v  Causes editcap to print verbose messages while it's working.
259
260           Use of -v with the de-duplication switches of -d, -D or -w will
261           cause all MD5 hashes to be printed whether the packet is skipped or
262           not.
263
264       -V  Print the version and exit.
265
266       -w  <dup time window>
267           Attempts to remove duplicate packets.  The current packet's arrival
268           time is compared with up to 1000000 previous packets.  If the
269           packet's relative arrival time is less than or equal to the <dup
270           time window> of a previous packet and the packet length and MD5
271           hash of the current packet are the same then the packet to skipped.
272           The duplicate comparison test stops when the current packet's
273           relative arrival time is greater than <dup time window>.
274
275           The <dup time window> is specified as seconds[.fractional seconds].
276
277           The [.fractional seconds] component can be specified to nine (9)
278           decimal places (billionths of a second) but most typical trace
279           files have resolution to six (6) decimal places (millionths of a
280           second).
281
282           NOTE: Specifying large <dup time window> values with large
283           tracefiles can result in very long processing times for editcap.
284
285           NOTE: The -w option assumes that the packets are in chronological
286           order.  If the packets are NOT in chronological order then the -w
287           duplication removal option may not identify some duplicates.
288
289       --inject-secrets <secrets type>,<file>
290           Inserts the contents of <file> into a Decryption Secrets Block
291           (DSB) within the pcapng output file. This enables decryption
292           without requiring additional configuration in protocol preferences.
293
294           The file format is described by <secrets type> which can be one of:
295
296           tls  TLS Key Log as described at
297           <https://developer.mozilla.org/NSS_Key_Log_Format> wg   WireGuard
298           Key Log, see <https://wiki.wireshark.org/WireGuard#Key_Log_Format>
299
300           This option may be specified multiple times. The available options
301           for <secrets type> can be listed with --inject-secrets help.
302
303       --discard-all-secrets
304           Discard all decryption secrets from the input file when writing the
305           output file.  Does not discard secrets added by --inject-secrets in
306           the same command line.
307

EXAMPLES

309       To see more detailed description of the options use:
310
311           editcap -h
312
313       To shrink the capture file by truncating the packets at 64 bytes and
314       writing it as Sun snoop file use:
315
316           editcap -s 64 -F snoop capture.pcapng shortcapture.snoop
317
318       To delete packet 1000 from the capture file use:
319
320           editcap capture.pcapng sans1000.pcapng 1000
321
322       To limit a capture file to packets from number 200 to 750 (inclusive)
323       use:
324
325           editcap -r capture.pcapng small.pcapng 200-750
326
327       To get all packets from number 1-500 (inclusive) use:
328
329           editcap -r capture.pcapng first500.pcapng 1-500
330
331       or
332
333           editcap capture.pcapng first500.pcapng 501-9999999
334
335       To exclude packets 1, 5, 10 to 20 and 30 to 40 from the new file use:
336
337           editcap capture.pcapng exclude.pcapng 1 5 10-20 30-40
338
339       To select just packets 1, 5, 10 to 20 and 30 to 40 for the new file
340       use:
341
342           editcap -r capture.pcapng select.pcapng 1 5 10-20 30-40
343
344       To remove duplicate packets seen within the prior four frames use:
345
346           editcap -d capture.pcapng dedup.pcapng
347
348       To remove duplicate packets seen within the prior four frames while
349       skipping radiotap headers use:
350
351           editcap -d --skip-radiotap-header capture.pcapng dedup.pcapng
352
353       To remove duplicate packets seen within the prior 100 frames use:
354
355           editcap -D 101 capture.pcapng dedup.pcapng
356
357       To remove duplicate packets seen equal to or less than 1/10th of a
358       second:
359
360           editcap -w 0.1 capture.pcapng dedup.pcapng
361
362       To display the MD5 hash for all of the packets (and NOT generate any
363       real output file):
364
365           editcap -v -D 0 capture.pcapng /dev/null
366
367       or on Windows systems
368
369           editcap -v -D 0 capture.pcapng NUL
370
371       To advance the timestamps of each packet forward by 3.0827 seconds:
372
373           editcap -t 3.0827 capture.pcapng adjusted.pcapng
374
375       To ensure all timestamps are in strict chronological order:
376
377           editcap -S 0 capture.pcapng adjusted.pcapng
378
379       To introduce 5% random errors in a capture file use:
380
381           editcap -E 0.05 capture.pcapng capture_error.pcapng
382
383       To remove vlan tags from all packets within an Ethernet-encapsulated
384       capture file, use:
385
386           editcap -L -C 12:4 capture_vlan.pcapng capture_no_vlan.pcapng
387
388       To chop both the 10 byte and 20 byte regions from the following 75 byte
389       packet in a single pass, use any of the 8 possible methods provided
390       below:
391
392           <--------------------------- 75 ---------------------------->
393
394           +---+-------+-----------+---------------+-------------------+
395           | 5 |   10  |     15    |       20      |         25        |
396           +---+-------+-----------+---------------+-------------------+
397
398           1) editcap -C 5:10 -C -25:-20 capture.pcapng chopped.pcapng
399           2) editcap -C 5:10 -C 50:-20 capture.pcapng chopped.pcapng
400           3) editcap -C -70:10 -C -25:-20 capture.pcapng chopped.pcapng
401           4) editcap -C -70:10 -C 50:-20 capture.pcapng chopped.pcapng
402           5) editcap -C 30:20 -C -60:-10 capture.pcapng chopped.pcapng
403           6) editcap -C 30:20 -C 15:-10 capture.pcapng chopped.pcapng
404           7) editcap -C -45:20 -C -60:-10 capture.pcapng chopped.pcapng
405           8) editcap -C -45:20 -C 15:-10 capture.pcapng chopped.pcapng
406
407       To add comment strings to the first 2 input frames, use:
408
409           editcap -a "1:1st frame" -a 2:Second capture.pcapng capture-comments.pcapng
410

SEE ALSO

412       pcap(3), wireshark(1), tshark(1), mergecap(1), dumpcap(1), capinfos(1),
413       text2pcap(1), od(1), pcap-filter(7) or tcpdump(8)
414

NOTES

416       Editcap is part of the Wireshark distribution.  The latest version of
417       Wireshark can be found at <https://www.wireshark.org>.
418
419       HTML versions of the Wireshark project man pages are available at:
420       <https://www.wireshark.org/docs/man-pages>.
421

AUTHORS

423         Original Author
424         -------- ------
425         Richard Sharpe           <sharpe[AT]ns.aus.com>
426
427
428         Contributors
429         ------------
430         Guy Harris               <guy[AT]alum.mit.edu>
431         Ulf Lamping              <ulf.lamping[AT]web.de>
432
433
434
4353.2.3                             2020-04-13                        EDITCAP(1)
Impressum