pcaprub 0.11.3 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1,15 @@
1
- require "pcaprub.so"
1
+ begin
2
+ if RUBY_VERSION =~ /1.8/
3
+ require '1.8/pcaprub_c'
4
+ elsif RUBY_VERSION =~ /1.9/
5
+ require '1.9/pcaprub_c'
6
+ elsif RUBY_VERSION =~ /2.0/
7
+ require '2.0/pcaprub_c'
8
+ elsif RUBY_VERSION =~ /2.1/
9
+ require '2.1/pcapru_c'
10
+ else
11
+ require 'pcaprub_c'
12
+ end
13
+ rescue Exception
14
+ require 'pcaprub_c'
15
+ end
@@ -1,18 +1,18 @@
1
1
  module PCAPRUB #:nodoc:
2
-
2
+
3
3
  module VERSION #:nodoc:
4
-
4
+
5
5
  MAJOR = 0
6
- MINOR = 11
7
- TINY = 3
6
+ MINOR = 12
7
+ TINY = 0
8
8
 
9
9
  STRING = [MAJOR, MINOR, TINY].join('.')
10
-
10
+
11
11
  end
12
12
  class Pcap
13
- def self.version
13
+ def self.version
14
14
  return PCAPRUB::VERSION::STRING
15
15
  end
16
16
  end
17
-
17
+
18
18
  end
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
+ require 'bundler/setup'
2
3
  require 'test/unit'
3
- require 'shoulda'
4
+ require 'shoulda-context'
4
5
 
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -8,3 +9,9 @@ require 'pcaprub'
8
9
 
9
10
  class Test::Unit::TestCase
10
11
  end
12
+
13
+ if RUBY_VERSION >= "1.9.2"
14
+ require 'coveralls'
15
+ Coveralls.wear!
16
+ end
17
+
@@ -11,94 +11,116 @@ require 'pcaprub'
11
11
  #
12
12
 
13
13
  class Pcap::UnitTest < Test::Unit::TestCase
14
+ def test_version
15
+ assert_equal(String, Pcap.version.class)
16
+ puts "Pcaprub version: #{Pcap.version}"
17
+ end
14
18
 
