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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a1ecc5932a3e21b8c657e9369ffdd9c723e6f7b1
4
- data.tar.gz: 99dc681b6bad049acb3d135c6552b777e6d3e93f
3
+ metadata.gz: 282b1065a65ad397abd040bcdc8fa3b692c2cae0
4
+ data.tar.gz: df9c6be00a06fd8a1602c59e55d8614a633da93e
5
5
  SHA512:
6
- metadata.gz: c0e27c627a094b1407a26fe39b3aa9d8008d6c2436f1bd8031eb986b5d59c27d880a187035a1efead7f5cf81797a957b19601d732b2b9e8a803004580777f501
7
- data.tar.gz: 2cf6239d132f6bb32a22bc360fd105a3e7260d3e037ee25e58d02885f34e3bbb39b798eb34305c957a0bd5daa23847a65576764fabc4a99f5613a6594e53e6c9
6
+ metadata.gz: 618dabf64136f5f255a5e85e95efc1d17d215b1e45c563528e2b7919486538877d509254a0c607b85f5ca66bceafae46e7f2577d60c4ef5bfe4ddf7dd53287b0
7
+ data.tar.gz: c32162eb764c0b91d8ca93a0d9435e1adf3560367f7145c2eb25c8c551a41cdaaa67c349303fa3666accdfb5e793a582742f2e7fa838e321e18cc6be91289283
@@ -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
- if(! rbpcap_ready(rbp)) return self;
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
- pcap_freecode(&bpf);
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 = OFFLINE;
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
@@ -4,7 +4,7 @@ module PCAPRUB #:nodoc:
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 12
7
- TINY = 3
7
+ TINY = 4
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY].join('.')
10
10
 
@@ -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)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pcaprub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.3
4
+ version: 0.12.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - shadowbq