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]¶ Bases:
pcapkit.protocols.internet.ip.IPThis class implements Internet Protocol version 4.
-
classmethod
__index__()[source]¶ Numeral registry index of the protocol.
- Returns
Numeral registry index of the protocol in IANA.
- Return type
-
_read_ipv4_options(size=None)[source]¶ Read IPv4 option list.
- Parameters
size (Optional[int]) – buffer size
- Returns
Tuple[Tuple[pcapkit.const.ipv4.option_number.OptionNumber], Dict[str, Union[DataType_Opt, Tuple[DataType_Opt]]]]: IPv4 option list and extracted IPv4 options
-
_read_mode_donone(size, kind)[source]¶ Read options require no process.
- Parameters
- Returns
extracted option
- Return type
- Raises
ProtocolError – If
sizeis LESS THAN3.
-
_read_mode_qs(size, kind)[source]¶ Read Quick Start option.
Structure of 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
size (int) – length of option
kind (Literal[25]) – option kind value (QS)
- Returns
extracted Quick Start option
- Return type
- Raises
ProtocolError – If the option is malformed.
-
_read_mode_route(size, kind)[source]¶ Read options with route data.
Structure of these options [RFC 791]:
Loose Source Route
+--------+--------+--------+---------//--------+ |10000011| length | pointer| route data | +--------+--------+--------+---------//--------+
Strict Source Route
+--------+--------+--------+---------//--------+ |10001001| length | pointer| route data | +--------+--------+--------+---------//--------+
Record Route
+--------+--------+--------+---------//--------+ |00000111| length | pointer| route data | +--------+--------+--------+---------//--------+
- Parameters
size (int) – length of option
kind (Literal[7, 131, 137]) – option kind value (RR/LSR/SSR)
- Returns
extracted option with route data
- Return type
- Raises
ProtocolError – If the option is malformed.
-
_read_mode_rsralt(size, kind)[source]¶ Read Router Alert option.
Structure of Router Alert (RTRALT) option [RFC 2113]:
+--------+--------+--------+--------+ |10010100|00000100| 2 octet value | +--------+--------+--------+--------+
- Parameters
size (int) – length of option
kind (Literal[140]) – option kind value (RTRALT)
- Returns
extracted option with security info
- Return type
- Raises
ProtocolError – If
sizeis NOT4.
-
_read_mode_sec(size, kind)[source]¶ Read options with security info.
Structure of these options [RFC 1108]:
Security (SEC)
+------------+------------+------------+-------------//----------+ | 10000010 | XXXXXXXX | SSSSSSSS | AAAAAAA[1] AAAAAAA0 | | | | | [0] | +------------+------------+------------+-------------//----------+ TYPE = 130 LENGTH CLASSIFICATION PROTECTION LEVEL AUTHORITY FLAGSExtended Security (ESEC)
+------------+------------+------------+-------//-------+ | 10000101 | 000LLLLL | AAAAAAAA | add sec info | +------------+------------+------------+-------//-------+ TYPE = 133 LENGTH ADDITIONAL ADDITIONAL SECURITY INFO SECURITY FORMAT CODE INFO
c
-
_read_mode_tr(size, kind)[source]¶ Read Traceroute option.
Structure of Traceroute (TR) option [RFC 6814]:
0 8 16 24 +-+-+-+-+-+-+-+-+---------------+---------------+---------------+ |F| C | Number | Length | ID Number | +-+-+-+-+-+-+-+-+---------------+---------------+---------------+ | Outbound Hop Count | Return Hop Count | +---------------+---------------+---------------+---------------+ | Originator IP Address | +---------------+---------------+---------------+---------------+
- Parameters
size (int) – length of option
kind (Literal[82]) – option kind value (TR)
- Returns
extracted Traceroute option
- Return type
- Raises
ProtocolError – If
sizeis NOT12.
-
_read_mode_ts(size, kind)[source]¶ Read Time Stamp option.
Structure of Timestamp (TS) option [RFC 791]:
+--------+--------+--------+--------+ |01000100| length | pointer|oflw|flg| +--------+--------+--------+--------+ | internet address | +--------+--------+--------+--------+ | timestamp | +--------+--------+--------+--------+ | . | . .
- Parameters
size (int) – length of option
kind (Literal[68]) – option kind value (TS)
- Returns
extracted Time Stamp option
- Return type
- Raises
ProtocolError – If the option is malformed.
-
_read_mode_unpack(size, kind)[source]¶ Read options require unpack process.
- Parameters
- Returns
extracted option
- Return type
- Raises
ProtocolError – If
sizeis LESS THAN3.
-
_read_opt_type(kind)[source]¶ Read option type field.
- Parameters
kind (int) – option kind value
- Returns
extracted IPv4 option
- Return type
-
classmethod
id()[source]¶ Index ID of the protocol.
- Returns
Index ID of the protocol.
- Return type
Literal[‘IPv4’]
-
make(**kwargs)[source]¶ Make (construct) packet data.
- Keyword Arguments
**kwargs – Arbitrary keyword arguments.
- Returns
Constructed packet data.
- 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 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Parameters
length (Optional[int]) – Length of packet data.
- Keyword Arguments
**kwargs – Arbitrary keyword arguments.
- Returns
Parsed packet data.
- Return type
-
property
name¶ Name of corresponding protocol.
- Return type
Literal[‘Internet Protocol version 4’]
-
property
protocol¶ Name of next layer protocol.
- Return type
-
classmethod
-
pcapkit.protocols.internet.ipv4.IPv4_OPT: DataType_IPv4_OPT¶ IPv4 option
dictparsing mapping.copy
class
number
kind
length
process
name
0
0
0
0
[RFC 791] End of Option List
0
0
1
1
[RFC 791] No-Operation
0
0
7
7
?
2
[RFC 791] Record Route
0
0
11
11
4
1
0
0
12
12
4
1
0
0
25
25
8
3
[RFC 4782] Quick-Start
0
2
4
68
?
4
[RFC 791] Time Stamp
0
2
18
82
?
5
1
0
2
130
?
6
[RFC 1108] Security
1
0
3
131
?
2
[RFC 791] Loose Source Route
1
0
5
133
?
6
[RFC 1108] Extended Security
1
0
8
136
4
1
1
0
9
137
?
2
[RFC 791] Strict Source Route
1
0
17
145
?
0
1
0
20
148
4
7
[RFC 2113] Router Alert
-
pcapkit.protocols.internet.ipv4.process_opt: Dict[int, Callable[[pcapkit.protocols.internet.ipv4.IPv4, int, int], DataType_Opt]]¶ Process method for IPv4 options.
Code
Method
Description
0
do nothing
1
unpack according to size
2
unpack route data options
3
unpack Quick-Start
4
unpack Time Stamp
5
unpack Traceroute
6
unpack (Extended) Security
7
unpack Router Alert
Data Structure¶
Important
Following classes are only for documentation purpose.
They do NOT exist in the pcapkit module.
-
class
pcapkit.protocols.internet.ipv4.DataType_IPv4¶ - Bases
TypedDict
Structure of IPv4 header [RFC 791].
-
version: Literal[4]¶ Version (
4).
-
dsfield: DataType_DS_Field¶ Type of services.
-
flags: DataType_IPv4_Flags¶ Flags.
-
proto: pcapkit.const.reg.transtype.TransType¶ Protocol (transport layer).
-
src: ipaddress.IPv4Address¶ Source IP address.
-
dst: ipaddress.IPv4Address¶ Destination IP address.
-
opt: Tuple[pcapkit.const.ipv4.option_number.OptionNumber]¶ Tuple of option acronyms.
-
class
pcapkit.protocols.internet.ipv4.DataType_DS_Field¶ - Bases
TypedDict
IPv4 DS fields.
-
dscp: DataType_IPv4_DSCP¶ Differentiated services code point (DSCP).
-
ecn: pcapkit.const.ipv4.tos_ecn.ToSECN¶ Explicit congestion notification (ECN).
-
class
pcapkit.protocols.internet.ipv4.DataType_IPv4_DSCP¶ - Bases
TypedDict
Differentiated services code point (DSCP).
-
pre: pcapkit.const.ipv4.tos_pre.ToSPrecedence¶ ToS precedence.
-
del: pcapkit.const.ipv4.tos_del.ToSDelay¶ ToS delay.
-
thr: pcapkit.const.ipv4.tos_thr.ToSThroughput¶ ToS throughput.
-
rel: pcapkit.const.ipv4.tos_rel.ToSReliability¶ ToS reliability.
-
class
pcapkit.protocols.internet.ipv4.DataType_IPv4_Flags¶ - Bases
TypedDict
IPv4 flags.
-
class
pcapkit.protocols.internet.ipv4.DataType_Opt¶ - Bases
TypedDict
IPv4 option data.
-
type: DataType_IPv4_Option_Type¶ Option type info.
-
class
pcapkit.protocols.internet.ipv4.DataType_IPv4_OPT¶ - Bases
TypedDict
IPv4 option
dictparsing mapping.
IPv4 Option Type¶
For IPv4 option type field as described in RFC 791, its structure is described as below:
Octets |
Bits |
Name |
Descriptions |
|---|---|---|---|
0 |
0 |
|
Copied Flag ( |
0 |
1 |
|
Option Class ( |
0 |
3 |
|
Option Number |
IPv4 Miscellaneous Options¶
1-Byte Options¶
Permission Options¶
No Process Options¶
For IPv4 options require no process, its structure is described as below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Kind |
0 |
0 |
|
Copied Flag |
0 |
1 |
|
Option Class |
0 |
3 |
|
Option Number |
1 |
8 |
|
Length |
2 |
16 |
|
Kind-specific Data |
Unpack Process Options¶
For IPv4 options require unpack process, its structure is described as below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Kind |
0 |
0 |
|
Copied Flag |
0 |
1 |
|
Option Class |
0 |
3 |
|
Option Number |
1 |
8 |
|
Length |
2 |
16 |
|
Kind-specific Data |
IPv4 Options with Route Data¶
For IPv4 options with route data as described in RFC 791, its structure is described as below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Kind ( |
0 |
0 |
|
Copied Flag ( |
0 |
1 |
|
Option Class ( |
0 |
3 |
|
Option Number ( |
1 |
8 |
|
Length |
2 |
16 |
|
Pointer ( |
3 |
24 |
|
Route Data |
IPv4 Quick Start Options¶
For IPv4 Quick Start options as described in RFC 4782, its structure is described as below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Kind ( |
0 |
0 |
|
Copied Flag ( |
0 |
1 |
|
Option Class ( |
0 |
3 |
|
Option Number ( |
1 |
8 |
|
Length ( |
2 |
16 |
|
Function ( |
2 |
20 |
|
Rate Request / Report (in Kbps) |
3 |
24 |
|
QS TTL / |
4 |
32 |
|
QS Nounce |
7 |
62 |
Reserved ( |
IPv4 Time Stamp Option¶
For IPv4 Time Stamp option as described in RFC 791, its structure is described as below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Kind ( |
0 |
0 |
|
Copied Flag ( |
0 |
1 |
|
Option Class ( |
0 |
3 |
|
Option Number ( |
1 |
8 |
|
Length ( |
2 |
16 |
|
Pointer ( |
3 |
24 |
|
Overflow Octets |
3 |
28 |
|
Flag |
4 |
32 |
|
Internet Address |
8 |
64 |
|
Timestamp |
-
class
pcapkit.protocols.internet.ipv4.DataType_Opt_TimeStamp¶ - Bases
DataType_Opt
Structure of Timestamp (TS) option [RFC 791].
-
ip: Optional[Tuple[ipaddress.IPv4Address]]¶ Array of Internet addresses (if
flagis1/3).
-
timestamp: Optional[Tuple[datetime.datetime]]¶ Array of timestamps (if
flagis0/1/3).
IPv4 Traceroute Option¶
For IPv4 Traceroute option as described in RFC 6814, its structure is described as below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
ip.tr.kind |
Kind (82) |
0 |
0 |
ip.tr.type.copy |
Copied Flag (0) |
0 |
1 |
ip.tr.type.class |
Option Class (0) |
0 |
3 |
ip.tr.type.number |
Option Number (18) |
1 |
8 |
ip.tr.length |
Length (12) |
2 |
16 |
ip.tr.id |
ID Number |
4 |
32 |
ip.tr.ohc |
Outbound Hop Count |
6 |
48 |
ip.tr.rhc |
Return Hop Count |
8 |
64 |
ip.tr.ip |
Originator IP Address |
IPv4 Options with Security Info¶
For IPv4 options with security info as described in RFC 1108, its structure is described as below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Kind ( |
0 |
0 |
|
Copied Flag ( |
0 |
1 |
|
Option Class ( |
0 |
3 |
|
Option Number ( |
1 |
8 |
|
Length ( |
2 |
16 |
|
Classification Level |
3 |
24 |
|
Protection Authority Flags |
-
class
pcapkit.protocols.internet.ipv4.DataType_Opt_Security_Info¶ - Bases
DataType_Opt
Structure of IPv4 options with security info [RFC 791].
-
level: pcapkit.const.ipv4.classification_level.ClassificationLevel¶ Classification level.
-
flags: Tuple[DataType_SEC_Flags]¶ Array of protection authority flags.
-
class
pcapkit.protocols.internet.ipv4.DataType_SEC_Flags¶ - Bases
pcapkit.corekit.infoclass.Info
Protection authority flags, as mapping of protection authority bit assignments
enumerationandboolflags.
IPv4 Traceroute Option¶
For IPv4 Router Alert option as described in RFC 2113, its structure is described as below:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Kind ( |
0 |
0 |
|
Copied Flag ( |
0 |
1 |
|
Option Class ( |
0 |
3 |
|
Option Number ( |
1 |
8 |
|
Length ( |
2 |
16 |
|
Alert |
2 |
16 |
|
Alert Code |
-
class
pcapkit.protocols.internet.ipv4.DataType_Opt_RouterAlert¶ - Bases
DataType_Opt
Structure of Router Alert (RTRALT) option [RFC 2113].
-
alert: pcapkit.const.ipv4.router_alert.RouterAlert¶ Alert.