[Haskell-cafe] Using dump in Netwotk.Pcap

Harald ROTTER harald.rotter at sagem.com
Tue May 8 07:23:01 EDT 2007

Dear Haskellers,

as a Haskell newbie I really enjoyed Austin Seipp's article on writing a
packet sniffer in Haskell using the libpcap.
I played around with Network.Pcap and tried to dump packets into a pcap
file using the dump function:

dump :: Ptr PcapDumpTag -> Ptr PktHdr -> Ptr Word8 -> IO ()

As compared to the loop function (used by Austin's packet sniffer)

loop :: Ptr PcapTag -> Int -> Callback -> IO Int
type Callback = PktHdr -> Ptr Word8 -> IO ()

the dump function takes a "Ptr PktHdr". If I want to "dump" inside a
Callback, I have the problem of getting
a "PktHdr" argument, but I need a "Ptr PktHdr" to dump. I tried to use

with :: Storable a => a -> (Ptr a -> IO b) -> IO b

but PktHdr is unfortunately not an instance of the "Storable" class.

How is it possible to use the "dump" function (that needs a Ptr PktHdr)
inside a Callback that only
passes PktHdr ?

Any help is appreciated.

Thank you


" Ce courriel et les documents qui y sont attaches peuvent contenir des informations confidentielles. Si vous n'etes  pas le destinataire escompte, merci d'en informer l'expediteur immediatement et de detruire ce courriel  ainsi que tous les documents attaches de votre systeme informatique. Toute divulgation, distribution ou copie du present courriel et des documents attaches sans autorisation prealable de son emetteur est interdite." 

" This e-mail and any attached documents may contain confidential or proprietary information. If you are not the intended recipient, please advise the sender immediately and delete this e-mail and all attached documents from your computer system. Any unauthorised disclosure, distribution or copying hereof is prohibited."

More information about the Haskell-Cafe mailing list