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

udp.srcport

Source Port

2

16

udp.dstport

Destination Port

4

32

udp.len

Length (header includes)

6

48

udp.checksum

Checksum


class pcapkit.protocols.transport.udp.UDP(file=None, length=None, **kwargs)[source]

Bases: pcapkit.protocols.transport.transport.Transport

This class implements User Datagram Protocol.

classmethod __index__()[source]

Numeral registry index of the protocol.

Returns

Numeral registry index of the protocol in IANA.

Return type

pcapkit.const.reg.transtype.TransType

__length_hint__()[source]

Return an estimated length for the object.

Return type

Literal[8]

make(**kwargs)[source]

Make (construct) packet data.

Keyword Arguments

**kwargs – Arbitrary keyword arguments.

Returns

Constructed packet data.

Return type

bytes

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 ...
+---------------- ...
Parameters

length (Optional[int]) – Length of packet data.

Keyword Arguments

**kwargs – Arbitrary keyword arguments.

Returns

Parsed packet data.

Return type

DataType_UDP

property dst

Destination port.

Return type

int

property length

Header length of current protocol.

Return type

Literal[8]

property name

Name of current protocol.

Return type

Literal[‘User Datagram Protocol’]

property src

Source port.

Return type

int

Data Structure

Important

Following classes are only for documentation purpose. They do NOT exist in the pcapkit module.

class pcapkit.protocols.transport.udp.DataType_UDP
Bases

TypedDict

Structure of UDP header [RFC 768].

srcport: int

Source port.

dstport: int

Destination port.

len: int

Length.

checksum: bytes

Checksum.


*

https://en.wikipedia.org/wiki/User_Datagram_Protocol