Contents Menu Expand Light mode Dark mode Auto light/dark, in light mode Auto light/dark, in dark mode Skip to content
PyPCAPKit
PyPCAPKit

API Reference

  • Module Documentation
    • User Interface
      • Core Interface
      • Auxiliary Interface
      • Registry Helpers
    • Library Foundation
      • File Extractor
      • Engine Support
        • Base Engine
        • Built-in Engines
        • 3rd-Party Engines
      • Packets Reassembly
        • Reassembly Base Class
        • IP Datagram Reassembly
          • IP Reassembly Base Class
          • IPv4 Datagram Reassembly
          • IPv6 Datagram Reassembly
        • TCP Datagram Reassembly
        • DTLS Handshake-Message Reassembly
      • Reassembled Payload Analysis
        • IP Datagram Analysis
        • TCP Datagram Analysis
        • DTLS Handshake-Message Analysis
      • Flow Tracing
        • Flow Tracing Base Class
        • Follow TCP Stream
      • Registry Management
    • Protocol Family
      • Root Protocol
      • Link Layer
        • Link Layer Base Protocol
        • Ethernet Protocol
        • ARP - Address Resolution Protocol
        • InARP - Inverse Address Resolution Protocol
        • FRAD - Frame Relay Access Device
        • GRE - Generic Routing Encapsulation
        • IEEE 802.11 - Wireless LAN MAC Header
        • L2TP - Layer Two Tunnelling Protocol
        • L2TPv2 - Layer Two Tunnelling Protocol Version 2
        • LinuxSLL - Linux “Cooked” Capture Encapsulation Family
        • Linux “Cooked” Capture Encapsulation
        • Linux “Cooked” Capture Encapsulation v2
        • BSD Loopback Encapsulation
        • Netlink - Linux Netlink Socket Framing
        • Radiotap - IEEE 802.11 Radiotap Header
        • VLAN - 802.1Q/802.1ad VLAN Tag Types
        • C_Tag - 802.1Q Customer VLAN Tag Type
        • S_Tag - 802.1ad Service VLAN Tag Type
      • Internet Layer
        • Internet Layer Base Protocol
        • IP - Internet Protocol
        • IPv4 - Internet Protocol Version 4
        • IPv6 - Internet Protocol Version 6
        • IPv6-Ext - IPv6 Extension Header
        • IPv6-Frag - Fragment Header for IPv6
        • IPv6-Opts - Destination Options for IPv6
        • IPv6-Route - Routing Header for IPv6
        • HOPOPT - IPv6 Hop-by-Hop Options
        • IPv6 Options - Shared Option Helpers
        • MH - Mobility Header
        • IPsec - Internet Protocol Security
        • AH - Authentication Header
        • ESP - Encapsulating Security Payload
        • ICMP - Internet Control Message Protocol
        • ICMPv4 - Internet Control Message Protocol
        • ICMPv6 - Internet Control Message Protocol for IPv6
        • HIP - Host Identity Protocol
        • IGMP - Internet Group Management Protocol
        • IGMPv1 - Internet Group Management Protocol Version 1
        • IGMPv2 - Internet Group Management Protocol Version 2
        • IGMPv3 - Internet Group Management Protocol Version 3
        • IPX - Internetwork Packet Exchange
      • Transport Layer
        • Transport Layer Base Protocol
        • DCCP - Datagram Congestion Control Protocol
        • SCTP - Stream Control Transmission Protocol
        • TCP - Transmission Control Protocol
        • UDP - User Datagram Protocol
      • Application Layer
        • Application Layer Base Protocol
        • HTTP - Hypertext Transfer Protocol
        • HTTP/1.* - Hypertext Transfer Protocol
        • HTTP/2 - Hypertext Transfer Protocol
        • FTP - File Transfer Protocol
        • FTP_DATA - FTP Data Channel
        • NGAP - NG Application Protocol
        • OSPF - Open Shortest Path First
        • RARP - Reverse Address Resolution Protocol
        • DRARP - Dynamic Reverse Address Resolution Protocol
        • SSL - Secure Sockets Layer
        • SSLv2 - Secure Sockets Layer Version 2
        • TLS/SSL - Transport Layer Security
        • SSLv3 - Secure Sockets Layer Version 3
        • DTLS - Datagram Transport Layer Security
      • Auxiliary Protocols
        • PCAP File Headers
        • PCAP-NG File Format
        • Raw Packet Data
        • No-Payload Packet
        • Checksums
    • Module Utilities
      • User Defined Exceptions
      • User Defined Warnings
      • Logging System
      • Configuration
      • Character Set Detection
      • Timestamp Conversion
      • Pickle Reductions
      • Shared Context Variables
      • Lazy Imports
    • Core Utilities
      • Protocol Fields
        • Base Fields
        • Numerical Fields
        • Text Fields
        • IP Address Fields
        • Container Fields
        • Miscellaneous Fields
      • Checksums
        • Internet Checksum
      • Parsing Context
      • Decorator Functions
      • Enumeration Base
      • Info Class
      • I/O Objects
      • Module Descriptor
      • Multi-Mapping Dictionary
      • Deferred Packet
      • Protocol Chain
      • Schema Helpers
        • Byte-Order Helpers
        • IP Address Conversion
        • Jumbo Payload Lookup
        • Padding Arithmetic
        • Short-Read Replay
      • Sentinel Objects
      • Version Info
    • Compatibility Tools
      • Built-in Support
      • 3rd-Party Support
    • Dump Utilities
      • Common Utilities
      • PCAP Dumper
      • Null Dumper
    • Constant Enumerations
      • Protocol Type Registry Constant Enumerations
      • ARP Constant Enumerations
      • IEEE802_11 Constant Enumerations
      • L2TP Constant Enumerations
      • Linux-Specific Constant Enumerations
      • Radiotap Constant Enumerations
      • VLAN Constant Enumerations
      • ESP Constant Enumerations
      • HIP Constant Enumerations
      • ICMPv4 Constant Enumerations
      • ICMPv6 Constant Enumerations
      • IGMP Constant Enumerations
      • IPv4 Constant Enumerations
      • IPv6 Constant Enumerations
      • IPX Constant Enumerations
      • MH Constant Enumerations
      • DCCP Constant Enumerations
      • SCTP Constant Enumerations
      • TCP Constant Enumerations
      • FTP Constant Enumerations
      • HTTP Constant Enumerations
      • NGAP Constant Enumerations
      • OSPF Constant Enumerations
      • SSLv2 Constant Enumerations
      • SSL Constant Enumerations
      • PCAPNG Constant Enumerations
    • Vendor Crawlers
      • Base Crawler
      • Protocol Type Registry Vendor Crawlers
      • ARP Vendor Crawlers
      • IEEE802_11 Vendor Crawlers
      • L2TP Vendor Crawlers
      • Linux-Specific Vendor Crawlers
      • Radiotap Vendor Crawlers
      • VLAN Vendor Crawlers
      • ESP Vendor Crawlers
      • HIP Vendor Crawler
      • ICMPv4 Vendor Crawlers
      • ICMPv6 Vendor Crawlers
      • IGMP Vendor Crawlers
      • IPv4 Vendor Crawlers
      • IPv6 Vendor Crawlers
      • IPX Vendor Crawlers
      • MH Vendor Crawlers
      • DCCP Vendor Crawlers
      • SCTP Vendor Crawlers
      • TCP Vendor Crawlers
      • FTP Vendor Crawler
      • HTTP Vendor Crawler
      • NGAP Vendor Crawlers
      • OSPF Vendor Crawlers
      • SSLv2 Vendor Crawlers
      • SSL Vendor Crawlers
      • PCAPNG Vendor Crawlers

