Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jonathan Heusser <jonny@drugphish.ch>
To: caml-list@inria.fr
Subject: [Caml-list] camlIDL and callbacks
Date: Sat, 22 Nov 2003 20:16:38 +0100	[thread overview]
Message-ID: <3FBFB616.80301@drugphish.ch> (raw)

[-- Attachment #1: Type: text/plain, Size: 652 bytes --]

Hello,

I'm trying to implement libpcap bindings for ocaml using CamlIDL.

Currently, I'm running into trouble with C libpcap functions which are 
using
callbacks. Those are: pcap_loop, pcap_dispatch and indirectly pcap_next 
(which calls pcap_dispatch)

When using e.g. pcap_next in ocaml, defined by the idl code attached, it 
returns a
correct pcap_pkthdr though the call to pcap_dispatch is not working due 
to the missing
callback functionality..

Can anyone give me an idea how to solve such C-to-ocaml callback issues 
in idl ?

thank you for any help,
jonathan heusser

-- 
Key fingerprint = 2A55 EB7C B7EA 6336 7767  4A47 910A 307B 1333 BD6C


[-- Attachment #2: pcap.idl --]
[-- Type: text/plain, Size: 1244 bytes --]

quote(C, "
	#include <pcap.h>

	typedef pcap_t *pcap_handle;
	typedef struct pcap_pkthdr pcap_pkthdr;

	typedef void (*pcap_callback)(u_char *, const struct pcap_pkthdr *,
			 const u_char *);

")

/* type defitions */
/* .............. */

typedef [abstract, ptr] void * pcap_handle;

struct timeval {
	int tv_sec;
	int tv_usec;
};

typedef struct {
	struct timeval ts;
	int caplen;
	int len;
} pcap_pkthdr;

/* function definitions */
/* .................... */

/* experimental callback handler */
typedef [ptr,mltype("string -> pcap_pkthdr -> string -> unit")] void *pcap_callback;

/* tested, OK */
pcap_handle pcap_open_live([in,string] char *dev, [in] int snaplen, 
		[in] int promisc, [in] int to_ms, [in,out,string] char *err);

/* tested, OK */
[string] char *pcap_lookupdev([in,out,string] char *errbuf);

/* broken ! */
[string] unsigned char *pcap_next([in] pcap_handle p, [in,out] pcap_pkthdr * h)
	quote(call, "_res = (char*) pcap_next(p,h); 
	");

/* tested, OK */
void pcap_close(pcap_handle p);

/* broken ! */
int pcap_loop([in] pcap_handle p, [in] int cnt, [in] pcap_callback callback, 
		[in,string] char *user);

int pcap_dispatch([in] pcap_handle p, [in] int cnt, [in] pcap_callback callback,
	[in,string] char *user);
	

             reply	other threads:[~2003-11-22 17:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-22 19:16 Jonathan Heusser [this message]
2003-11-22 17:58 ` Daniel Bünzli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3FBFB616.80301@drugphish.ch \
    --to=jonny@drugphish.ch \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox