DHCPv4 - Dynamic Host Configuration Protocol¶
pcapkit.protocols.application.dhcpv4.protocol holds
DHCPv4, the extractor for
Dynamic Host Configuration Protocol (DHCP) messages [RFC 2131], laid out as
protocol gives. Its last field,
options, opens with the magic cookie, and the sname and file fields
hold options too where the Option Overload option says so
(RFC 2131 Section 4.1).
Added in version 1.10.0.
- class pcapkit.protocols.application.dhcpv4.protocol.DHCPv4(file, length=None, /, *, layer=None, protocol=None, context=None)[source]¶
-
This class implements the Dynamic Host Configuration Protocol.
A message is a DHCP one where its options carry the DHCP Message Type option (RFC 2131 Section 3), so this class refuses one without it, on both paths;
BOOTPreads it. Its options decode asDHCPgives, in theoptionsfield, then in thefileandsnamefields the Option Overload option there overloads, in that order, which is also the order an option carried more than once has its instances concatenated in (RFC 3396 Section 7).Added in version 1.10.0.
Properties
- property message_type: MessageType | None¶
DHCP message type, or
Nonewhere its option keeps its octets.
Methods
- read(length=None, **kwargs)[source]¶
Read Dynamic Host Configuration Protocol.
Structure of a DHCP message [RFC 2131 Section 2]:
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 +---------------+---------------+---------------+---------------+ | op (1) | htype (1) | hlen (1) | hops (1) | +---------------+---------------+---------------+---------------+ | xid (4) | +-------------------------------+-------------------------------+ | secs (2) | flags (2) | +-------------------------------+-------------------------------+ | ciaddr (4) | +---------------------------------------------------------------+ | yiaddr (4) | +---------------------------------------------------------------+ | siaddr (4) | +---------------------------------------------------------------+ | giaddr (4) | +---------------------------------------------------------------+ | chaddr (16) | +---------------------------------------------------------------+ | sname (64) | +---------------------------------------------------------------+ | file (128) | +---------------------------------------------------------------+ | options (variable) | +---------------------------------------------------------------+
An option that runs past its field, as a capture cut leaves one, keeps its octets as the field’s padding, and the options field records the cut as its header schema would. An option carried more than once is cut short where one of its instances runs past its field, so it keeps its octets, as one carried once does.
- Parameters:
- Return type:
- Returns:
Parsed packet data.
- Raises:
ProtocolError – If no magic cookie opens the options field, or the options carry no DHCP Message Type option whole before any option runs past its field.
- make(*, op=Opcode.BOOTREQUEST, htype=Hardware.Ethernet, hlen=None, hops=0, xid=0, secs=0, flags=0, ciaddr='0.0.0.0', yiaddr='0.0.0.0', siaddr='0.0.0.0', giaddr='0.0.0.0', chaddr=b'', chaddr_padding=None, sname=b'', file=b'', options=(), padding=b'', payload=b'', **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
hlen (
int|None) – Hardware address length; that ofchaddrifNone.hops (
int) – Hops.xid (
int) – Transaction ID.secs (
int) – Seconds elapsed since the client began.flags (
Mapping[str,Any] |int) – Flags, as their data model or a mapping of its keys, or the two octets as an integer.ciaddr (
IPv4Address|str|bytes|int) – Client IP address.yiaddr (
IPv4Address|str|bytes|int) – Your (client) IP address.siaddr (
IPv4Address|str|bytes|int) – Next server IP address.giaddr (
IPv4Address|str|bytes|int) – Relay agent IP address.chaddr (
str|bytes) – Client hardware address: a MAC address for an Ethernet or IEEE 802 type, or its octets.chaddr_padding (
bytes|None) – Octets ofchaddrafter the address; zeros filling the field ifNone.sname (
bytes|Mapping[str,Any]) – Server host name, which NULs fill out, or the options it holds, asOverloadedFieldholds them.file (
bytes|Mapping[str,Any]) – Boot file name, which NULs fill out, or the options it holds, likewise.options (
Iterable[Mapping[str,Any]]) – Options, each a mapping asOptionholds it, written after the magic cookie.padding (
bytes) – Octets after the End option, or with none, the option the field ends inside.payload (
bytes|ProtocolBase|Schema) – Octets after the message.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If a field does not fit its width; if an option is malformed, or given as fields where the options,
fileandsnamehold its code more than once (RFC 3396 Section 7); ifsnameorfileholds options where the Option Overload option does not say so, or text where it does; or if the options carry no DHCP Message Type option.
Utilities
Data Models¶
- class pcapkit.protocols.application.dhcpv4.data.DHCPv4(op, htype, hlen, hops, xid, secs, flags, ciaddr, yiaddr, siaddr, giaddr, chaddr, chaddr_padding, sname, file, magic_cookie, options, padding, split_options)[source]¶
Bases:
ProtocolData model for a DHCP message (RFC 2131 Section 2).
- ciaddr: IPv4Address¶
Client IP address.
- yiaddr: IPv4Address¶
Your (client) IP address.
- siaddr: IPv4Address¶
Next server IP address.
- giaddr: IPv4Address¶
Relay agent IP address.
- chaddr: str | bytes¶
Client hardware address, its first
hlenoctets; a MAC address for an Ethernet or IEEE 802 type of six octets.
- sname: bytes | OverloadedField¶
Server host name, its trailing NULs removed, or the options it holds where the Option Overload option says so.
- file: bytes | OverloadedField¶
Boot file name, its trailing NULs removed, or the options it holds where the Option Overload option says so.
- split_options: tuple[SplitOption, ...]¶
Options the message carries more than once, each its instances in
options,fileandsnameconcatenated in that order (RFC 3396 Section 7), in the order their first instances appear.