Message from discussion
ANNOUNCE: ocaml bitmatch (Erlang-style bitstrings for OCaml)
Path: g2news1.google.com!news4.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!news-out2.kabelfoon.nl!newsfeed.kabelfoon.nl!xindi.nntp.kabelfoon.nl!news.banetele.no!uio.no!nntp.uio.no!not-for-mail
From: Sylvain Le Gall <sylv...@le-gall.net>
Newsgroups: fa.caml
Subject: [Caml-list] Re: ANNOUNCE: ocaml bitmatch (Erlang-style bitstrings
for OCaml)
Date: Wed, 02 Apr 2008 00:18:00 UTC
Organization: Internet mailing list
Lines: 104
Sender: caml-list-boun...@yquem.inria.fr
Message-ID: <fa.aPBHR4nHGPHCKPwMfxrKTB7TLBc@ifi.uio.no>
References: <fa.RMQ/LdyMaqys1UP+mmZBxeRKxr8@ifi.uio.no>
NNTP-Posting-Host: jess.uio.no
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Trace: readme.uio.no 1207095480 1651 129.240.10.48 (2 Apr 2008 00:18:00 GMT)
X-Complaints-To: abuse@uio.no
NNTP-Posting-Date: Wed, 2 Apr 2008 00:18:00 +0000 (UTC)
To: caml-l...@inria.fr
X-IronPort-AV: E=Sophos;i="4.25,589,1199660400";
d="scan'208";a="24479307"
X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr
X-Original-To: caml-l...@yquem.inria.fr
Delivered-To: caml-l...@yquem.inria.fr
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"
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"
X-Injected-Via-Gmane: http://gmane.org/
X-Gmane-NNTP-Posting-Host: ks300734.kimsufi.com
User-Agent: slrn/0.9.8.1pl2 (Debian)
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
X-BeenThere: caml-l...@yquem.inria.fr
X-Mailman-Version: 2.1.5
List-Id: Caml users' mailing list <caml-list.yquem.inria.fr>
List-Unsubscribe: <http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list>,
<mailto:caml-list-requ...@yquem.inria.fr?subject=unsubscribe>
List-Post: <mailto:caml-l...@yquem.inria.fr>
List-Help: <mailto:caml-list-requ...@yquem.inria.fr?subject=help>
List-Subscribe: <http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list>,
<mailto:caml-list-requ...@yquem.inria.fr?subject=subscribe>
Original-Date: Wed, 2 Apr 2008 00:17:22 +0000 (UTC)
Original-Message-Id: <slrnfv5k4i.tll.sylv...@gallu.homelinux.org>
Original-References: <20080401224256.GB19...@annexia.org>
On 01-04-2008, Richard Jones <r...@annexia.org> 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
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs