protocol ip {
vershl { ip[0:1] } /* [position:size] in terms of bytes */
vers { (vershl & 0xf0)>>4 } /* getting the higher order four bits and shifting them down */
tmphl { (vershl & 0x0f) } /* getting the lower order bits */
hlen { tmphl << 2 } /* multiplying length by 4 to get it in terms of bytes */
totlen { ip[2:2] }
ident { ip[4:2] }
frags { ip[6:2] }
ttl { ip[8:1] }
proto { ip[9:1] }
cksum { ip[10:2] }
source { ip[12:4] }
dest { ip[16:4] }
demux { /* this is used to specify encapsulation */
( proto == 6 ) { tcp at hlen }
( proto == 17 ) { udp at hlen }
( default ) { ipunknown at hlen }
}
}
type ipdatagram = {
vershl : Word8.word,
(* vers :
tmphl :
hlen : *)
(* totlen : 16 bits
ident : 16 bits
frags : 16 bits *)
ttl : Word8.word,
proto : Word8.word,
(* cksum : 16 bits *)
source : Word32.word,
dest : Word32.word,
}