1 (* Parse and display an IPv4 header from a file.
7 let header = Bitstring.bitstring_of_file "ipv4_header.dat"
11 | { version : 4; hdrlen : 4; tos : 8; length : 16;
12 identification : 16; flags : 3; fragoffset : 13;
13 ttl : 8; protocol : 8; checksum : 16;
16 options : (hdrlen-5)*32 : bitstring;
17 payload : -1 : bitstring }
20 printf "IPv%d:\n" version;
21 printf " header length: %d * 32 bit words\n" hdrlen;
22 printf " type of service: %d\n" tos;
23 printf " packet length: %d bytes\n" length;
24 printf " identification: %d\n" identification;
25 printf " flags: %d\n" flags;
26 printf " fragment offset: %d\n" fragoffset;
27 printf " ttl: %d\n" ttl;
28 printf " protocol: %d\n" protocol;
29 printf " checksum: %d\n" checksum;
30 printf " source: %lx dest: %lx\n" source dest;
31 printf " header options + padding:\n";
32 Bitstring.hexdump_bitstring stdout options;
33 printf " packet payload:\n";
34 Bitstring.hexdump_bitstring stdout payload
37 eprintf "cannot parse IP version %d\n" version
40 eprintf "data is smaller than one nibble:\n";
41 Bitstring.hexdump_bitstring stderr header