IPv4 - Internet Protocol version 4¶
pcapkit.protocols.internet.ipv4
contains
IPv4
only,
which implements extractor for Internet Protocol
version 4 (IPv4) *, whose structure is described
as below:
Octets |
Bits |
Name |
Description |
---|---|---|---|
0 |
0 |
|
Version ( |
0 |
4 |
|
Internal Header Length (IHL) |
1 |
8 |
|
Differentiated Services Code Point (DSCP) |
1 |
14 |
|
Explicit Congestion Notification (ECN) |
2 |
16 |
|
Total Length |
4 |
32 |
|
Identification |
6 |
48 |
Reserved Bit (must be |
|
6 |
49 |
|
Don’t Fragment (DF) |
6 |
50 |
|
More Fragments (MF) |
6 |
51 |
|
Fragment Offset |
8 |
64 |
|
Time To Live (TTL) |
9 |
72 |
|
Protocol (Transport Layer) |
10 |
80 |
|
Header Checksum |
12 |
96 |
|
Source IP Address |
16 |
128 |
|
Destination IP Address |
20 |
160 |
|
IP Options (if IHL > |
- class pcapkit.protocols.internet.ipv4.IPv4(file=None, length=None, **kwargs)[source]¶
-
This class implements Internet Protocol version 4.
This class currently supports parsing of the following IPv4 options, which are directly mapped to the
pcapkit.const.ipv4.option_number.OptionNumber
enumeration:Option Code
Option Parser
ESEC
- Parameters
*args (Any) – Arbitrary positional arguments.
**kwargs (Any) – Arbitrary keyword arguments.
- Return type
Protocol[PT]
- property name: Literal['Internet Protocol version 4']¶
Name of corresponding protocol.
- Return type
Literal[“Internet Protocol version 4”]
- property src: IPv4Address¶
Source IP address.
- Return type
- property dst: IPv4Address¶
Destination IP address.
- Return type
- read(length=None, **kwargs)[source]¶
Read Internet Protocol version 4 (IPv4).
Structure of IPv4 header [RFC 791]:
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Version| IHL |Type of Service| Total Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Identification |Flags| Fragment Offset | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Time to Live | Protocol | Header Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Destination Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options | Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- classmethod id()[source]¶
Index ID of the protocol.
- Return type
tuple[Literal[“IPv4”]]
- Returns
Index ID of the protocol.
- _read_ipv4_opt_type(code)[source]¶
Read option type field.
- Parameters
code (
int
) – option kind value- Return type
- Returns
Extracted IPv4 option type, as an object of the option flag (copied flag), option class, and option number.
- _read_ipv4_options(length)[source]¶
Read IPv4 option list.
- Parameters
length (int) – length of options
- Return type
- Returns
Extracted IPv4 options.
- Raises
ProtocolError – If the threshold is NOT matching.
- _read_opt_unassigned(kind, *, options)[source]¶
Read IPv4 unassigned options.
Structure of IPv4 unassigned options [RFC 791]:
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | type | length | option data ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_UnassignedOption
- Returns
Parsed option data.
- Raises
ProtocolError – If
size
is LESS THAN3
.
- _read_opt_eool(kind, *, options)[source]¶
Read IPv4 End of Option List (
EOOL
) option.Structure of IPv4 End of Option List (
EOOL
) option [RFC 719]:+--------+ |00000000| +--------+ Type=0
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_EOOLOption
- Returns
Parsed option data.
- _read_opt_nop(kind, *, options)[source]¶
Read IPv4 No Operation (
NOP
) option.Structure of IPv4 No Operation (
NOP
) option [RFC 719]:+--------+ |00000001| +--------+ Type=1
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_NOPOption
- Returns
Parsed option data.
- _read_opt_sec(kind, *, options)[source]¶
Read IPv4 Security (
SEC
) option.Structure of IPv4 Security (
SEC
) option [RFC 1108]:+------------+------------+------------+-------------//----------+ | 10000010 | XXXXXXXX | SSSSSSSS | AAAAAAA[1] AAAAAAA0 | | | | | [0] | +------------+------------+------------+-------------//----------+ TYPE = 130 LENGTH CLASSIFICATION PROTECTION LEVEL AUTHORITY FLAGS
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_SECOption
- Returns
Parsed option data.
- Raises
ProtocolError – If
size
is LESS THAN3
.
- _read_opt_lsr(kind, *, options)[source]¶
Read IPv4 Loose Source Route (
LSR
) option.Structure of IPv4 Loose Source Route (
LSR
) option [RFC 791]:+--------+--------+--------+---------//--------+ |10000011| length | pointer| route data | +--------+--------+--------+---------//--------+
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_LSROption
- Returns
Parsed option data.
- Raises
ProtocolError – If option is malformed.
- _read_opt_ts(kind, *, options)[source]¶
Read IPv4 Time Stamp (
TS
) option.Structure of IPv4 Time Stamp (
TS
) option [RFC 791]:+--------+--------+--------+--------+ |01000100| length | pointer|oflw|flg| +--------+--------+--------+--------+ | internet address | +--------+--------+--------+--------+ | timestamp | +--------+--------+--------+--------+ | . | . .
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_TSOption
- Returns
Parsed option data.
- Raises
ProtocolError – If the option is malformed.
- _read_opt_esec(kind, *, options)[source]¶
Read IPv4 Extended Security (
ESEC
) option.Structure of IPv4 Extended Security (
ESEC
) option [RFC 1108]:+------------+------------+------------+-------//-------+ | 10000101 | 000LLLLL | AAAAAAAA | add sec info | +------------+------------+------------+-------//-------+ TYPE = 133 LENGTH ADDITIONAL ADDITIONAL SECURITY INFO SECURITY FORMAT CODE INFO
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_ESECOption
- Returns
Parsed option data.
- Raises
ProtocolError – If
size
is LESS THAN3
.
- _read_opt_rr(kind, *, options)[source]¶
Read IPv4 Record Route (
RR
) option.Structure of IPv4 Record Route (
RR
) option [RFC 791]:+--------+--------+--------+---------//--------+ |00000111| length | pointer| route data | +--------+--------+--------+---------//--------+ Type=7
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_RROption
- Returns
Parsed option data.
- Raises
ProtocolError – If option is malformed.
- _read_opt_sid(kind, *, options)[source]¶
Read IPv4 Stream ID (
SID
) option.Structure of IPv4 Stream ID (
SID
) option [RFC 791][RFC 6814]:+--------+--------+--------+--------+ |10001000|00000010| Stream ID | +--------+--------+--------+--------+ Type=136 Length=4
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_SIDOption
- Returns
Parsed option data.
- Raises
ProtocolError – If
size
is NOT4
.
- _read_opt_ssr(kind, *, options)[source]¶
Read IPv4 Strict Source Route (
SSR
) option.Structure of IPv4 Strict Source Route (
SSR
) option [RFC 791]:+--------+--------+--------+---------//--------+ |10001001| length | pointer| route data | +--------+--------+--------+---------//--------+ Type=137
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_SSROption
- Returns
Parsed option data.
- Raises
ProtocolError – If option is malformed.
- _read_opt_mtup(kind, *, options)[source]¶
Read IPv4 MTU Probe (
MTUP
) option.Structure of IPv4 MTU Probe (
MTUP
) option [RFC 1063][RFC 1191]:+--------+--------+--------+--------+ |00001011|00000100| 2 octet value | +--------+--------+--------+--------+
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_MTUPOption
- Returns
Parsed option data.
- Raises
ProtocolError – If
size
is NOT4
.
- _read_opt_mtur(kind, *, options)[source]¶
Read IPv4 MTU Reply (
MTUR
) option.Structure of IPv4 MTU Reply (
MTUR
) option [RFC 1063][RFC 1191]:+--------+--------+--------+--------+ |00001100|00000100| 2 octet value | +--------+--------+--------+--------+
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_MTUROption
- Returns
Parsed option data.
- Raises
ProtocolError – If
size
is NOT4
.
- _read_opt_tr(kind, *, options)[source]¶
Read IPv4 Traceroute (
TR
) option.Structure of IPv4 Traceroute (
TR
) option [RFC 1393][RFC 6814]:0 8 16 24 +-+-+-+-+-+-+-+-+---------------+---------------+---------------+ |F| C | Number | Length | ID Number | +-+-+-+-+-+-+-+-+---------------+---------------+---------------+ | Outbound Hop Count | Return Hop Count | +---------------+---------------+---------------+---------------+ | Originator IP Address | +---------------+---------------+---------------+---------------+
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_TROption
- Returns
Parsed option data.
- Raises
ProtocolError – If
size
is NOT12
.
- _read_opt_rtralt(kind, *, options)[source]¶
Read IPv4 Router Alert (
RTRALT
) option.Structure of IPv4 Router Alert (
RTRALT
) option [RFC 2113]:+--------+--------+--------+--------+ |10010100|00000100| 2 octet value | +--------+--------+--------+--------+
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_RTRALTOption
- Returns
Parsed option data.
- Raises
ProtocolError – If
size
is NOT4
.
- _read_opt_qs(kind, *, options)[source]¶
Read IPv4 Quick Start (
QS
) option.Structure of IPv4 Quick Start (
QS
) option [RFC 4782]:A Quick-Start Request
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Option | Length=8 | Func. | Rate | QS TTL | | | | 0000 |Request| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | QS Nonce | R | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Report of Approved Rate
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Option | Length=8 | Func. | Rate | Not Used | | | | 1000 | Report| | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | QS Nonce | R | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Parameters
kind (RegType_OptionNumber) – option type code
options (Option) – extracted IPv4 options
- Return type
DataType_QSOption
- Returns
Parsed option data.
- Raises
ProtocolError – If the option is malformed.
Data Structures¶
- class pcapkit.protocols.data.internet.ipv4.IPv4(version, hdr_len, tos, len, id, flags, offset, ttl, protocol, checksum, src, dst)[source]¶
Bases:
Info
Data model for IPv4 packet.
- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- version: Literal[4]¶
Version.
- ttl: timedelta¶
Time to live.
- src: IPv4Address¶
Source address.
- dst: IPv4Address¶
Destination address.
- options: OrderedMultiDict[OptionNumber, Option]¶
- class pcapkit.protocols.data.internet.ipv4.ToSField(pre, del, thr, rel, ecn)[source]¶
Bases:
Info
Data model for IPv4 ToS fields.
Important
Due to the preserved keyword conflict, please use
from_dict()
to create an instance of this data model.- Parameters
*args (Any) – Arbitrary positional arguments.
**kwargs (Any) – Arbitrary keyword arguments.
- Return type
- pre: ToSPrecedence¶
Precedence.
- thr: ToSThroughput¶
Throughput.
- rel: ToSReliability¶
Reliability.
- class pcapkit.protocols.data.internet.ipv4.Flags(df, mf)[source]¶
Bases:
Info
Data model for IPv4 Flags.
- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- class pcapkit.protocols.data.internet.ipv4.Option(code, length, type)[source]¶
Bases:
Info
Data model for IPv4 options.
- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- code: OptionNumber¶
Option code.
- type: OptionType¶
Option type.
- class pcapkit.protocols.data.internet.ipv4.OptionType(change, class, number)[source]¶
Bases:
Info
Data model for IPv4 option type data.
- Parameters
*args (Any) – Arbitrary positional arguments.
**kwargs (Any) – Arbitrary keyword arguments.
- Return type
- class: OptionClass¶
Option class.
- class pcapkit.protocols.data.internet.ipv4.UnassignedOption(code, length, type, data)[source]¶
Bases:
Option
Data model for IPv4 unassigned option.
- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- class pcapkit.protocols.data.internet.ipv4.EOOLOption(code, length, type)[source]¶
Bases:
Option
Data model for IPv4 End of Option List (
EOOL
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- class pcapkit.protocols.data.internet.ipv4.NOPOption(code, length, type)[source]¶
Bases:
Option
Data model for IPv4 No Operation (
NOP
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- class pcapkit.protocols.data.internet.ipv4.SECOption(code, length, type, level, flags)[source]¶
Bases:
Option
Data model for IPv4 Security (
SEC
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- level: ClassificationLevel¶
Classification level.
- flags: Optional[OrderedMultiDict[ProtectionAuthority, bool]]¶
Protection authority flags.
- class pcapkit.protocols.data.internet.ipv4.LSROption(code, length, type, pointer, route)[source]¶
Bases:
Option
Data model for IPv4 Loose Source Route (
LSR
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- class pcapkit.protocols.data.internet.ipv4.TSOption(code, length, type, pointer, overflow, flag, timestamp)[source]¶
Bases:
Option
Data model for IPv4 Time Stamp (
TS
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- timestamp: Optional[bytes | tuple[dt_type, ...] | OrderedMultiDict[IPv4Address, dt_type]]¶
Timestamp data.
- class pcapkit.protocols.data.internet.ipv4.ESECOption(code, length, type, level, flags)[source]¶
Bases:
Option
Data model for IPv4 Extended Security (
ESEC
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- level: ClassificationLevel¶
Classification level.
- flags: Optional[OrderedMultiDict[ProtectionAuthority, bool]]¶
Protection authority flags.
- class pcapkit.protocols.data.internet.ipv4.RROption(code, length, type, pointer, route)[source]¶
Bases:
Option
Data model for IPv4 Record Route (
RR
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- class pcapkit.protocols.data.internet.ipv4.SIDOption(code, length, type, sid)[source]¶
Bases:
Option
Data model for IPv4 Stream ID (
SID
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- class pcapkit.protocols.data.internet.ipv4.SSROption(code, length, type, pointer, route)[source]¶
Bases:
Option
Data model for IPv4 Strict Source Route (
SSR
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- class pcapkit.protocols.data.internet.ipv4.MTUPOption(code, length, type, mtu)[source]¶
Bases:
Option
Data model for IPv4 MTU Probe (
MTUP
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- class pcapkit.protocols.data.internet.ipv4.MTUROption(code, length, type, mtu)[source]¶
Bases:
Option
Data model for IPv4 MTU Reply (
MTUR
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- class pcapkit.protocols.data.internet.ipv4.TROption(code, length, type, id, outbound, return, originator)[source]¶
Bases:
Option
Data model for IPv4 Traceroute (
TR
) option.Important
Due to the preserved keyword conflict, please use
from_dict()
to create an instance of this data model.- Parameters
*args (Any) – Arbitrary positional arguments.
**kwargs (Any) – Arbitrary keyword arguments.
- Return type
- originator: IPv4Address¶
- class pcapkit.protocols.data.internet.ipv4.RTRALTOption(code, length, type, alert)[source]¶
Bases:
Option
Data model for IPv4 Router Alert (
RTRALT
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- alert: RouterAlert¶
Router alert.
- class pcapkit.protocols.data.internet.ipv4.QSOption(code, length, type, func, rate, ttl, nounce)[source]¶
Bases:
Option
Data model for IPv4 Quick Start (
QS
) option.- Parameters
*args (VT) – Arbitrary positional arguments.
**kwargs (VT) – Arbitrary keyword arguments.
- Return type
- func: QSFunction¶
QS function.
- ttl: Optional[timedelta]¶
TTL.