To Rephrase
I am newbie to haskell. I am trying to parse a pcap file using network pcap package.
I have byte stream as an input, so I used dispatchBS function with my own callback function.
My goal is to get the concatenated result from all callbacks. [a] of all the packets parsed. How do I keep track of all the packets got so far when dispatchBS has nothing in its signature to maintain state of all packets parsed so far?
http://hackage.haskell.org/packages/archive/pcap/0.4.5/doc/html/Network-Pcap.html#t:CallbackBS
For example, you might use the "loop" function and provide your own callback. This callback has to be an IO action, so one simple solution would be to have it append its packet argument to a sequence (see Data.Sequence) held in an IORef. Once you have received enough packets, just read the IOVar. Or you could do something more sophisticated with threads and queues, depending on what you are trying to achieve.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With