pcaprub 0.12.3 → 0.12.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/pcaprub_c/pcaprub.c +17 -4
- data/lib/pcaprub/version.rb +1 -1
- data/test/test_pcaprub_unit.rb +11 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 282b1065a65ad397abd040bcdc8fa3b692c2cae0
|
4
|
+
data.tar.gz: df9c6be00a06fd8a1602c59e55d8614a633da93e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 618dabf64136f5f255a5e85e95efc1d17d215b1e45c563528e2b7919486538877d509254a0c607b85f5ca66bceafae46e7f2577d60c4ef5bfe4ddf7dd53287b0
|
7
|
+
data.tar.gz: c32162eb764c0b91d8ca93a0d9435e1adf3560367f7145c2eb25c8c551a41cdaaa67c349303fa3666accdfb5e793a582742f2e7fa838e321e18cc6be91289283
|
data/ext/pcaprub_c/pcaprub.c
CHANGED
@@ -32,6 +32,7 @@ static VALUE rbpcap_thread_wait_handle(HANDLE fno);
|
|
32
32
|
|
33
33
|
#define OFFLINE 1
|
34
34
|
#define LIVE 2
|
35
|
+
#define DEAD 3
|
35
36
|
|
36
37
|
#if !defined(PCAP_NETMASK_UNKNOWN)
|
37
38
|
/*
|
@@ -413,7 +414,11 @@ rbpcap_setfilter(VALUE self, VALUE filter)
|
|
413
414
|
if(TYPE(filter) != T_STRING)
|
414
415
|
rb_raise(eBPFilterError, "filter must be a string");
|
415
416
|
|
416
|
-
|
417
|
+
if(! rbpcap_ready(rbp)) return self;
|
418
|
+
|
419
|
+
if(rbp->type == DEAD) {
|
420
|
+
rb_raise(eBPFilterError, "unable to set bpf filter on OPEN_DEAD");
|
421
|
+
}
|
417
422
|
|
418
423
|
if(rbp->type == LIVE)
|
419
424
|
if(pcap_lookupnet(rbp->iface, &netid, &mask, eb) < 0) {
|
@@ -427,7 +432,7 @@ rbpcap_setfilter(VALUE self, VALUE filter)
|
|
427
432
|
}
|
428
433
|
|
429
434
|
if(pcap_setfilter(rbp->pd, &bpf) < 0) {
|
430
|
-
|
435
|
+
pcap_freecode(&bpf);
|
431
436
|
rb_raise(eBPFilterError, "unable to set bpf filter: %s", pcap_geterr(rbp->pd));
|
432
437
|
}
|
433
438
|
|
@@ -662,7 +667,6 @@ rbpcap_open_dead(VALUE self, VALUE linktype, VALUE snaplen)
|
|
662
667
|
{
|
663
668
|
rbpcap_t *rbp;
|
664
669
|
|
665
|
-
|
666
670
|
if(TYPE(linktype) != T_FIXNUM)
|
667
671
|
rb_raise(rb_eArgError, "linktype must be a fixnum");
|
668
672
|
if(TYPE(snaplen) != T_FIXNUM)
|
@@ -671,7 +675,7 @@ rbpcap_open_dead(VALUE self, VALUE linktype, VALUE snaplen)
|
|
671
675
|
Data_Get_Struct(self, rbpcap_t, rbp);
|
672
676
|
|
673
677
|
memset(rbp->iface, 0, sizeof(rbp->iface));
|
674
|
-
rbp->type =
|
678
|
+
rbp->type = DEAD;
|
675
679
|
|
676
680
|
rbp->pd = pcap_open_dead(
|
677
681
|
NUM2INT(linktype),
|
@@ -890,6 +894,10 @@ rbpcap_next_data(VALUE self)
|
|
890
894
|
if(rbp->type == OFFLINE && ret <= 0)
|
891
895
|
return Qnil;
|
892
896
|
|
897
|
+
if(rbp->type == DEAD && ret <= 0)
|
898
|
+
return Qnil;
|
899
|
+
|
900
|
+
|
893
901
|
if(ret > 0 && job.hdr.caplen > 0)
|
894
902
|
return rb_str_new((char *) job.pkt, job.hdr.caplen);
|
895
903
|
|
@@ -935,6 +943,9 @@ rbpcap_next_packet(VALUE self)
|
|
935
943
|
if(rbp->type == OFFLINE && ret <= 0)
|
936
944
|
return Qnil;
|
937
945
|
|
946
|
+
if(rbp->type == DEAD && ret <= 0)
|
947
|
+
return Qnil;
|
948
|
+
|
938
949
|
if(ret > 0 && job.hdr.caplen > 0)
|
939
950
|
{
|
940
951
|
rbpacket = ALLOC(rbpacket_t);
|
@@ -977,6 +988,7 @@ rbpcap_each_data(VALUE self)
|
|
977
988
|
for(;;) {
|
978
989
|
VALUE packet = rbpcap_next_data(self);
|
979
990
|
if(packet == Qnil && rbp->type == OFFLINE) break;
|
991
|
+
if(packet == Qnil && rbp->type == DEAD) break;
|
980
992
|
#if defined(WIN32)
|
981
993
|
packet == Qnil ? rbpcap_thread_wait_handle(fno) : rb_yield(packet);
|
982
994
|
#else
|
@@ -1018,6 +1030,7 @@ rbpcap_each_packet(VALUE self)
|
|
1018
1030
|
for(;;) {
|
1019
1031
|
VALUE packet = rbpcap_next_packet(self);
|
1020
1032
|
if(packet == Qnil && rbp->type == OFFLINE) break;
|
1033
|
+
if(packet == Qnil && rbp->type == DEAD) break;
|
1021
1034
|
#if defined(WIN32)
|
1022
1035
|
packet == Qnil ? rbpcap_thread_wait_handle(fno) : rb_yield(packet);
|
1023
1036
|
#else
|
data/lib/pcaprub/version.rb
CHANGED
data/test/test_pcaprub_unit.rb
CHANGED
@@ -138,6 +138,17 @@ class Pcap::UnitTest < Test::Unit::TestCase
|
|
138
138
|
assert_equal(o, o.setmonitor(true))
|
139
139
|
end
|
140
140
|
|
141
|
+
def test_open_dead
|
142
|
+
# No applied filters on OPEN_DEAD just compile checking
|
143
|
+
o = Pcap.open_dead(Pcap::DLT_NULL, 65535)
|
144
|
+
assert_nothing_raised do
|
145
|
+
o.compile("ip host 1.2.3.4")
|
146
|
+
end
|
147
|
+
assert_raise PCAPRUB::BPFError do
|
148
|
+
o.setfilter("ip host 1.2.3.5")
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
141
152
|
def test_filter
|
142
153
|
d = Pcap.lookupdev
|
143
154
|
o = Pcap.create(d)
|