UDP - User Datagram Protocol¶
pcapkit.protocols.transport.udp.protocol contains
UDP only,
which implements the extractor for User Datagram Protocol
(UDP) [*], whose structure is:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Source Port |
2 |
16 |
|
Destination Port |
4 |
32 |
|
Length (header included) |
6 |
48 |
|
Checksum |
- class pcapkit.protocols.transport.udp.protocol.UDP(file=None, length=None, **kwargs)[source]¶
-
This class implements User Datagram Protocol.
The
self.__proto__registry binds these ports:Port Number
Protocol
80
1701
5684
8080
Note
HTTP, bound as inTCP.__proto__, picksHTTPv1orHTTPv2from the payload through_dispatch_version().Changed in version 1.5.0:
make()takestotal_length, which afrom_data()rebuild passes so that a truncated capture keeps its declared Length (#1155), andtrailer, so that the octets past the Length field rebuild as captured (#1461).Changed in version 1.6.0:
The checksum is computed when
make()is given none, over thepseudoit is given or by the enclosing IP layer, and verified by that layer underCHECKSUM_VERIFY(#2474).make()raisesProtocolErrorfor a Length past 16 bits, given or computed, and a checksum that is not two octets, where it wrote the Length’s low 16 bits and padded or cut the checksum (#2614).
- __proto__: DefaultDict[int, ModuleDescriptor[ProtocolBase] | Type[ProtocolBase]]¶
Protocol index mapping for decoding next layer, see
self._decode_next_layer&self._import_next_layer.
- __proto_key__: ClassVar[tuple[Type[EnumRegistry], bool]]¶
What
__proto__is keyed by – the enum a key must be a member of, and whether a bareintis valid too. Read byregister_protocol_code()to check acode=key asregister_udp()checks its own; a bareintis a port number, which anAppTypemember carries (#2268).
- read(length=None, **kwargs)[source]¶
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=None, total_length=None, payload=b'', trailer=b'', pseudo=None, **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
checksum (
bytes|None) – Checksum; ifNoneandCHECKSUM_COMPUTEis on, computed overpseudo(RFC 768), or left to an IP layer this datagram is the payload of; zero, i.e. none, otherwise.total_length (
int|None) – Length of the datagram, header included; computed from the header and the payload when omitted. A jumbogram’s is given as zero (RFC 2675 Section 4).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.pseudo (
IP_Pseudo|None) – Pseudo-header of the enclosing IP layer; its length is replaced bytotal_length, as the Length field gives it.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
srcportordstportis abool(#2287),total_length, given or computed, does not fit 16 bits, orchecksumis not two octets.
Changed in version 1.5.0: An out-of-range
srcportordstportraisesValueErrorrather than being accepted (#758).total_lengthsits beforepayload(#1155), so a caller passingpayloadpositionally setstotal_lengthinstead.
- _verify_pseudo_checksum(pseudo)[source]¶
Verify the checksum over the pseudo-header of the enclosing IP layer.
That layer calls this once parsed, see
verify_upper(). A zero checksum over IPv4, which means none (RFC 768), and the pseudo-header’s sum alone, which checksum offload leaves on the sending host, areNOT_COMPUTED. A zero one over IPv6 is wrong, as one is mandatory there (RFC 8200 Section 8.1).
Header Schemas¶
Removed in version 1.6.0: pcapkit.protocols.schema.transport.udp, with no alias: the module moved here
(#2534).
- class pcapkit.protocols.transport.udp.schema.UDP(srcport=NO_VALUE, dstport=NO_VALUE, len=NO_VALUE, checksum=NO_VALUE, payload=NO_VALUE, trailer=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
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.
- trailer: bytes = <PayloadField trailer>¶
Octets captured past the Length field, see
IPv4.trailer.
Data Models¶
Removed in version 1.6.0: pcapkit.protocols.data.transport.udp, with no alias: the module moved here
(#2534).
- class pcapkit.protocols.transport.udp.data.UDP(srcport, dstport, len, checksum)[source]¶
Bases:
ProtocolData model for UDP protocol.
- checksum_status: ChecksumStatus¶
Outcome of verifying
checksum, present only when the enclosing IP layer verified it underCHECKSUM_VERIFY.
Footnotes