libpcap Binding & Cabal Question

I am trying to build the binding for libpcap.
http://www.haskell.org/pipermail/libraries/2004-June/002285.html
http://www.haskell.org//pipermail/libraries/attachments/20040630/4469b357/Pc...
Unfortunately when I run hsc2hs I get errors.
[dom@tility pcap]$ hsc2hs Pcap.hs
Pcap.hs:121:21: net/bpf.h: No such file or directory
Pcap.hs: In function `main':
Pcap.hs:461: error: structure has no member named `sa_len'
The first one is easily fixed. The version of libpcap I downloaded from
www.tcpdump.org (LIBPCAP 0.9.4) contains pcap-bpf.h not net/bpf.h (so I
replaced #inlcude

Hi Dominic, I wrote the binding so I'll try to have a look at the problem over the weekend. I've been meaning to Cabalize it for a while...perhaps the list will give advice that will let you get there first! It should also be updated to support the packet injection call, which is available on both Windows and Unix now. I will send an update to you and the list when it is ready. Best Regards, Greg On Apr 14, 2006, at 3:57 AM, Dominic Steinitz wrote:
I am trying to build the binding for libpcap.
http://www.haskell.org/pipermail/libraries/2004-June/002285.html http://www.haskell.org//pipermail/libraries/attachments/ 20040630/4469b357/Pcap-0001.obj
Unfortunately when I run hsc2hs I get errors.
[dom@tility pcap]$ hsc2hs Pcap.hs Pcap.hs:121:21: net/bpf.h: No such file or directory Pcap.hs: In function `main': Pcap.hs:461: error: structure has no member named `sa_len'
The first one is easily fixed. The version of libpcap I downloaded from www.tcpdump.org (LIBPCAP 0.9.4) contains pcap-bpf.h not net/bpf.h (so I replaced #inlcude
with #include ). The second one is a result because in some systems socket addresses are fixed-length and sizeof (struct sockaddr) gives the size of the structure but in other systems the socket address is variable length and there's an sa_len field giving the length of the structure.
The libpcap authors handle this by using configure to see if the sa_len field exists. If it does then
#define SA_LEN(addr) (get_sa_len(addr))
If does not then (actually it's more complicated than this but I don't want to clutter up an already cluttered email)
#define SA_LEN(addr) (sizeof (struct sockaddr))
Finally to my questions.
1. How do I get Cabal to check for the existence of sa_len? I'm guessing I follow the instructions in "2.2. System-dependent parameters" but I have never used autoconf in my life so if there were another easier way I'd be happy to hear about it.
2. How do I tell Cabal I need LIBPCAP 0.9.4?
Dominic.
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On Friday 14 Apr 2006 1:45 pm, Gregory Wright wrote:
Hi Dominic,
I wrote the binding so I'll try to have a look at the problem over the weekend. I've been meaning to Cabalize it for a while...perhaps the list will give advice that will let you get there first!
I haven't cabalized it yet but I did manage to get it working. In case anyone is interested, I've put a darcsized copy of the code here: darcs get http://www.haskell.org/networktools/src/pcap 1. Install libpcap. I used 0.9.4. 2. autoheader 3. autoconf 4. ./configure 5. hsc2hs Pcap.hsc 6. ghc -o test test.hs --make -lpcap -fglasgow-exts Greg, Can you test it works for you? I'm assuming your system supports sa_len. Mine doesn't. Dominic.

Hi Dominic, On Apr 22, 2006, at 11:09 AM, Dominic Steinitz wrote:
On Friday 14 Apr 2006 1:45 pm, Gregory Wright wrote:
Hi Dominic,
I wrote the binding so I'll try to have a look at the problem over the weekend. I've been meaning to Cabalize it for a while...perhaps the list will give advice that will let you get there first!
I haven't cabalized it yet but I did manage to get it working. In case anyone is interested, I've put a darcsized copy of the code here:
darcs get http://www.haskell.org/networktools/src/pcap
1. Install libpcap. I used 0.9.4. 2. autoheader 3. autoconf 4. ./configure 5. hsc2hs Pcap.hsc 6. ghc -o test test.hs --make -lpcap -fglasgow-exts
Greg,
Can you test it works for you? I'm assuming your system supports sa_len. Mine doesn't.
Dominic.
I'll give it a try. Last week I also added the pcap_inject and pcap_sendpacket functions to my local Pcap.hsc. I'll try your version and a version with these functions merged. Best WIshes, Greg

Dominic, The test works with ghc 6.4.2 on OS X 10.4.6, with test.hs edited to used "en0" instead of "eth0". I'll give it a try on FreeBSD 6.0 with ghc 6.4.1 as well. Best Wishes, Greg On Apr 22, 2006, at 11:09 AM, Dominic Steinitz wrote:
On Friday 14 Apr 2006 1:45 pm, Gregory Wright wrote:
Hi Dominic,
I wrote the binding so I'll try to have a look at the problem over the weekend. I've been meaning to Cabalize it for a while...perhaps the list will give advice that will let you get there first!
I haven't cabalized it yet but I did manage to get it working. In case anyone is interested, I've put a darcsized copy of the code here:
darcs get http://www.haskell.org/networktools/src/pcap
1. Install libpcap. I used 0.9.4. 2. autoheader 3. autoconf 4. ./configure 5. hsc2hs Pcap.hsc 6. ghc -o test test.hs --make -lpcap -fglasgow-exts
Greg,
Can you test it works for you? I'm assuming your system supports sa_len. Mine doesn't.
Dominic.
participants (2)
-
Dominic Steinitz
-
Gregory Wright