let () =
bitmatch header with
- | version : 4; hdrlen : 4; tos : 8; length : 16;
- identification : 16; flags : 3; fragoffset : 13;
- ttl : 8; protocol : 8; checksum : 16;
- source : 32;
- dest : 32;
- options : (hdrlen-5)*32 : bitstring;
- payload : -1 : bitstring
+ | { version : 4; hdrlen : 4; tos : 8; length : 16;
+ identification : 16; flags : 3; fragoffset : 13;
+ ttl : 8; protocol : 8; checksum : 16;
+ source : 32;
+ dest : 32;
+ options : (hdrlen-5)*32 : bitstring;
+ payload : -1 : bitstring }
when version = 4 ->
printf "IPv%d:\n" version;
printf " packet payload:\n";
Bitmatch.hexdump_bitstring stdout payload
- | version : 4 ->
+ | { version : 4 } ->
eprintf "cannot parse IP version %d\n" version
- | _ as header ->
+ | { _ } as header ->
eprintf "data is smaller than one nibble:\n";
Bitmatch.hexdump_bitstring stderr header
let payload = Bitmatch.create_bitstring payload_length
let header =
- BITSTRING
+ BITSTRING {
version : 4; hdrlen : 4; tos : 8; length : 16;
identification : 16; flags : 3; fragoffset : 13;
ttl : 8; protocol : 8; checksum : 16;
dest : 32;
options : -1, bitstring;
payload : payload_length, bitstring
+ }
let () = Bitmatch.file_of_bitstring header "ipv4_header_out.dat"