15
- def test_version
16
- assert_equal(String, Pcap.version.class)
17
- puts "Pcaprub version: #{Pcap.version}"
18
- end
19
-
20
- def test_lookupdev
21
- assert_equal(String, Pcap.lookupdev.class)
22
- puts "Pcaprub default device: #{Pcap.lookupdev}"
23
- end
24
-
25
- def test_lookupnet
26
- dev = Pcap.lookupdev
27
- assert_equal(Array, Pcap.lookupnet(dev).class)
28
- net = Pcap.lookupnet(dev)
29
- puts "Pcaprub net (#{dev}): #{net[0]} #{[net[1]].pack("N").unpack("H*")[0]}"
30
- end
31
-
32
- def test_pcap_new
33
- o = Pcap.new
34
- assert_equal(Pcap, o.class)
35
- end
36
-
37
- def test_pcap_setfilter_bad
38
- e = nil
39
- o = Pcap.new
40
- begin
41
- o.setfilter("not ip")
42
- rescue ::Exception => e
43
- end
44
-
45
- assert_equal(e.class, ArgumentError)
46
- end
47
-
48
- def test_pcap_setfilter
49
- d = Pcap.lookupdev
50
- o = Pcap.open_live(d, 65535, true, 1)
51
- r = o.setfilter("not ip")
52
- assert_equal(Pcap, r.class)
53
- end
54
-
55
- def test_pcap_inject
56
- d = Pcap.lookupdev
57
- o = Pcap.open_live(d, 65535, true, 1)
58
- r = o.inject("X" * 512)
59
- assert_equal(512, r)
60
- end
61
-
62
- def test_pcap_datalink
63
- d = Pcap.lookupdev
64
- o = Pcap.open_live(d, 65535, true, 1)
65
- r = o.datalink
66
- assert_equal(Fixnum, r.class)
67
- end
68
-
69
- def test_pcap_snapshot
70
- d = Pcap.lookupdev
71
- o = Pcap.open_live(d, 1344, true, 1)
72
- r = o.snapshot
73
- assert_equal(1344, r)
74
- end
75
-
76
- def test_pcap_stats
77
- d = Pcap.lookupdev
78
- o = Pcap.open_live(d, 1344, true, 1)
79
- r = o.stats
80
- assert_equal(Hash, r.class)
81
- end
82
-
83
- def test_pcap_next
84
- d = Pcap.lookupdev
85
- o = Pcap.open_live(d, 1344, true, 1)
86
-
87
- @c = 0
88
- t = Thread.new { while(true); @c += 1; select(nil, nil, nil, 0.10); end; }
89
-
90
- require 'timeout'
91
- begin
92
- Timeout.timeout(10) do
93
- o.each do |pkt|
94
- end
95
- end
96
- rescue ::Timeout::Error
97
- end
98
-
99
- t.kill
100
- puts "Background thread ticked #{@c} times while capture was running"
101
- true
102
- end
103
-
19
+ def test_lookupdev
20
+ assert_equal(String, Pcap.lookupdev.class)
21
+ puts "Pcaprub default device: #{Pcap.lookupdev}"
22
+ end
23
+
24
+ def test_lookupnet
25
+ dev = Pcap.lookupdev
26
+ assert_equal(Array, Pcap.lookupnet(dev).class)
27
+ net = Pcap.lookupnet(dev)
28
+ puts "Pcaprub net (#{dev}): #{net[0]} #{[net[1]].pack("N").unpack("H*")[0]}"
29
+ end
30
+
31
+ def test_pcap_new
32
+ o = Pcap.new
33
+ assert_equal(Pcap, o.class)
34
+ end
35
+
36
+ def test_pcap_setfilter_bad
37
+ e = nil
38
+ o = Pcap.new
39
+ begin
40
+ o.setfilter("not ip")
41
+ rescue ::Exception => e
42
+ end
43
+
44
+ assert_equal(e.class, PCAPRUB::PCAPRUBError)
45
+ end
46
+
47
+ def test_pcap_setfilter
48
+ d = Pcap.lookupdev
49
+ o = Pcap.open_live(d, 65535, true, 1)
50
+ r = o.setfilter("not ip")
51
+ assert_equal(Pcap, r.class)
52
+ end
53
+
54
+ def test_pcap_inject
55
+ d = Pcap.lookupdev
56
+ o = Pcap.open_live(d, 65535, true, 1)
57
+ r = o.inject("X" * 512)
58
+
59
+ # Travis CI's virtual network interface does not support injection
60
+ if ENV['CI']
61
+ assert_equal(-1,r)
62
+ else
63
+ assert_equal(512, r)
64
+ end
65
+ end
66
+
67
+ def test_pcap_datalink
68
+ d = Pcap.lookupdev
69
+ o = Pcap.open_live(d, 65535, true, 1)
70
+ r = o.datalink
71
+ assert_equal(Fixnum, r.class)
72
+ end
73
+
74
+ def test_pcap_snapshot
75
+ d = Pcap.lookupdev
76
+ o = Pcap.open_live(d, 1344, true, 1)
77
+ r = o.snapshot
78
+ assert_equal(1344, r)
79
+ end
80
+
81
+ def test_pcap_stats
82
+ d = Pcap.lookupdev
83
+ o = Pcap.open_live(d, 1344, true, 1)
84
+ r = o.stats
85
+ assert_equal(Hash, r.class)
86
+ end
87
+
88
+ def test_pcap_next
89
+ d = Pcap.lookupdev
90
+ o = Pcap.open_live(d, 1344, true, 1)
91
+
92
+ @c = 0
93
+ t = Thread.new { while(true); @c += 1; select(nil, nil, nil, 0.10); end; }
94
+
95
+ pkt_count = 0
96
+ require 'timeout'
97
+ begin
98
+ Timeout.timeout(10) do
99
+ o.each do |pkt|
100
+ pkt_count += 1
101
+ end
102
+ end
103
+ rescue ::Timeout::Error
104
+ end
105
+
106
+ t.kill
107
+ puts "Background thread ticked #{@c} times while capture was running"
108
+ puts "Captured #{pkt_count} packets"
109
+ assert(0 < @c, "Background thread failed to tick while capture was running");
110
+ true
111
+ end
112
+
113
+ def test_create_from_primitives
114
+ d = Pcap.lookupdev
115
+ o = Pcap.create(d).setsnaplen(65535).settimeout(100).setpromisc(true)
116
+ assert_equal(o, o.activate)
117
+ o.close
118
+ end
119
+
120
+ def test_monitor
121
+ return if RUBY_PLATFORM =~ /mingw|win/
122
+ d = Pcap.lookupdev
123
+ o = Pcap.create(d)
124
+ assert_equal(o, o.setmonitor(true))
125
+ end
104
126
  end
metadata CHANGED
@@ -1,30 +1,114 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pcaprub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3
5
- prerelease:
4
+ version: 0.12.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - shadowbq
8
+ - crondaemon
9
+ - jmcavinee
10
+ - unmarshal
9
11
  autorequire:
10
12
  bindir: bin
11
13
  cert_chain: []
12
- date: 2012-11-27 00:00:00.000000000 Z
13
- dependencies: []
14
- description: libpcap bindings for ruby compat with JRUBY Ruby1.8 Ruby1.9
14
+ date: 2014-08-10 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: bundler
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: !binary |-
23
+ MS4z
24
+ type: :development
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: !binary |-
31
+ MS4z
32
+ - !ruby/object:Gem::Dependency
33
+ name: rake
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: !binary |-
39
+ MC45LjI=
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: !binary |-
47
+ MC45LjI=
48
+ - !ruby/object:Gem::Dependency
49
+ name: rake-compiler
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: !binary |-
55
+ MC42LjA=
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: !binary |-
63
+ MC42LjA=
64
+ - !ruby/object:Gem::Dependency
65
+ name: shoulda-context
66
+ requirement: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: !binary |-
71
+ MS4xLjY=
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: !binary |-
79
+ MS4xLjY=
80
+ - !ruby/object:Gem::Dependency
81
+ name: minitest
82
+ requirement: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ~>
85
+ - !ruby/object:Gem::Version
86
+ version: !binary |-
87
+ NC43LjA=
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: !binary |-
95
+ NC43LjA=
96
+ description: libpcap bindings for ruby with Ruby1.8, Ruby1.9, Ruby 2.x
15
97
  email: shadowbq@gmail.com
16
98
  executables: []
17
99
  extensions:
18
- - ext/pcaprub/extconf.rb
100
+ - ext/pcaprub_c/extconf.rb
19
101
  extra_rdoc_files:
20
102
  - FAQ.rdoc
21
103
  - LICENSE
22
104
  - README.rdoc
23
105
  - USAGE.rdoc
24
- - ext/pcaprub/pcaprub.c
106
+ - ext/pcaprub_c/pcaprub.c
25
107
  files:
26
108
  - .document
109
+ - .travis.yml
27
110
  - FAQ.rdoc
111
+ - Gemfile
28
112
  - LICENSE
29
113
  - README.rdoc
30
114
  - Rakefile
@@ -33,38 +117,41 @@ files:
33
117
  - examples/file_cap.rb
34
118
  - examples/simple_cap.rb
35
119
  - examples/telnet-raw.pcap
36
- - ext/pcaprub/extconf.rb
37
- - ext/pcaprub/pcaprub.c
120
+ - ext/pcaprub_c/extconf.rb
121
+ - ext/pcaprub_c/pcaprub.c
38
122
  - lib/pcaprub.rb
39
123
  - lib/pcaprub/common.rb
40
124
  - lib/pcaprub/ext.rb
41
125
  - lib/pcaprub/version.rb
42
- - pcaprub.gemspec
43
126
  - test/helper.rb
44
127
  - test/test_pcaprub.rb
45
128
  - test/test_pcaprub_unit.rb
46
- homepage: http://github.com/shadowbq/pcaprub
47
- licenses: []
129
+ homepage: https://github.com/pcaprub/pcaprub
130
+ licenses:
131
+ - LGPL-2.1
132
+ metadata: {}
48
133
  post_install_message:
49
134
  rdoc_options: []
50
135
  require_paths:
51
136
  - lib
52
137
  required_ruby_version: !ruby/object:Gem::Requirement
53
- none: false
54
138
  requirements:
55
139
  - - ! '>='
56
140
  - !ruby/object:Gem::Version
57
141
  version: '0'
58
142
  required_rubygems_version: !ruby/object:Gem::Requirement
59
- none: false
60
143
  requirements:
61
144
  - - ! '>='
62
145
  - !ruby/object:Gem::Version
63
146
  version: '0'
64
- requirements: []
65
- rubyforge_project: pcaprub
66
- rubygems_version: 1.8.24
147
+ requirements:
148
+ - libpcap
149
+ rubyforge_project:
150
+ rubygems_version: 2.4.1
67
151
  signing_key:
68
- specification_version: 3
152
+ specification_version: 4
69
153
  summary: libpcap bindings for ruby
70
- test_files: []
154
+ test_files:
155
+ - test/helper.rb
156
+ - test/test_pcaprub.rb
157
+ - test/test_pcaprub_unit.rb
@@ -1,60 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "pcaprub"
8
- s.version = "0.11.3"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["shadowbq"]
12
- s.date = "2012-11-27"
13
- s.description = "libpcap bindings for ruby compat with JRUBY Ruby1.8 Ruby1.9"
14
- s.email = "shadowbq@gmail.com"
15
- s.extensions = ["ext/pcaprub/extconf.rb"]
16
- s.extra_rdoc_files = [
17
- "FAQ.rdoc",
18
- "LICENSE",
19
- "README.rdoc",
20
- "USAGE.rdoc",
21
- "ext/pcaprub/pcaprub.c"
22
- ]
23
- s.files = [
24
- ".document",
25
- "FAQ.rdoc",
26
- "LICENSE",
27
- "README.rdoc",
28
- "Rakefile",
29
- "USAGE.rdoc",
30
- "examples/dead_cap.rb",
31
- "examples/file_cap.rb",
32
- "examples/simple_cap.rb",
33
- "examples/telnet-raw.pcap",
34
- "ext/pcaprub/extconf.rb",
35
- "ext/pcaprub/pcaprub.c",
36
- "lib/pcaprub.rb",
37
- "lib/pcaprub/common.rb",
38
- "lib/pcaprub/ext.rb",
39
- "lib/pcaprub/version.rb",
40
- "pcaprub.gemspec",
41
- "test/helper.rb",
42
- "test/test_pcaprub.rb",
43
- "test/test_pcaprub_unit.rb"
44
- ]
45
- s.homepage = "http://github.com/shadowbq/pcaprub"
46
- s.require_paths = ["lib"]
47
- s.rubyforge_project = "pcaprub"
48
- s.rubygems_version = "1.8.24"
49
- s.summary = "libpcap bindings for ruby"
50
-
51
- if s.respond_to? :specification_version then
52
- s.specification_version = 3
53
-
54
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- else
56
- end
57
- else
58
- end
59
- end
60
-