Guides & Changelog

  • Engine Comparison
  • Customisation & Extensions
  • How to …
  • Glossary
  • Changelog
    • 1.6.0 – unreleased
    • 1.5.1 – 2026-10-30
    • 1.5.0 – 2026-10-29
    • 1.4.1 – 2026-08-22
    • 1.4.0 – 2026-08-21
    • 1.3.5 – 2024-11-16
    • 1.3.4 – 2024-11-14
    • 1.3.3 – 2024-11-03
    • 1.3.1 – 2023-12-21
    • 1.3.0 – 2023-10-04
    • 1.2.2 – 2023-09-14
    • 1.2.1 – 2023-08-27
    • 1.2.0 – 2023-08-26
    • 1.1.1 – 2023-08-15
    • 1.1.0 – 2023-07-09
    • 1.0.3 – 2023-06-29
    • 1.0.2 – 2023-06-05
    • 1.0.1 – 2023-05-14
    • 1.0.0 – 2023-05-09
    • 0.16.3 – 2022-10-31
    • 0.16.2 – 2022-08-03
    • 0.16.1 – 2022-06-07
    • 0.16.0 – 2022-05-31
    • 0.15.5 – 2020-10-11
    • 0.15.4 – 2020-08-28
    • 0.15.3 – 2020-08-17
    • 0.15.2 – 2020-06-27
    • 0.15.1 – 2020-06-18
    • 0.15.0 – 2020-06-07
    • 0.14.5 – 2019-10-24
    • 0.14.4 – 2019-09-01
    • 0.14.3 – 2019-08-08
    • 0.14.2 – 2019-03-28
    • 0.14.1 – 2019-03-07
    • 0.14.0 – 2019-03-02
    • 0.13.3 – 2019-02-26
    • 0.13.2 – 2019-01-24
    • 0.13.1 – 2019-01-23
    • 0.13.0 – 2018-12-08

