blob: 451dd90b7e2f88f486548c35905adbbbf4e5b0e3 [file] [log] [blame]
JP Abgrall511eca32014-02-12 13:46:45 -08001.\" Copyright (c) 1994, 1996, 1997
2.\" The Regents of the University of California. All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that: (1) source code distributions
6.\" retain the above copyright notice and this paragraph in its entirety, (2)
7.\" distributions including binary code include the above copyright notice and
8.\" this paragraph in its entirety in the documentation or other materials
9.\" provided with the distribution, and (3) all advertising materials mentioning
10.\" features or use of this software display the following acknowledgement:
11.\" ``This product includes software developed by the University of California,
12.\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13.\" the University nor the names of its contributors may be used to endorse
14.\" or promote products derived from this software without specific prior
15.\" written permission.
16.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19.\"
Elliott Hughes965a4b52017-05-15 10:37:39 -070020.TH PCAP-SAVEFILE @MAN_FILE_FORMATS@ "8 March 2015"
JP Abgrall511eca32014-02-12 13:46:45 -080021.SH NAME
22pcap-savefile \- libpcap savefile format
23.SH DESCRIPTION
24NOTE: applications and libraries should, if possible, use libpcap to
Elliott Hughesd8845d72015-10-19 18:07:04 -070025read savefiles, rather than having their own code to read savefiles.
JP Abgrall511eca32014-02-12 13:46:45 -080026If, in the future, a new file format is supported by libpcap,
27applications and libraries using libpcap to read savefiles will be able
28to read the new format of savefiles, but applications and libraries
29using their own code to read savefiles will have to be changed to
30support the new file format.
31.PP
32``Savefiles'' read and written by libpcap and applications using libpcap
33start with a per-file header. The format of the per-file header is:
34.RS
35.TS
36box;
37c s
38c | c
39c s.
40Magic number
41_
42Major version Minor version
43_
44Time zone offset
45_
46Time stamp accuracy
47_
48Snapshot length
49_
50Link-layer header type
51.TE
52.RE
53.PP
54All fields in the per-file header are in the byte order of the host
55writing the file. Normally, the first field in the per-file header is a
564-byte magic number, with the value 0xa1b2c3d4. The magic number, when
57read by a host with the same byte order as the host that wrote the file,
58will have the value 0xa1b2c3d4, and, when read by a host with the
59opposite byte order as the host that wrote the file, will have the value
600xd4c3b2a1. That allows software reading the file to determine whether
61the byte order of the host that wrote the file is the same as the byte
62order of the host on which the file is being read, and thus whether the
63values in the per-file and per-packet headers need to be byte-swapped.
64.PP
65If the magic number has the value 0xa1b23c4d (with the two nibbles of
66the two lower-order bytes of the magic number swapped), which would be
67read as 0xa1b23c4d by a host with the same byte order as the host that
68wrote the file and as 0x4d3cb2a1 by a host with the opposite byte order
69as the host that wrote the file, the file format is the same as for
70regular files, except that the time stamps for packets are given in
71seconds and nanoseconds rather than seconds and microseconds.
72.PP
73Following this are:
74.IP
75A 2-byte file format major version number; the current version number is
762.
77.IP
78A 2-byte file format minor version number; the current version number is
794.
80.IP
81A 4-byte time zone offset; this is always 0.
82.IP
83A 4-byte number giving the accuracy of time stamps in the file; this is
84always 0.
85.IP
86A 4-byte number giving the "snapshot length" of the capture; packets
87longer than the snapshot length are truncated to the snapshot length, so
88that, if the snapshot length is
89.IR N ,
90only the first
91.I N
92bytes of a packet longer than
93.I N
94bytes will be saved in the capture.
95.IP
96a 4-byte number giving the link-layer header type for packets in the
97capture; see
98.BR pcap-linktype (@MAN_MISC_INFO@)
99for the
100.B LINKTYPE_
101values that can appear in this field.
102.PP
103Following the per-file header are zero or more packets; each packet
104begins with a per-packet header, which is immediately followed by the
105raw packet data. The format of the per-packet header is:
106.RS
107.TS
108box;
109c.
110Time stamp, seconds value
111_
112Time stamp, microseconds or nanoseconds value
113_
114Length of captured packet data
115_
116Un-truncated length of the packet data
117.TE
118.RE
119.PP
120All fields in the per-packet header are in the byte order of the host
121writing the file. The per-packet header begins with a time stamp giving
122the approximate time the packet was captured; the time stamp consists of
123a 4-byte value, giving the time in seconds since January 1, 1970,
12400:00:00 UTC, followed by a 4-byte value, giving the time in
125microseconds or nanoseconds since that second, depending on the magic
126number in the file header. Following that are a 4-byte value giving the
127number of bytes of captured data that follow the per-packet header and a
1284-byte value giving the number of bytes that would have been present had
129the packet not been truncated by the snapshot length. The two lengths
130will be equal if the number of bytes of packet data are less than or
131equal to the snapshot length.
132.SH SEE ALSO
133pcap(3PCAP), pcap-linktype(@MAN_MISC_INFO@)