<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">There is a pcap library &nbsp;- it is a bit of overkill if all you are trying to do is read pcap files.<div><br></div><div>I have an (internal - could be made external to the company) library that does this sort of thing and reads using Binary the pcap file and does the appropriate re-ordering of the bytes within the words depending on the pcap endianness</div><div><br></div><div>Neil</div><div><br><div><div>On 12 Oct 2011, at 16:38, mukesh tiwari wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hello all <br>I was going through wireshark and read this<a href="http://wiki.wireshark.org/SampleCaptures?action=AttachFile&amp;do=view&amp;target=udp_lite_full_coverage_0.pcap"> pcap</a> file in wireshark. I wrote a simple haskell file which reads the pcap file displays its contents however it looks completely different from wireshark. When i run this program . it does not produce any thing and when i press ^C ( CTRL - C ) it produce output. <br>
<br>output for given file <br>^C<b>0xd4 0xc3 0xb2 0xa1 0x02 0x00 0x04 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0xff 0xff 0x00 0x00 0x01 0x00 0x00 0x00 0x0b 0xd4 0x9e 0x43 0x41 0x38 0x01 0x00 0x3c 0x00 0x00 0x00 0x3c 0x00 0x00 0x00 </b>0x00<b> </b>0x04 0x76 0xdd 0xbb 0x3a 0x00 0x04 0x75 0xc7 0x87 0x49 0x08 0x00 0x45 0x00 0x00 0x28 0x1a 0x6a 0x40 0x00 0x40 0x88 0x6f 0x71 0x8b 0x85 0xcc 0xb0 0x8b 0x85 0xcc 0xb7 0x80 0x00 0x04 0xd2 0x00 0x00 0x38 0x45 0x68 0x65 0x6c 0x6c 0x6f 0x20 0x77 0x6f 0x72 0x6c 0x64 0x00 0x00 0x00 0x00 0x00 0x00 <br>
<br>The values displayed in wireshark <br>0000&nbsp; 00 04 76 dd bb 3a 00 04&nbsp; 75 c7 87 49 08 00 45 00&nbsp;&nbsp; ..v..:.. u..I..E.<br>0010&nbsp; 00 28 1a 6a 40 00 40 88&nbsp; 6f 71 8b 85 cc b0 8b 85&nbsp;&nbsp; .(.j@.@. oq......<br>0020&nbsp; cc b7 80 00 04 d2 00 00&nbsp; 38 45 68 65 6c 6c 6f 20&nbsp;&nbsp; ........ 8Ehello <br>
0030&nbsp; 77 6f 72 6c 64 0a 00 00&nbsp; 00 00 00 00&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; world... ....&nbsp;&nbsp;&nbsp; <br><br><br><br>import Data.Char<br>import Data.List<br>import Text.Printf<br>import Control.Monad<br><br><br><br>fileReader :: Handle -&gt; IO ()<br>
fileReader h = do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t &lt;- hIsEOF h<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if t&nbsp; then return ()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else do<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; tmp &lt;- hGetLine h<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; forM_&nbsp; tmp (&nbsp; printf "0x%02x " )&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileReader h&nbsp;&nbsp;&nbsp; <br>
<br>main = do <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; l &lt;- openBinaryFile "udp_lite_full_coverage_0.pcap" ReadMode<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fileReader l <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print "end"<br><br>I am simply trying to write&nbsp; a&nbsp; haskell script which produce interpretation of pcap packet same as wireshark ( At least for UDP packet ) . Could some one please tell me a guide map to approach for this . A general guide line for this project like What to read which&nbsp; could be helpful for this project , which haskell library or any thing which you think is useful . <br>
<br>Regards <br>Mukesh Tiwari<br>
_______________________________________________<br>Haskell-Cafe mailing list<br><a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br><a href="http://www.haskell.org/mailman/listinfo/haskell-cafe">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br></blockquote></div><br></div></body></html>