Skip to content

Commit 5f37c81

Browse files
committed
network/pcap.ksy: clarify magic meaning as per official documentation and StackOverflow, allow big-endian pcap parsing
1 parent e9bc0f1 commit 5f37c81

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

network/pcap.ksy

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,37 @@ meta:
99
pronom: fmt/779
1010
wikidata: Q28009435
1111
license: CC0-1.0
12-
ks-version: 0.8
12+
ks-version: '0.11'
1313
imports:
1414
- /network/ethernet_frame
1515
- /network/packet_ppi
16-
endian: le
1716
doc: |
1817
PCAP (named after libpcap / winpcap) is a popular format for saving
1918
network traffic grabbed by network sniffers. It is typically
2019
produced by tools like [tcpdump](https://www.tcpdump.org/) or
2120
[Wireshark](https://www.wireshark.org/).
2221
doc-ref: https://wiki.wireshark.org/Development/LibpcapFileFormat
2322
seq:
23+
- id: magic_number
24+
type: u4be
25+
enum: magic
2426
- id: hdr
2527
type: header
2628
- id: packets
2729
type: packet
2830
repeat: eos
2931
types:
3032
header:
33+
meta:
34+
endian:
35+
switch-on: _root.magic_number
36+
cases:
37+
'magic::le_microseconds': le
38+
'magic::le_nanoseconds': le
39+
'magic::be_microseconds': be
40+
'magic::be_nanoseconds': be
3141
doc-ref: 'https://wiki.wireshark.org/Development/LibpcapFileFormat#Global_Header'
3242
seq:
33-
- id: magic_number
34-
contents: [0xd4, 0xc3, 0xb2, 0xa1]
3543
- id: version_major
3644
type: u2
3745
valid:
@@ -61,12 +69,33 @@ types:
6169
Link-layer header type, specifying the type of headers at
6270
the beginning of the packet.
6371
packet:
72+
meta:
73+
endian:
74+
switch-on: _root.magic_number
75+
cases:
76+
'magic::le_microseconds': le
77+
'magic::le_nanoseconds': le
78+
'magic::be_microseconds': be
79+
'magic::be_nanoseconds': be
6480
doc-ref: 'https://wiki.wireshark.org/Development/LibpcapFileFormat#Record_.28Packet.29_Header'
6581
seq:
6682
- id: ts_sec
6783
type: u4
84+
doc: |
85+
Timestamp of a packet in seconds since 1970-01-01 00:00:00 UTC (UNIX timestamp).
86+
87+
In practice, some captures are not following that (e.g. because the device lacks
88+
a real-time clock), so this field might represent time since device boot, start of
89+
capture, or other arbitrary epoch.
6890
- id: ts_usec
6991
type: u4
92+
doc: |
93+
Depending on `_root.magic_number`, units for this field change:
94+
95+
* If it's `le_microseconds` or `be_microseconds`, this field
96+
contains microseconds.
97+
* If it's `le_nanoseconds` or `be_nanoseconds`, this field
98+
contains nanoseconds.
7099
- id: incl_len
71100
type: u4
72101
doc: Number of bytes of packet data actually captured and saved in the file.
@@ -296,3 +325,9 @@ enums:
296325
297: zwave_tap
297326
298: silabs_debug_channel
298327
299: fira_uci
328+
magic:
329+
# https://stackoverflow.com/a/17932578
330+
0xd4c3b2a1: le_microseconds
331+
0x4d3cb2a1: le_nanoseconds
332+
0xa1b2c3d4: be_microseconds
333+
0xa1b23c4d: be_nanoseconds

0 commit comments

Comments
 (0)