This repository has been archived by the owner on Oct 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathipv4.rflx
69 lines (62 loc) · 2.43 KB
/
ipv4.rflx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
with Protocol_Numbers;
package IPv4 is
type Version is range 4 .. 4 with Size => 4;
type IHL is range 5 .. 15 with Size => 4;
type DCSP is mod 2 ** 6;
type ECN is mod 2 ** 2;
type Total_Length is mod 2 ** 16;
type Identification is mod 2 ** 16;
type Fragment_Offset is mod 2 ** 13;
type TTL is mod 2 ** 8;
type Header_Checksum is mod 2 ** 16;
type Address is mod 2 ** 32;
type Option_Class is (CONTROL => 0, DEBUGGING_AND_MEASUREMENT => 2) with Size => 2;
type Option_Number is mod 2 ** 5;
type Option_Length is range 2 .. 2 ** 8 - 1 with Size => 8;
type Option is
message
Copied : Boolean;
Option_Class : Option_Class;
Option_Number : Option_Number
then null
if Option_Class = CONTROL and Option_Number = 1
then Option_Length
if Option_Number > 1;
Option_Length : Option_Length;
Option_Data : Opaque
with Size => (Option_Length - 2) * 8
if (Option_Class = CONTROL and Option_Number = 2 and Option_Length = 11)
or (Option_Class = CONTROL and Option_Number = 8 and Option_Length = 4)
or (Option_Class = CONTROL and (Option_Number = 3 or Option_Number = 7 or Option_Number = 9))
or (Option_Class = DEBUGGING_AND_MEASUREMENT and Option_Number = 4);
end message;
type Options is sequence of Option;
type Packet is
message
Version : Version;
IHL : IHL;
DSCP : DCSP;
ECN : ECN;
Total_Length : Total_Length
if Total_Length >= IHL * 4;
Identification : Identification;
Flag_R : Boolean
if Flag_R = False;
Flag_DF : Boolean;
Flag_MF : Boolean;
Fragment_Offset : Fragment_Offset;
TTL : TTL;
Protocol : Protocol_Numbers::Assigned_Internet_Protocol_Numbers;
Header_Checksum : Header_Checksum;
Source : Address;
Destination : Address;
Options : Options
with Size => IHL * 32 - (Destination'Last - Message'First + 1);
Payload : Opaque
with Size => Total_Length * 8 - (IHL * 32)
then null
if Header_Checksum'Valid_Checksum;
end message with
Checksum => (Header_Checksum => (Version'First .. Header_Checksum'First - 1,
Header_Checksum'Last + 1 .. Payload'First - 1));
end IPv4;