Contributing

  • Testing
  • House Conventions
    • Minting an Unrecognised Value
    • Naming a Sentinel
    • The Registry Protocol
    • Extension-Header Base Classes
    • Protocol Family Grouping
    • Protocol Member Order
    • Protocol Layer Placement
    • Running the Repository
    • Writing the Documentation
    • Testing a Change
    • Choosing Between utilities and corekit
    • Reassembly Integration
    • Const-Vendor Pairing
  • Release Process
  • GitHub Actions Workflows
  • Help Wanted
Back to top
View this page
Edit this page

Netlink - Linux Netlink Socket Framing¶

pcapkit.protocols.link.netlink contains Netlink only, which implements the extractor for the struct nlmsghdr framing of Linux’s own kernel/user IPC transport, as seen on a LINKTYPE_LINUX_SLL/LINKTYPE_LINUX_SLL2 capture whose arphrd_type is ARPHRD_NETLINK (an nlmon interface). Its structure is described as below:

Octets

Bits

Name

Description

0

0

netlink.nlmsg_len

Message Length (header included)

4

32

netlink.nlmsg_type

Message Type

6

48

netlink.nlmsg_flags

Message Flags

8

64

netlink.nlmsg_seq

Sequence Number

12

96

netlink.nlmsg_pid

Sender Port ID

Only this fixed 16-octet header is dissected; per-family message payloads and multiple messages packed into one capture are out of scope for this first cut – see the module docstring’s Scope section. The byte order the header was written in is ambiguous (Netlink [*] is kernel/userspace IPC, not wire format) and is guessed by nlmsg_byteorder(); either way it is kept as netlink.byteorder.

class pcapkit.protocols.link.netlink.Netlink(file=None, length=None, **kwargs)[source]¶

Bases: Link[Netlink, Netlink]

This class implements Linux Netlink socket framing.

Every message’s payload is kept as Raw unless its nlmsg_type is registered – see the module docstring’s Scope section for why. self.__proto__ ships empty, so that register() works the same way every other Link subclass’s does.

property name: Literal['Netlink']¶

Name of current protocol.

property alias: Literal['Netlink']¶

Acronym of corresponding protocol.

property length: Literal[16]¶

Header length of current protocol.

property protocol: int¶

Message type of the dissected nlmsghdr.

classmethod id()[source]¶

Index ID of the protocol.

Return type:

tuple[Literal['Netlink']]

read(length=None, *, byteorder=None, **kwargs)[source]¶

Read Linux Netlink socket framing.

Structure of the nlmsghdr this class dissects, the first message in the frame:

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            nlmsg_len                         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|            nlmsg_type         |          nlmsg_flags          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            nlmsg_seq                         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                            nlmsg_pid                         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

  • byteorder (Literal['big', 'little'] | None) – Byte order to read the header in, ahead of guessing it from nlmsg_byteorder(). make() is handed the one info holds by from_data, and it reaches here too, so a rebuild reads the header as it was parsed rather than guessing again.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

Netlink

Returns:

Parsed packet data.

Raises:

ProtocolError – If byteorder is neither 'big' nor 'little'.

make(nlmsg_type=0, nlmsg_flags=0, nlmsg_seq=0, nlmsg_pid=0, nlmsg_len=None, byteorder=sys.byteorder, payload=b'', **kwargs)[source]¶

Make (construct) packet data.

Parameters:
  • nlmsg_type (int) – Message type.

  • nlmsg_flags (int) – Message flags.

  • nlmsg_seq (int) – Sequence number.

  • nlmsg_pid (int) – Sender port ID.

  • nlmsg_len (int | None) – Message length, header included; computed from the header and payload when omitted.

  • byteorder (Literal['big', 'little']) – Byte order to write the header in, by default this host’s, as a genuine capture is written in the capturing host’s own order.

  • payload (bytes | ProtocolBase | Schema) – Payload data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

Netlink

Returns:

Constructed packet data.

Raises:

ProtocolError – If byteorder is neither 'big' nor 'little'; if nlmsg_type or nlmsg_flags is not an int (a bool included) or does not fit in 16 bits; if nlmsg_seq or nlmsg_pid is not an int (a bool included) or does not fit in 32 bits; or if nlmsg_len is given and does not fit in 32 bits.

classmethod register(code, protocol)[source]¶

Register a new protocol class for a message type.

Notes

The fully qualified class name of the new protocol class should be {protocol.module}.{protocol.name}.

