(* Read in IPv4 and IPv6 ping packets and display them.
- * $Id: 60_ping.ml,v 1.1 2008-04-01 10:58:53 rjones Exp $
+ * $Id: 60_ping.ml,v 1.2 2008-04-01 15:22:46 rjones Exp $
*)
open Printf
let display pkt =
bitmatch pkt with
- | version : 4; hdrlen : 4; tos : 8; length : 16;
+ (* IPv4 packet header *)
+ | 4 : 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 ->
+ payload : -1 : bitstring ->
- printf "IPv%d:\n" version; (* IPv4 packet *)
+ printf "IPv4:\n";
printf " header length: %d * 32 bit words\n" hdrlen;
printf " type of service: %d\n" tos;
printf " packet length: %d bytes\n" length;
printf " packet payload:\n";
Bitmatch.hexdump_bitstring stdout payload
- | version : 4; tclass : 8; flow : 20;
+ (* IPv6 packet header *)
+ | 6 : 4; tclass : 8; flow : 20;
length : 16; nexthdr : 8; ttl : 8;
source : 128 : bitstring;
dest : 128 : bitstring;
- payload : -1 : bitstring
- when version = 6 ->
+ payload : -1 : bitstring ->
- printf "IPv%d:\n" version; (* IPv6 packet *)
+ printf "IPv6:\n";
printf " traffic class: %d\n" tclass;
printf " flow label: %d\n" flow;
printf " packet (payload) length: %d bytes\n" length;