Skip to content

Fix pcapng timestamps for multiple capture interfaces - #691

Open
ac1982 wants to merge 1 commit into
kbandla:masterfrom
ac1982:fix/pcapng-interface-timestamps
Open

ac1982 wants to merge 1 commit into
kbandla:masterfrom
ac1982:fix/pcapng-interface-timestamps

Conversation

@ac1982

@ac1982 ac1982 commented Oct 14, 2026

Copy link
Copy Markdown

Fixes #681.

Reader currently applies the first interface's timestamp resolution and offset to every packet. A capture containing microsecond and nanosecond interfaces therefore produces incorrect timestamps for the later interface.

Register each interface's clock and use the EPB/PB interface ID when decoding timestamps. Reset this table at section boundaries and read the new section's byte order before interpreting block lengths. Keep idb, snaplen, dloff and datalink() describing the first interface. Since the pypcap-compatible API exposes only one link type, explicitly reject incompatible link types; unknown interface IDs also raise ValueError.

Regression tests cover interleaved interfaces, decimal and binary resolutions, signed offsets, high timestamp bits, both packet block formats, mixed-endian sections and invalid interface references. All four new tests fail against the original implementation.

Validation:

  • Python 3.12: all 457 tests pass; pcapng subset 43 tests pass.
  • Python 2.7 in an amd64 Docker container: all 457 tests pass.
  • CI's fatal flake8 checks pass.
  • An independently serialized capture produces the same six timestamps in dpkt and tshark, with Ethernet/ARP payloads intact; UniversalReader also reads it correctly.

Other Python versions and operating systems were not tested locally. Simple Packet Blocks remain ignored as before; the writer is unchanged.

AI assistance was used for investigation, implementation and validation.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PCAPNG file with multiple interface description blocks is parsed incorrectly

1 participant