I'm having trouble with pcap...
I've been trying to make this ruby script work
#!/usr/bin/env ruby
# this line imports the libpcap ruby bindings
require 'pcaplet'
# create a sniffer that grabs the first 1500 bytes of each packet
$network = Pcaplet.new('-s 1500')
# create a filter that uses our query string and the sniffer we just made
$filter = Pcap::Filter.new('tcp and dst port 80', $network.capture)
# add the new filter to the sniffer
$network.add_filter($filter)
# iterate over every packet that goes through the sniffer for p in the $network
# print packet data for each packet that matches the filter
puts p.tcp_data if $filter =~ p
$end
but I end up getting this when I try and run it
/usr/lib/ruby/site_ruby/1.8/i486-linux/pcap.so: warning: do not use Fixnums as Symbols
/usr/lib/ruby/site_ruby/1.8/i486-linux/pcap.so: warning: do not use Fixnums as Symbols
/usr/lib/ruby/site_ruby/1.8/i486-linux/pcap.so: warning: do not use Fixnums as Symbols
packet_filter.rb:17:in `=~': wrong type NilClass (expected Pcap::Packet) (TypeError)
from packet_filter.rb:17
So I downloaded ruby-1.8.6-i486-1.tgz and the ruby-1.8.6_p287-i486-1_slack12.0.tgz to make sure I was fully updated. I installpkg ruby-1.8.6-i486.tgz and then the ruby-1.8.6_p287-i486-1_slack12.0.tgz(patch).
Still I had the same problem so I googled for a bit and found a patch(not sure if it did what ruby-1.8.6_p287-i486-1_slack12.0.tgz did, but I figured it was worth a shot.
So I downloaded the source for pcap ruby-pcap-0.6.tar.gz along with this patch
[trist007@bt:~/downloads]$ cat patch-Pcap.c
--- patch-Pcap.c begins here ---
--- Pcap.c.orig 2008-05-01 15:26:25.000000000 -0500
+++ Pcap.c 2008-05-01 15:27:21.000000000 -0500
@@ -782,9 +782,9 @@
/* define class PcapStat */
cPcapStat = rb_funcall(rb_cStruct, rb_intern("new"), 4,
Qnil,
- INT2NUM(rb_intern("recv")),
- INT2NUM(rb_intern("drop")),
- INT2NUM(rb_intern("ifdrop")));
+ ID2SYM(rb_intern("recv")),
+ ID2SYM(rb_intern("drop")),
+ ID2SYM(rb_intern("ifdrop")));
rb_define_const(mPcap, "Stat", cPcapStat);
/* define exception classes */
--- patch-Pcap.c ends here ---
So then I do this
tar -xvvzf ruby-pcap-0.6.tar.gz
cd pcap
mv ~/patch patch-Pcap.c .
patch -u -o patch-Pcap Pcap.c patch-Pcap.c
# says patching file
ruby extconf.rb #which configures it
make
make install
# no errors get passed
Then I run the script again, and I get that same error from above. No change at all. Any thoughts?
|