X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;ds=sidebyside;f=examples%2Fmake_ipv4_header.ml;h=225eae3e34c4ac432c652fd949ef37006ae1e7cc;hb=0fb4b24ebe3b85c935786f8e3e472d0d2292744e;hp=55ba2e1ee8e3330fd3ce841003d6f93ecb8bfa5a;hpb=e3bd7e70911c1afb5ad31d2368ed94961a973f62;p=ocaml-bitstring.git diff --git a/examples/make_ipv4_header.ml b/examples/make_ipv4_header.ml index 55ba2e1..225eae3 100644 --- a/examples/make_ipv4_header.ml +++ b/examples/make_ipv4_header.ml @@ -1,5 +1,5 @@ (* Create an IPv4 header. - * $Id: make_ipv4_header.ml,v 1.1 2008-03-31 22:52:17 rjones Exp $ + * $Id$ *) open Printf @@ -14,32 +14,24 @@ let fragoffset = 0 let ttl = 255 let protocol = 17 (* UDP *) let checksum = 0 -let source = 0xc0a80202 (* 192.168.2.2 *) -let dest = 0xc0a80201 (* 192.168.2.1 *) -let options = Bitmatch.empty_bitstring +let source = 0xc0a80202_l (* 192.168.2.2 *) +let dest = 0xc0a80201_l (* 192.168.2.1 *) +let options = Bitstring.empty_bitstring let payload_length = (length - hdrlen*4) * 8 -let payload = Bitmatch.create_bitstring payload_length +let payload = Bitstring.create_bitstring payload_length let header = - <| 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 : -1, bitstring; - payload : payload_length, bitstring |> - + 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 (* - generates: - - let header = Bitmatch.join_bitstrings [ - Bitmatch.create_unsigned_be version 4; - Bitmatch.create_unsigned_be hdrlen 4; (* etc. *) - options; - Bitmatch.check_bitstring_length payload payload_length - ] - - which can throw an exception if values are out of range. + Not implemented at the moment XXX + options : -1 : bitstring; + payload : payload_length : bitstring *) + } -let () = Bitmatch.file_of_bitstring header "ipv4_header_out.dat" +let () = Bitstring.bitstring_to_file header "ipv4_header_out.dat"