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)#

Bases: Transport[UDP, UDP]

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

pcapkit.protocols.application.http.HTTP

Parameters:
  • *args (Any) – Arbitrary positional arguments.

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

Return type:

Self

property name: Literal['User Datagram Protocol']#

Name of current protocol.

property length: Literal[8]#

Header length of current protocol.

property src: int#

Source port.

property dst: int#

Destination port.

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 ...
+---------------- ...
Parameters:
  • length (Optional[int]) – Length of packet data.

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

Return type:

UDP

Returns:

Parsed packet data.

make(srcport=0, dstport=0, checksum=b'\\x00\\x00', payload=b'', **kwargs)#

Make (construct) packet data.

Parameters:
  • srcport (int) – Source port.

  • dstport (int) – Destination port.

  • checksum (bytes) – Checksum.

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

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

Return type:

UDP

Returns:

Constructed packet data.

classmethod _make_data(data)#

Create key-value pairs from data for protocol construction.

Parameters:

data (UDP) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

__proto__: DefaultDict[int, tuple[str, str]]#

Protocol index mapping for decoding next layer, c.f. self._decode_next_layer & self._import_next_layer.

Type:

DefaultDict[int, tuple[str, str]]

classmethod __index__()#

Numeral registry index of the protocol.

Return type:

TransType

Returns:

Numeral registry index of the protocol in IANA.

Header Schemas#

class pcapkit.protocols.schema.transport.udp.UDP(dict_=None, **kwargs)#

Bases: Schema

Header schema for UDP packet.

Parameters:
  • *args (VT) – Arbitrary positional arguments.

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

Return type:

Self

srcport: int = <UInt16Field srcport>#

Source port.

Parameters:

packet (dict[str, Any]) –

Return type:

Self

dstport: int = <UInt16Field dstport>#

Destination port.

Parameters:

packet (dict[str, Any]) –

Return type:

Self

len: int = <UInt16Field len>#

Length of UDP packet.

Parameters:

packet (dict[str, Any]) –

Return type:

Self

checksum: bytes = <BytesField checksum>#

Checksum of UDP packet.

Parameters:

packet (dict[str, Any]) –

Return type:

Self

payload: bytes = <PayloadField payload>#

Payload.

Parameters:

packet (dict[str, Any]) –

Return type:

Self

Data Models#

class pcapkit.protocols.data.transport.udp.UDP(*args, **kwargs)#

Bases: Data

Data model for UDP protocol.

Parameters:
  • *args – Arbitrary positional arguments.

  • **kwargs – Arbitrary keyword arguments.

srcport: int#

Source port.

dstport: int#

Destination port.

len: int#

Length (header includes).

checksum: bytes#

Checksum.