File : net-packet-ip-v4.ads
package Net.Packet.IP.V4 is
do_debug : Debug_Mode := Inherit;
type Address is new Net.Packet.IP.Address with private;
LOOPBACK, BROADCAST, ANY : constant Address;
function New_Address (b : Payload_Type) return Address;
function To_String (a : Address) return String;
type Packet is new Net.Packet.IP.Packet with private;
function New_Packet (f : Payload_Type) return Packet;
function Payload (p : Packet) return Payload_Type;
function Src (p : Packet) return Address'Class;
function Dst (p : Packet) return Address'Class;
private
type ipv4_addr is array (1 .. 4) of Integer_8;
pragma Pack (ipv4_addr); -- is already network byte order
for ipv4_addr'Size use 4*8;
type Address is new Net.Packet.IP.Address with record
addr : ipv4_addr;
end record;
LOOPBACK : constant Address := (addr => (127, 0, 0, 1));
BROADCAST : constant Address := (addr => (255, 255, 255, 255));
ANY : constant Address := (addr => (0, 0, 0, 0));
type Version_Type is (v4);
for Version_Type use (v4 => 4);
subtype header_length is Integer_8 range 5 .. 15;
subtype fragment_offset is Integer_12;
subtype optblob is Payload_Type;
type precedence_type is (Routine, Priority, Immediate, Flash,
Flash_Override, CRITIC_ECP, Internetwork_Control, Network_Control);
for precedence_type use (Routine => 0, Priority => 1, Immediate => 2,
Flash => 3, Flash_Override => 4, CRITIC_ECP => 5,
Internetwork_Control => 6, Network_Control => 7);
type protocol_type is (HOPOPT, ICMP, IGMP, GGP, IP, ST, TCP, CBT, EGP,
IGP, BBN_RCC_MON, NVP_II, PUP, ARGUS, EMCON, XNET, CHAOS, UDP, MUX,
DCN_MEAS, HMP, PRM, XNS_IDP, TRUNK_1, TRUNK_2, LEAF_1, LEAF_2, RDP,
IRTP, ISO_TP4, NETBLT, MFE_NSP, MERIT_INP, SEP, Third_Party_Connect,
IDPR, XTP, DDP, IDPR_CMTP, TP_Plus_Plus, IL, IPv6, SDRP, IPv6_Route,
IPv6_Frag, IDRP, RSVP, GRE, MHRP, BNA, ESP, AH, I_NLSP, SWIPE, NARP,
MOBILE, TLSP, SKIP, IPv6_ICMP, IPv6_NoNxt, IPv6_Opts, Host_Internal,
CFTP, Local_Network, SAT_EXPAK, KRYPTOLAN, RVD, IPPC,
Distributed_File_System, SAT_MON, VISA, IPCV, CPNX, CPHB, WSN, PVP,
BR_SAT_MON, SUN_ND, WB_MON, WB_EXPAK, ISO_IP, VMTP, SECURE_VMTP,
VINES, TTP, NSFNET_IGP, DGP, TCF, EIGRP, OSPFIGP, Sprite_RPC, LARP,
MTP, AX_25, IPIP, MICP, SCC_SP, ETHERIP, ENCAP, Private_Encryption,
GMTP, IFMP, PNNI, PIM, ARIS, SCPS, QNX, Active_Networks, IPComp, SNP,
Compaq_Peer, IPX_in_IP, VRRP, PGM, Null_Hop, L2TP, DDX, IATP, STP,
SRP, UTI, SMP, SM, PTP, ISIS, FIRE, CRTP, CRUDP, SSCOPMCE, IPLT, SPS,
PIPE, SCTP, FC);
for protocol_type use (
HOPOPT => 0, -- IPv6 Hop-by-Hop Option [RFC1883]
ICMP => 1, -- Internet Control Message [RFC792]
IGMP => 2, -- Internet Group Management [RFC1112]
GGP => 3, -- Gateway-to-Gateway [RFC823]
IP => 4, -- IP in IP (encapsulation) [RFC2003]
ST => 5, -- Stream [RFC1190,IEN119]
TCP => 6, -- Transmission Control [RFC793]
CBT => 7, -- CBT [Ballardie]
EGP => 8, -- Exterior Gateway Protocol [RFC888,DLM1]
IGP => 9, -- any private interior gateway [IANA]
BBN_RCC_MON => 10, -- BBN RCC Monitoring [SGC]
NVP_II => 11, -- Network Voice Protocol [RFC741,SC3]
PUP => 12, -- PUP [PUP,XEROX]
ARGUS => 13, -- ARGUS [RWS4]
EMCON => 14, -- EMCON [BN7]
XNET => 15, -- Cross Net Debugger [IEN158,JFH2]
CHAOS => 16, -- Chaos [NC3]
UDP => 17, -- User Datagram [RFC768,JBP]
MUX => 18, -- Multiplexing [IEN90,JBP]
DCN_MEAS => 19, -- DCN Measurement Subsystems [DLM1]
HMP => 20, -- Host Monitoring [RFC869,RH6]
PRM => 21, -- Packet Radio Measurement [ZSU]
XNS_IDP => 22, -- XEROX NS IDP [ETHERNET,XEROX]
TRUNK_1 => 23, -- Trunk-1 [BWB6]
TRUNK_2 => 24, -- Trunk-2 [BWB6]
LEAF_1 => 25, -- Leaf-1 [BWB6]
LEAF_2 => 26, -- Leaf-2 [BWB6]
RDP => 27, -- Reliable Data Protocol [RFC908,RH6]
IRTP => 28, -- Internet Reliable Transaction [RFC938,TXM]
ISO_TP4 => 29, -- ISO Transport Protocol Class 4 [RFC905,RC77]
NETBLT => 30, -- Bulk Data Transfer Protocol [RFC969,DDC1]
MFE_NSP => 31, -- MFE Network Services Protocol [MFENET,BCH2]
MERIT_INP => 32, -- MERIT Internodal Protocol [HWB]
SEP => 33, -- Sequential Exchange Protocol [JC120]
Third_Party_Connect => 34, -- Third Party Connect Protocol [SAF3]
IDPR => 35, -- Inter-Domain Policy Routing Protocol [MXS1]
XTP => 36, -- XTP [GXC]
DDP => 37, -- Datagram Delivery Protocol [WXC]
IDPR_CMTP => 38, -- IDPR Control Message Transport Proto [MXS1]
TP_Plus_Plus => 39, -- TP++ Transport Protocol [DXF]
IL => 40, -- IL Transport Protocol [Presotto]
IPv6 => 41, -- Ipv6 [Deering]
SDRP => 42, -- Source Demand Routing Protocol [DXE1]
IPv6_Route => 43, -- Routing Header for IPv6 [Deering]
IPv6_Frag => 44, -- Fragment Header for IPv6 [Deering]
IDRP => 45, -- Inter-Domain Routing Protocol [Sue Hares]
RSVP => 46, -- Reservation Protocol [Bob Braden]
GRE => 47, -- General Routing Encapsulation [Tony Li]
MHRP => 48, -- Mobile Host Routing Protocol[David Johnson]
BNA => 49, -- BNA [Gary Salamon]
ESP => 50, -- Encap Security Payload for IPv6 [RFC1827]
AH => 51, -- Authentication Header for IPv6 [RFC1826]
I_NLSP => 52, -- Integrated Net Layer Security TUBA [GLENN]
SWIPE => 53, -- IP with Encryption [JI6]
NARP => 54, -- NBMA Address Resolution Protocol [RFC1735]
MOBILE => 55, -- IP Mobility [Perkins]
TLSP => 56, -- Transport Layer Security Protocol [Oberg]
SKIP => 57, -- SKIP [Markson]
IPv6_ICMP => 58, -- ICMP for IPv6 [RFC1883]
IPv6_NoNxt => 59, -- No Next Header for IPv6 [RFC1883]
IPv6_Opts => 60, -- Destination Options for IPv6 [RFC1883]
Host_Internal => 61, -- any host internal protocol [IANA]
CFTP => 62, -- CFTP [CFTP,HCF2]
Local_Network => 63, -- any local network [IANA]
SAT_EXPAK => 64, -- SATNET and Backroom EXPAK [SHB]
KRYPTOLAN => 65, -- Kryptolan [PXL1]
RVD => 66, -- MIT Remote Virtual Disk Protocol [MBG]
IPPC => 67, -- Internet Pluribus Packet Core [SHB]
Distributed_File_System => 68, -- any distributed file system [IANA]
SAT_MON => 69, -- SATNET Monitoring [SHB]
VISA => 70, -- VISA Protocol [GXT1]
IPCV => 71, -- Internet Packet Core Utility [SHB]
CPNX => 72, -- Computer Protocol Network Executive [DXM2]
CPHB => 73, -- Computer Protocol Heart Beat [DXM2]
WSN => 74, -- Wang Span Network [VXD]
PVP => 75, -- Packet Video Protocol [SC3]
BR_SAT_MON => 76, -- Backroom SATNET Monitoring [SHB]
SUN_ND => 77, -- SUN ND PROTOCOL-Temporary [WM3]
WB_MON => 78, -- WIDEBAND Monitoring [SHB]
WB_EXPAK => 79, -- WIDEBAND EXPAK [SHB]
ISO_IP => 80, -- ISO Internet Protocol [MTR]
VMTP => 81, -- VMTP [DRC3]
SECURE_VMTP => 82, -- SECURE-VMTP [DRC3]
VINES => 83, -- VINES [BXH]
TTP => 84, -- TTP [JXS]
NSFNET_IGP => 85, -- NSFNET-IGP [HWB]
DGP => 86, -- Dissimilar Gateway Protocol [DGP,ML109]
TCF => 87, -- TCF [GAL5]
EIGRP => 88, -- EIGRP [CISCO,GXS]
OSPFIGP => 89, -- OSPFIGP [RFC1583,JTM4]
Sprite_RPC => 90, -- Sprite RPC Protocol [SPRITE,BXW]
LARP => 91, -- Locus Address Resolution Protocol [BXH]
MTP => 92, -- Multicast Transport Protocol [SXA]
AX_25 => 93, -- AX.25 Frames [BK29]
IPIP => 94, -- IP-within-IP Encapsulation Protocol [JI6]
MICP => 95, -- Mobile Internetworking Control Pro. [JI6]
SCC_SP => 96, -- Semaphore Communications Sec. Pro. [HXH]
ETHERIP => 97, -- Ethernet-within-IP Encapsulation [RXH1]
ENCAP => 98, -- Encapsulation Header [RFC1241,RXB3]
Private_Encryption => 99, -- any private encryption scheme [IANA]
GMTP => 100, -- GMTP [RXB5]
IFMP => 101, -- Ipsilon Flow Management Protocol [Hinden]
PNNI => 102, -- PNNI over IP [Callon]
PIM => 103, -- Protocol Independent Multicast [Farinacci]
ARIS => 104, -- ARIS [Feldman]
SCPS => 105, -- SCPS [Durst]
QNX => 106, -- QNX [Hunter]
Active_Networks => 107, -- [Braden]
IPComp => 108, -- IP Payload Compression Protocol [RFC2393]
SNP => 109, -- Sitara Networks Protocol [Sridhar]
Compaq_Peer => 110, -- Compaq Peer Protocol [Volpe]
IPX_in_IP => 111, -- IPX in IP [Lee]
VRRP => 112, -- Virtual Router Redundancy Protocol [Hinden]
PGM => 113, -- PGM Reliable Transport Protocol [Speakman]
Null_Hop => 114, -- any 0-hop protocol [IANA]
L2TP => 115, -- Layer Two Tunneling Protocol [Aboba]
DDX => 116, -- D-II Data Exchange (DDX) [Worley]
IATP => 117, -- Interactive Agent Transfer Protocol [Murphy]
STP => 118, -- Schedule Transfer Protocol [JMP]
SRP => 119, -- SpectraLink Radio Protocol [Hamilton]
UTI => 120, -- UTI [Lothberg]
SMP => 121, -- Simple Message Protocol [Ekblad]
SM => 122, -- SM [Crowcroft]
PTP => 123, -- Performance Transparency Protocol [Welzl]
ISIS => 124, -- over IPv4 [Przygienda]
FIRE => 125, -- [Partridge]
CRTP => 126, -- Combat Radio Transport Protocol [Sautter]
CRUDP => 127, -- Combat Radio User Datagram [Sautter]
SSCOPMCE => 128, -- Waber]
IPLT => 129, -- Hollbach]
SPS => 130, -- Secure Packet Shield [McIntosh]
PIPE => 131, -- Private IP Encapsulation within IP [Petri]
SCTP => 132, -- Stream Control Transmission Protocol [Stewart]
FC => 133 -- Fibre Channel [Rajagopal]
);
type Head is record
version : Version_Type := v4;
length1, length2 : Integer_8;
headlen : header_length := 5;
tos_pred : precedence_type := Routine;
tos_delay,
tos_thoughput,
tos_reliability,
dont_fragment,
more_fragments : Boolean := False;
ttl : Integer_8 := 255;
identification1,
identification2 : Integer_8;
checksum1,
checksum2 : Integer_8 := 0;
offset1 : Integer_5 := 0;
offset2 : Integer_8 := 0;
protocol : protocol_type;
src1, src2, src3, src4,
dst1, dst2, dst3, dst4 : Integer_8;
end record;
-- 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
-- 0 1 2 3
-- 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
-- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-- |Version| IHL |Type of Service| Total Length |
-- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-- | Identification |Flags| Fragment Offset |
-- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-- | Time to Live | Protocol | Header Checksum |
-- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-- | Source Address |
-- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-- | Destination Address |
-- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
-- | Options | Padding |
-- +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
for Head use record
version at 0 range 4 .. 7;
headlen at 0 range 0 .. 3;
tos_pred at 1 range 5 .. 7;
tos_delay at 1 range 4 .. 4;
tos_thoughput at 1 range 3 .. 3;
tos_reliability at 1 range 2 .. 2;
length1 at 2 range 0 .. 7;
length2 at 3 range 0 .. 7;
identification1 at 4 range 0 .. 7;
identification2 at 5 range 0 .. 7;
dont_fragment at 6 range 6 .. 6;
more_fragments at 6 range 5 .. 5;
offset1 at 6 range 0 .. 4;
offset2 at 7 range 0 .. 7;
ttl at 8 range 0 .. 7;
protocol at 9 range 0 .. 7;
checksum1 at 10 range 0 .. 7;
checksum2 at 11 range 0 .. 7;
src1 at 12 range 0 .. 7;
src2 at 13 range 0 .. 7;
src3 at 14 range 0 .. 7;
src4 at 15 range 0 .. 7;
dst1 at 16 range 0 .. 7;
dst2 at 17 range 0 .. 7;
dst3 at 18 range 0 .. 7;
dst4 at 19 range 0 .. 7;
end record;
for Head'Bit_Order use System.Low_Order_First;
package Head_Conv is new System.Address_To_Access_Conversions (Head);
subtype Head_Ptr is Head_Conv.Object_Pointer;
type Packet is new Net.Packet.IP.Packet with record
head : Head_Ptr;
options : optblob;
payload : Payload_Type;
end record;
end Net.Packet.IP.V4;