UDP - User Datagram Protocol¶
pcapkit.protocols.transport.udp contains
UDP only,
which implements extractor for User Datagram Protocol
(UDP) [*], whose structure is described as below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Source Port |
2 |
16 |
|
Destination Port |
4 |
32 |
|
Length (header includes) |
6 |
48 |
|
Checksum |
- class pcapkit.protocols.transport.udp.UDP(file=None, length=None, **kwargs)¶
-
This class implements User Datagram Protocol.
This class currently supports parsing of the following protocols, which are registered in the
self.__proto__attribute:Port Number
Protocol
80
1701
8080
Note
Both HTTP ports resolve to
pcapkit.protocols.application.http.HTTP, which identifies the version from the payload and delegates.TCP.__proto__binds the same class for its HTTP ports.- read(length=None, **kwargs)¶
Read User Datagram Protocol (UDP).
Structure of UDP header [RFC 768]:
0 7 8 15 16 23 24 31 +--------+--------+--------+--------+ | Source | Destination | | Port | Port | +--------+--------+--------+--------+ | | | | Length | Checksum | +--------+--------+--------+--------+ | | data octets ... +---------------- ...
- make(srcport=0, dstport=0, checksum=b'\\x00\\x00', total_length=None, payload=b'', trailer=b'', **kwargs)¶
Make (construct) packet data.
- Parameters:
checksum (
bytes) – Checksum.total_length (
int|None) – Length of the datagram, header included; computed from the header and the payload when omitted.payload (
bytes|Schema|ProtocolBase) – Payload data.trailer (
bytes) – Octets after the datagram, outside the Length field; written as is and not counted in a computedtotal_length.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- classmethod _make_data(data)¶
Create key-value pairs from
datafor protocol construction.
- __proto__: DefaultDict[int, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]¶
Protocol index mapping for decoding next layer, c.f.
self._decode_next_layer&self._import_next_layer.- Type:
DefaultDict[int, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]
Header Schemas¶
- class pcapkit.protocols.schema.transport.udp.UDP(*args: _VT, **kwargs: _VT)¶
Bases:
SchemaHeader schema for UDP packet.
- payload: bytes = <PayloadField payload>¶
Payload. A Length below the header’s own 8 octets leaves the length negative, which takes the rest of the datagram, as before.
- trailer: bytes = <PayloadField trailer>¶
Octets captured past the Length field, c.f.
IPv4.trailer.
Data Models¶
- class pcapkit.protocols.data.transport.udp.UDP(*args: VT, **kwargs: VT)¶
Bases:
ProtocolData model for UDP protocol.
Footnotes