From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.3 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id AB5F9BBCA for ; Wed, 2 Apr 2008 02:17:45 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAA5u8kfAXQIn/2dsb2JhbACsag X-IronPort-AV: E=Sophos;i="4.25,589,1199660400"; d="scan'208";a="24479297" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 02 Apr 2008 02:17:45 +0200 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m320HiAt029171 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Wed, 2 Apr 2008 02:17:45 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgwCAA5u8kdQW+UCgWdsb2JhbACRSgEBECaaaA X-IronPort-AV: E=Sophos;i="4.25,589,1199660400"; d="scan'208";a="9081034" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail2-smtp-roc.national.inria.fr with ESMTP; 02 Apr 2008 02:17:36 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JgqfR-0002lL-UC for caml-list@inria.fr; Wed, 02 Apr 2008 00:17:29 +0000 Received: from ks300734.kimsufi.com ([91.121.65.225]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 02 Apr 2008 00:17:29 +0000 Received: from sylvain by ks300734.kimsufi.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 02 Apr 2008 00:17:29 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sylvain Le Gall Subject: Re: ANNOUNCE: ocaml bitmatch (Erlang-style bitstrings for OCaml) Date: Wed, 2 Apr 2008 00:17:22 +0000 (UTC) Message-ID: References: <20080401224256.GB19556@annexia.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ks300734.kimsufi.com User-Agent: slrn/0.9.8.1pl2 (Debian) Sender: news X-Miltered: at concorde with ID 47F2D0A8.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; le-gall:01 ocaml:01 ocaml:01 camlp:01 syntax:01 implements:01 erlang:01 erlang:01 kostis:01 padl:01 camlp:01 syntax:01 flags:01 tos:01 flags:01 On 01-04-2008, Richard Jones wrote: > In the finest tradition of version 0.1 announcements, this is the > first announcement of a highly experimental camlp4 syntax extension > which implements Erlang-style bitstrings, matching over bitstrings, > and construction of bitstrings. > > Source: http://www.annexia.org/tmp/ocaml-bitmatch-0.1.tar.gz > License: LGPLv2+ with OCaml linking exception > > Erlang has a "byte-oriented" data type which can be treated as a > stream of bits, and provides rather elegant features for creating and > matching over such streams. This is a key feature of Erlang and was > developed because of its history in telecommunications. (More about > the feature in this paper: > http://user.it.uu.se/~kostis/Papers/padl07.pdf) > > I have written a camlp4 syntax extension which does much the same in > OCaml. For example, you can now effortlessly parse IP packets: > > let display pkt = > bitmatch pkt with > (* IPv4 packet header from RFC 791: > 0 1 2 3 > 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > |Version| IHL |Type of Service| Total Length | > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | Identification |Flags| Fragment Offset | > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | Time to Live | Protocol | Header Checksum | > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | Source Address | > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | Destination Address | > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > | Options | Padding | > +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ > *) > | 4 : 4; hdrlen : 4; tos : 8; length : 16; (* same as above in OCaml *) > identification : 16; flags : 3; fragoffset : 13; > ttl : 8; protocol : 8; checksum : 16; > source : 32; > dest : 32; > options : (hdrlen-5)*32 : bitstring; (* NB computed length *) > payload : -1 : bitstring -> > At the condition this is not a joke ;-) I have two questions: * do you think you can get something efficient (part of the paper you are linking, talked about performance) * is there a way to retain part of the data structure... E.g TCP/UDP packet has the same IP part (the one you describe) + a TCP/UDP header... Example type ip_header_begin = << version: 4; hdrlen : 4; tos : 8; length : 16; identification : 16; flags : 3; fragoffset : 13; ttl : 8; >> type ip_header_end = << checksum : 16; source : 32; dest : 32; >> ;; type udp_header = << source_port: 16; destination_port: 16; length: 16; checksum: 16; >> ;; | ip_beg: ip_header_begin; 17: 8; ip_end: ip_header_end; udp: udp_header -> Printf.printf "Found an UDP packet (TTL: %d)" ip_beg.ttl | ip_beg: ip_header_begin; 6: 8; ip_end: ip_header_end; -> print_string "Found a TCP packet" (N.B.: there is other way to handle this problem... but this is just a question). Anyway, i found this interesting and worth looking at. Regards, Sylvain Le Gall