Parameters:
  • code (int) – nlmsg_type of the dissected message

  • protocol (ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]) – module descriptor or a ProtocolBase subclass

Important

This overrides Link.register because self.__proto__ is keyed by nlmsg_type rather than by EtherType.

Raises:

pcapkit.utilities.exceptions.RegistryError – If protocol is not a class, or not a ProtocolBase subclass.

Warns:

pcapkit.utilities.warnings.RegistryWarning – If this message type is already registered and the incumbent differs from the replacement; see Protocol.register for the guard.

__length_hint__()[source]¶

Return an estimated length for the object.

Return type:

Literal[16]

classmethod __index__()[source]¶

Numeral registry index of the protocol.

Return type:

ARPHRD

Returns:

Numeral registry index of the protocol in Linux ARP hardware types, the arphrd_type that LinuxSLL.__proto__ dispatches here.

classmethod _make_data(data)[source]¶

Create key-value pairs from data for protocol construction.

Parameters:

data (Netlink) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

__proto__: DefaultDict[int, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]¶

Protocol index mapping for decoding next layer, keyed by nlmsg_type. Deliberately empty – see the class docstring – so every unregistered key resolves through the defaultdict fallback to Raw.

pcapkit.protocols.link.netlink.nlmsg_byteorder(nlmsg_len, length)[source]¶

Guess the byte order a Netlink message header was written in.

Parameters:
  • nlmsg_len (bytes) – The 4 raw octets of nlmsg_len.

  • length (int) – Octets available from the start of this header to the end of the frame – nlmsg_len counts the header itself (RFC 3549 Section 2.3.2: “the length of the message in bytes, including the header”), so this is the quantity to compare against, not the payload alone.

Return type:

Literal['big', 'little']

Returns:

'big' or 'little', whichever reading of nlmsg_len comes closer to length; ties favour 'little', the overwhelmingly common case (x86/ARM hosts).

Note

This is the heuristic Wireshark’s own netlink dissector uses (packet-netlink.c, dissect_netlink()): a genuine message length is normally well under the size either misreading of 4 arbitrary octets would imply, so the reading closer to the octets actually on hand is overwhelmingly likely to be the real one.

Header Schemas¶

class pcapkit.protocols.schema.link.netlink.Netlink(nlmsg_len=NO_VALUE, nlmsg_type=NO_VALUE, nlmsg_flags=NO_VALUE, nlmsg_seq=NO_VALUE, nlmsg_pid=NO_VALUE, payload=NO_VALUE, *, __packet__=None, **kwargs)[source]¶

Bases: Schema

Header schema for Linux Netlink socket framing (nlmsghdr).

nlmsg_len: bytes = <BytesField nlmsg_len>¶

Message length, including this header; 4 octets, byte order ambiguous.

nlmsg_type: bytes = <BytesField nlmsg_type>¶

Message type; 2 octets, byte order ambiguous.

nlmsg_flags: bytes = <BytesField nlmsg_flags>¶

Message flags; 2 octets, byte order ambiguous.

nlmsg_seq: bytes = <BytesField nlmsg_seq>¶

Sequence number; 4 octets, byte order ambiguous.

nlmsg_pid: bytes = <BytesField nlmsg_pid>¶

Sender port ID; 4 octets, byte order ambiguous.

payload: bytes = <PayloadField payload>¶

Payload.

Data Models¶

class pcapkit.protocols.data.link.netlink.Netlink(nlmsg_len, nlmsg_type, nlmsg_flags, nlmsg_seq, nlmsg_pid, byteorder)[source]¶

Bases: Protocol

Data model for Linux Netlink socket framing (nlmsghdr).

nlmsg_len: int¶

Message length, in octets, including this 16-octet header – as written, in whichever byte order byteorder records.

nlmsg_type: int¶

Message type; 1-4 are the generic control values (NLMSG_NOOP/NLMSG_ERROR/NLMSG_DONE/NLMSG_OVERRUN) shared by every Netlink family, 16 and above are family-specific and not interpreted by this class.

nlmsg_flags: int¶

Message flags; their bit meanings depend on nlmsg_type and on whether the message is a request, so they are not decoded further.

nlmsg_seq: int¶

Sequence number.

nlmsg_pid: int¶

Sender port ID; 0 when sent by the kernel.

byteorder: Literal['big', 'little']¶

Byte order the header was written in.

Footnotes

[*]

netlink(7); RFC 3549 Section 2.3.2

Next
Radiotap - IEEE 802.11 Radiotap Header
Previous
BSD Loopback Encapsulation
Copyright © 2017-2026, Jarry Shaw
Made with Sphinx and @pradyunsg's Furo
On this page
  • Netlink - Linux Netlink Socket Framing
    • Header Schemas
    • Data Models