dakrone-pcap-ffi 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,10 +2,7 @@ History.txt
2
2
  Manifest.txt
3
3
  Rakefile
4
4
  README.txt
5
- examples/print_bytes.rb
6
5
  lib/pcap.rb
7
- lib/pcap/exceptions.rb
8
- lib/pcap/exceptions/read_error.rb
9
6
  lib/pcap/typedefs.rb
10
7
  lib/pcap/time_val.rb
11
8
  lib/pcap/in_addr.rb
@@ -15,7 +12,6 @@ lib/pcap/if.rb
15
12
  lib/pcap/addr.rb
16
13
  lib/pcap/file_header.rb
17
14
  lib/pcap/packet_header.rb
18
- lib/pcap/packet.rb
19
15
  lib/pcap/packets.rb
20
16
  lib/pcap/packets/typedefs.rb
21
17
  lib/pcap/packets/ethernet.rb
@@ -23,18 +19,8 @@ lib/pcap/packets/ip.rb
23
19
  lib/pcap/packets/tcp.rb
24
20
  lib/pcap/stat.rb
25
21
  lib/pcap/data_link.rb
26
- lib/pcap/error_buffer.rb
27
22
  lib/pcap/handler.rb
28
23
  lib/pcap/dumper.rb
29
24
  lib/pcap/version.rb
30
25
  lib/pcap/ffi.rb
31
26
  lib/pcap/pcap.rb
32
- tasks/spec.rb
33
- spec/spec_helper.rb
34
- spec/helpers/dumps.rb
35
- spec/dumps/simple_tcp.pcap
36
- spec/error_buffer.rb
37
- spec/data_link_spec.rb
38
- spec/handler_examples.rb
39
- spec/handler_spec.rb
40
- spec/pcap_spec.rb
data/Rakefile CHANGED
@@ -2,17 +2,22 @@
2
2
 
3
3
  require 'rubygems'
4
4
  require './lib/pcap/version.rb'
5
- require './tasks/spec.rb'
5
+
6
+ #Hoe.new('pcap-ffi', FFI::PCap::VERSION) do |p|
7
+ #p.rubyforge_name = 'pcap-ffi'
8
+ #p.developer('Postmodern','postmodern.mod3@gmail.com')
9
+ #p.remote_rdoc_dir = ''
10
+ #p.extra_deps = [['ffi', '>=0.4.0']]
11
+ #end
6
12
 
7
13
  # Generate a gem using jeweler
8
14
  begin
9
15
  require 'jeweler'
10
16
  Jeweler::Tasks.new do |gemspec|
11
- gemspec.rubyforge_project = 'pcap-ffi'
12
17
  gemspec.name = "pcap-ffi"
13
18
  gemspec.summary = "FFI bindings for libpcap"
14
- gemspec.email = "postmodern.mod3@gmail.com"
15
- gemspec.homepage = "http://github.com/postmodern/pcap-ffi"
19
+ gemspec.email = "lee@writequit.org"
20
+ gemspec.homepage = "http://github.com/dakrone/pcap-ffi"
16
21
  gemspec.description = "Bindings to sniff packets using the FFI interface in Ruby."
17
22
  gemspec.authors = ["Postmodern, Dakrone"]
18
23
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -6,32 +6,19 @@ module FFI
6
6
  module PCap
7
7
  class Dumper < FFI::MemoryPointer
8
8
 
9
- def initialize(dumper)
10
- @dumper = dumper
11
- end
12
-
13
- def write(header,bytes)
14
- PCap.pcap_dump(@dumper,header,bytes)
9
+ def self.open(path)
15
10
  end
16
11
 
17
12
  def tell
18
- PCap.pcap_dump_ftell(@dumper)
13
+ PCap.pcap_dump_ftell(self)
19
14
  end
20
15
 
21
16
  def flush
22
- PCap.pcap_dump_flush(@dumper)
17
+ PCap.pcap_dump_flush(self)
23
18
  end
24
19
 
25
20
  def close
26
- PCap.pcap_dump_close(@dumper)
27
- end
28
-
29
- def to_ptr
30
- @dumper
31
- end
32
-
33
- def inspect
34
- "#<#{self.class}: 0x#{@dumper.address.to_s(16)}>"
21
+ PCap.pcap_dump_close(self)
35
22
  end
36
23
 
37
24
  end
@@ -1,5 +1,3 @@
1
- require 'pcap/typedefs'
2
-
3
1
  require 'ffi'
4
2
 
5
3
  module FFI
@@ -8,6 +6,8 @@ module FFI
8
6
 
9
7
  ffi_lib 'libpcap'
10
8
 
9
+ ERRBUF_SIZE = 256
10
+
11
11
  enum :pcap_direction, [
12
12
  :pcap_d_inout,
13
13
  :pcap_d_in,
@@ -16,11 +16,11 @@ module FFI
16
16
 
17
17
  callback :pcap_handler, [:pointer, :pointer, :pointer], :void
18
18
 
19
- attach_function :pcap_lookupdev, [:pointer], :string
20
- attach_function :pcap_lookupnet, [:string, :pointer, :pointer, :pointer], :int
21
- attach_function :pcap_open_live, [:string, :int, :int, :int, :pointer], :pointer
19
+ attach_function :pcap_lookupdev, [:string], :string
20
+ attach_function :pcap_lookupnet, [:string, :pointer, :pointer, :string], :int
21
+ attach_function :pcap_open_live, [:string, :int, :int, :int, :string], :pointer
22
22
  attach_function :pcap_open_dead, [:int, :int], :pointer
23
- attach_function :pcap_open_offline, [:string, :pointer], :pointer
23
+ attach_function :pcap_open_offline, [:string, :string], :pointer
24
24
  attach_function :pcap_fopen_offline, [:pointer, :string], :pointer
25
25
  attach_function :pcap_close, [:pointer], :void
26
26
  attach_function :pcap_loop, [:pointer, :int, :pcap_handler, :pointer], :int
@@ -30,9 +30,9 @@ module FFI
30
30
  attach_function :pcap_breakloop, [:pointer], :void
31
31
  attach_function :pcap_stats, [:pointer, :pointer], :int
32
32
  attach_function :pcap_setfilter, [:pointer, :pointer], :int
33
- attach_function :pcap_setdirection, [:pointer, :pcap_direction], :int
34
- attach_function :pcap_getnonblock, [:pointer, :pointer], :int
35
- attach_function :pcap_setnonblock, [:pointer, :int, :pointer], :int
33
+ attach_function :pcap_setdirection, [:pointer, :pcap_direction_t], :int
34
+ attach_function :pcap_getnonblock, [:pointer, :string], :int
35
+ attach_function :pcap_setnonblock, [:pointer, :int, :string], :int
36
36
  attach_function :pcap_perror, [:pointer, :string], :void
37
37
  attach_function :pcap_inject, [:pointer, :pointer, :int], :int
38
38
  attach_function :pcap_sendpacket, [:pointer, :pointer, :int], :int
@@ -63,7 +63,7 @@ module FFI
63
63
  attach_function :pcap_dump_close, [:pointer], :void
64
64
  attach_function :pcap_dump, [:pointer, :pointer, :pointer], :void
65
65
 
66
- attach_function :pcap_findalldevs, [:pointer, :pointer], :int
66
+ attach_function :pcap_findalldevs, [:pointer, :string], :int
67
67
  attach_function :pcap_freealldevs, [:pointer], :void
68
68
 
69
69
  attach_function :pcap_lib_version, [], :string
@@ -1,9 +1,5 @@
1
- require 'pcap/exceptions/read_error'
2
1
  require 'pcap/ffi'
3
- require 'pcap/error_buffer'
4
2
  require 'pcap/data_link'
5
- require 'pcap/packet_header'
6
- require 'pcap/stat'
7
3
 
8
4
  require 'ffi'
9
5
 
@@ -22,26 +18,8 @@ module FFI
22
18
  # Number of packets to sniff
23
19
  attr_accessor :count
24
20
 
25
- def initialize(pcap,options={},&block)
21
+ def initialize(pcap)
26
22
  @pcap = pcap
27
- @closed = false
28
-
29
- # Default is to infinitely loop over packets.
30
- @count = (options[:count] || -1)
31
-
32
- if options[:direction]
33
- self.direction = options[:direction]
34
- end
35
-
36
- @callback_wrapper = Proc.new do |user,header,bytes|
37
- if @callback
38
- @callback.call(user,PacketHeader.new(header),bytes)
39
- end
40
- end
41
-
42
- callback(&block)
43
-
44
- trap('SIGINT') { self.close }
45
23
  end
46
24
 
47
25
  def datalink
@@ -49,120 +27,48 @@ module FFI
49
27
  end
50
28
 
51
29
  def callback(&block)
52
- @callback = block
53
- return @callback
54
- end
55
-
56
- def direction=(dir)
57
- directions = PCap.enum_type(:pcap_direction)
58
-
59
- return PCap.pcap_setdirection(@pcap,directions[:"pcap_d_#{dir}"])
60
- end
61
-
62
- def non_blocking=(mode)
63
- errbuf = ErrorBuffer.new
64
- mode = if mode
65
- 1
66
- else
67
- 0
68
- end
69
-
70
- if PCap.pcap_setnonblock(@pcap,mode,errbuf) == -1
71
- raise(RuntimeError,errbuf.to_s,caller)
30
+ if block
31
+ @callback = block
72
32
  end
73
33
 
74
- return mode == 1
34
+ return @callback
75
35
  end
76
36
 
77
- def non_blocking?
78
- errbuf = ErrorBuffer.new
79
- mode = PCap.pcap_getnonblock(@pcap,errbuf)
80
-
81
- if mode == -1
82
- raise(RuntimeError,errbuf.to_s,caller)
83
- end
84
-
85
- return mode == 1
37
+ def direction=(dir)
38
+ PCap.pcap_setdirection(@pcap,dir)
86
39
  end
87
40
 
88
- def loop(data=nil,&block)
41
+ def loop(data,&block)
89
42
  callback(&block) if block
90
43
 
91
- PCap.pcap_loop(@pcap,@count,@callback_wrapper,data)
44
+ PCap.pcap_loop(@pcap,@count,@callback,data)
92
45
  end
93
46
 
94
- alias each loop
47
+ alias :each :loop
95
48
 
96
- def dispatch(data=nil,&block)
49
+ def dispatch(data,&block)
97
50
  callback(&block) if block
98
51
 
99
- return PCap.pcap_dispatch(@pcap,@count,@callback_wrapper,data)
52
+ PCap.pcap_dispatch(@pcap,@count,@callback,data)
100
53
  end
101
54
 
102
55
  def next
103
56
  header = PacketHeader.new
104
57
  data = PCap.pcap_next(@pcap,header)
105
58
 
106
- return [nil, nil] if data.null?
107
59
  return [header, data]
108
60
  end
109
61
 
110
- def next_extra
111
- header_ptr = MemoryPointer.new(:pointer)
112
- data_ptr = MemoryPointer.new(:pointer)
113
-
114
- case PCap.pcap_next_ex(@pcap,header_ptr,data_ptr)
115
- when -1
116
- raise(ReadError,"an error occurred while reading the packet",caller)
117
- when -2
118
- raise(ReadError,"the 'savefile' contains no more packets",caller)
119
- end
120
-
121
- return [header_ptr.get_pointer(0), data_ptr.get_pointer(0)]
122
- end
123
-
124
- def open_dump(path)
125
- dump_ptr = PCap.pcap_dump_open(@pcap,File.expand_path(path))
126
-
127
- if dump_ptr.null?
128
- raise(RuntimeError,error,caller)
129
- end
130
-
131
- return Dumper.new(dump_ptr)
132
- end
133
-
134
- def stats
135
- stats = Stat.new
136
-
137
- PCap.pcap_stats(@pcap,stats)
138
- return stats
139
- end
140
-
141
- def error
142
- PCap.pcap_geterr(@pcap)
143
- end
144
-
145
62
  def stop
146
63
  PCap.pcap_breakloop(@pcap)
147
64
  end
148
65
 
149
- def closed?
150
- @closed == true
151
- end
152
-
153
66
  def close
154
- unless @closed
155
- @closed = true
156
- PCap.pcap_close(@pcap)
157
- end
158
- end
159
-
160
- def to_ptr
161
- @pcap
67
+ PCap.pcap_close(@pcap)
162
68
  end
163
69
 
164
70
  def inspect
165
- "#<#{self.class}: 0x#{@pcap.address.to_s(16)}>"
71
+ "#<#{self.class}: 0x#{@pcap.to_s(16)}>"
166
72
  end
167
73
 
168
74
  end
@@ -19,18 +19,10 @@ module FFI
19
19
  IF.new(self[:next])
20
20
  end
21
21
 
22
- def name
23
- self[:name]
24
- end
25
-
26
22
  def addresses
27
23
  Addr.new(self[:addresses])
28
24
  end
29
25
 
30
- def to_s
31
- self[:name]
32
- end
33
-
34
26
  end
35
27
  end
36
28
  end
@@ -9,18 +9,6 @@ module FFI
9
9
  layout :ts, TimeVal,
10
10
  :caplen, :bpf_uint32,
11
11
  :len, :bpf_uint32
12
-
13
- def timestamp
14
- self[:ts]
15
- end
16
-
17
- def captured
18
- self[:caplen]
19
- end
20
-
21
- def length
22
- self[:len]
23
- end
24
12
  end
25
13
  end
26
14
  end
@@ -1,5 +1,4 @@
1
1
  require 'pcap/packets/typedefs'
2
- require 'pcap/packet'
3
2
 
4
3
  require 'ffi'
5
4
 
@@ -8,8 +7,6 @@ module FFI
8
7
  module Packets
9
8
  class Ethernet < FFI::Struct
10
9
 
11
- include Packet
12
-
13
10
  # Number of bytes for an ethernet address
14
11
  ADDR_LEN = 6
15
12
 
@@ -1,4 +1,3 @@
1
- require 'pcap/packet'
2
1
  require 'pcap/in_addr'
3
2
 
4
3
  require 'ffi'
@@ -8,8 +7,6 @@ module FFI
8
7
  module Packets
9
8
  class IPv4 < FFI::Struct
10
9
 
11
- include Packet
12
-
13
10
  # IPv4 flags
14
11
  FLAGS = [
15
12
  # Reserved fragment flag
@@ -1,5 +1,4 @@
1
1
  require 'pcap/packets/typedefs'
2
- require 'pcap/packet'
3
2
 
4
3
  require 'ffi'
5
4
 
@@ -8,8 +7,6 @@ module FFI
8
7
  module Packets
9
8
  class TCP < FFI::Struct
10
9
 
11
- include Packet
12
-
13
10
  # TCP flags
14
11
  FLAGS = [
15
12
  # Null flags
@@ -1,85 +1,33 @@
1
1
  require 'pcap/ffi'
2
2
  require 'pcap/data_link'
3
- require 'pcap/if'
4
3
  require 'pcap/handler'
5
- require 'pcap/error_buffer'
6
4
 
7
5
  module FFI
8
6
  module PCap
9
- def PCap.lib_version
10
- PCap.pcap_lib_version
11
- end
12
-
13
- def PCap.device
14
- errbuf = ErrorBuffer.new
15
-
16
- unless (name = PCap.pcap_lookupdev(errbuf))
17
- raise(StandardError,errbuf.to_s,caller)
18
- end
19
-
20
- return name
21
- end
22
-
23
- def PCap.each_device(&block)
24
- devices = MemoryPointer.new(:pointer)
25
- errbuf = ErrorBuffer.new
26
-
27
- PCap.pcap_findalldevs(devices,errbuf)
28
- node = devices.get_pointer(0)
29
-
30
- if node.null?
31
- raise(StandardError,errbuf.to_s,caller)
32
- end
33
-
34
- device = IF.new(node)
35
-
36
- until device
37
- block.call(device) if block
38
- device = device.next
39
- end
40
-
41
- PCap.pcap_freealldevs(node)
42
- return nil
43
- end
44
-
45
- def PCap.open_live(options={},&block)
7
+ def PCap.open_live(options={})
46
8
  device = options[:device]
47
9
  promisc = if options[:promisc]
48
10
  1
49
11
  else
50
12
  0
51
13
  end
52
- snaplen = (options[:snaplen] || Handler::SNAPLEN)
14
+ snaplen = (options[:snaplen] || SNAPLEN)
53
15
  to_ms = (options[:timeout] || 0)
54
- errbuf = ErrorBuffer.new
55
16
 
56
17
  ptr = PCap.pcap_open_live(device,snaplen,promisc,to_ms,nil)
57
18
 
58
- if ptr.null?
59
- raise(StandardError,errbuf.to_s,caller)
19
+ unless ptr
20
+ raise(StandardError,errbuf,caller)
60
21
  end
61
22
 
62
- return Handler.new(ptr,options,&block)
23
+ return Handler.new(ptr)
63
24
  end
64
25
 
65
- def PCap.open_dead(datalink,options={})
26
+ def self.open_dead(datalink,snaplen=SNAPLEN)
66
27
  datalink = DataLink[datalink]
67
- snaplen = (options[:snaplen] || Handler::SNAPLEN)
68
28
 
69
- return Handler.new(PCap.pcap_open_dead(datalink,snaplen),options)
29
+ return Handler.new(PCap.pcap_open_dead(datalink,snaplen))
70
30
  end
71
31
 
72
- def PCap.open_offline(path,options={})
73
- path = File.expand_path(path)
74
- errbuf = ErrorBuffer.new
75
-
76
- ptr = PCap.pcap_open_offline(path,errbuf)
77
-
78
- if ptr.null?
79
- raise(StandardError,errbuf.to_s,caller)
80
- end
81
-
82
- return Handler.new(ptr,options)
83
- end
84
32
  end
85
33
  end
@@ -6,18 +6,6 @@ module FFI
6
6
  layout :ps_recv, :uint,
7
7
  :ps_drop, :uint,
8
8
  :ps_ifdrop, :uint
9
-
10
- def received
11
- self[:ps_recv]
12
- end
13
-
14
- def dropped
15
- self[:ps_drop]
16
- end
17
-
18
- def interface_dropped
19
- self[:ps_ifdrop]
20
- end
21
9
  end
22
10
  end
23
11
  end
@@ -16,14 +16,6 @@ module FFI
16
16
  self[:tv_usec]
17
17
  end
18
18
 
19
- def to_time
20
- Time.at(self[:tv_sec],self[:tv_usec])
21
- end
22
-
23
- def to_s
24
- to_time.to_s
25
- end
26
-
27
19
  end
28
20
  end
29
21
  end
@@ -1,4 +1,3 @@
1
- require 'rubygems'
2
1
  require 'ffi'
3
2
 
4
3
  module FFI
@@ -13,4 +12,5 @@ module FFI
13
12
  alias_type :uint32, :in_addr_t
14
13
  alias_type :int, :bpf_int32
15
14
  alias_type :uint, :bpf_uint32
15
+ alias_type :int, :pcap_direction_t
16
16
  end
@@ -2,13 +2,13 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{pcap-ffi}
5
- s.version = "0.0.0"
5
+ s.version = "0.0.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Postmodern, Dakrone"]
9
- s.date = %q{2009-05-27}
9
+ s.date = %q{2009-05-24}
10
10
  s.description = %q{Bindings to sniff packets using the FFI interface in Ruby.}
11
- s.email = %q{postmodern.mod3@gmail.com}
11
+ s.email = %q{lee@writequit.org}
12
12
  s.extra_rdoc_files = [
13
13
  "README.txt"
14
14
  ]
@@ -19,14 +19,10 @@ Gem::Specification.new do |s|
19
19
  "README.txt",
20
20
  "Rakefile",
21
21
  "VERSION",
22
- "examples/print_bytes.rb",
23
22
  "lib/pcap.rb",
24
23
  "lib/pcap/addr.rb",
25
24
  "lib/pcap/data_link.rb",
26
25
  "lib/pcap/dumper.rb",
27
- "lib/pcap/error_buffer.rb",
28
- "lib/pcap/exceptions.rb",
29
- "lib/pcap/exceptions/read_error.rb",
30
26
  "lib/pcap/ffi.rb",
31
27
  "lib/pcap/file_header.rb",
32
28
  "lib/pcap/handler.rb",
@@ -45,38 +41,17 @@ Gem::Specification.new do |s|
45
41
  "lib/pcap/time_val.rb",
46
42
  "lib/pcap/typedefs.rb",
47
43
  "lib/pcap/version.rb",
48
- "pcap-ffi.gemspec",
49
- "spec/data_link_spec.rb",
50
- "spec/dumps/simple_tcp.pcap",
51
- "spec/error_buffer.rb",
52
- "spec/handler_examples.rb",
53
- "spec/handler_spec.rb",
54
- "spec/helpers/dumps.rb",
55
- "spec/pcap_spec.rb",
56
- "spec/spec_helper.rb",
57
- "tasks/spec.rb"
44
+ "pcap-ffi.gemspec"
58
45
  ]
59
- s.has_rdoc = true
60
- s.homepage = %q{http://github.com/postmodern/pcap-ffi}
46
+ s.homepage = %q{http://github.com/dakrone/pcap-ffi}
61
47
  s.rdoc_options = ["--charset=UTF-8"]
62
48
  s.require_paths = ["lib"]
63
- s.rubyforge_project = %q{pcap-ffi}
64
- s.rubygems_version = %q{1.3.1}
49
+ s.rubygems_version = %q{1.3.3}
65
50
  s.summary = %q{FFI bindings for libpcap}
66
- s.test_files = [
67
- "spec/pcap_spec.rb",
68
- "spec/data_link_spec.rb",
69
- "spec/error_buffer.rb",
70
- "spec/spec_helper.rb",
71
- "spec/handler_spec.rb",
72
- "spec/handler_examples.rb",
73
- "spec/helpers/dumps.rb",
74
- "examples/print_bytes.rb"
75
- ]
76
51
 
77
52
  if s.respond_to? :specification_version then
78
53
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
79
- s.specification_version = 2
54
+ s.specification_version = 3
80
55
 
81
56
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
82
57
  else
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dakrone-pcap-ffi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern, Dakrone
@@ -9,12 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-05-27 00:00:00 -07:00
12
+ date: 2009-05-24 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
16
  description: Bindings to sniff packets using the FFI interface in Ruby.
17
- email: postmodern.mod3@gmail.com
17
+ email: lee@writequit.org
18
18
  executables: []
19
19
 
20
20
  extensions: []
@@ -28,14 +28,10 @@ files:
28
28
  - README.txt
29
29
  - Rakefile
30
30
  - VERSION
31
- - examples/print_bytes.rb
32
31
  - lib/pcap.rb
33
32
  - lib/pcap/addr.rb
34
33
  - lib/pcap/data_link.rb
35
34
  - lib/pcap/dumper.rb
36
- - lib/pcap/error_buffer.rb
37
- - lib/pcap/exceptions.rb
38
- - lib/pcap/exceptions/read_error.rb
39
35
  - lib/pcap/ffi.rb
40
36
  - lib/pcap/file_header.rb
41
37
  - lib/pcap/handler.rb
@@ -55,17 +51,8 @@ files:
55
51
  - lib/pcap/typedefs.rb
56
52
  - lib/pcap/version.rb
57
53
  - pcap-ffi.gemspec
58
- - spec/data_link_spec.rb
59
- - spec/dumps/simple_tcp.pcap
60
- - spec/error_buffer.rb
61
- - spec/handler_examples.rb
62
- - spec/handler_spec.rb
63
- - spec/helpers/dumps.rb
64
- - spec/pcap_spec.rb
65
- - spec/spec_helper.rb
66
- - tasks/spec.rb
67
- has_rdoc: true
68
- homepage: http://github.com/postmodern/pcap-ffi
54
+ has_rdoc: false
55
+ homepage: http://github.com/dakrone/pcap-ffi
69
56
  post_install_message:
70
57
  rdoc_options:
71
58
  - --charset=UTF-8
@@ -85,17 +72,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
72
  version:
86
73
  requirements: []
87
74
 
88
- rubyforge_project: pcap-ffi
75
+ rubyforge_project:
89
76
  rubygems_version: 1.2.0
90
77
  signing_key:
91
- specification_version: 2
78
+ specification_version: 3
92
79
  summary: FFI bindings for libpcap
93
- test_files:
94
- - spec/pcap_spec.rb
95
- - spec/data_link_spec.rb
96
- - spec/error_buffer.rb
97
- - spec/spec_helper.rb
98
- - spec/handler_spec.rb
99
- - spec/handler_examples.rb
100
- - spec/helpers/dumps.rb
101
- - examples/print_bytes.rb
80
+ test_files: []
81
+
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- require 'pcap'
5
-
6
- include FFI
7
-
8
- pcap = PCap.open_live(:device => ARGV[0]) do |user,header,bytes|
9
- puts "#{header.timestamp}:"
10
-
11
- header.captured.times { |i|
12
- print ' %.2x' % bytes.get_uchar(i)
13
- }
14
- putc "\n"
15
- end
16
-
17
- pcap.loop
@@ -1,26 +0,0 @@
1
- require 'ffi'
2
-
3
- module FFI
4
- module PCap
5
- class ErrorBuffer < FFI::Buffer
6
-
7
- # Size of the error buffers
8
- SIZE = 256
9
-
10
- #
11
- # Creates a new ErrorBuffer object.
12
- #
13
- def initialize
14
- super(SIZE)
15
- end
16
-
17
- #
18
- # Returns the error message within the error buffer.
19
- #
20
- def to_s
21
- get_string(SIZE)
22
- end
23
-
24
- end
25
- end
26
- end
@@ -1 +0,0 @@
1
- require 'pcap/exceptions/read_error'
@@ -1,6 +0,0 @@
1
- module FFI
2
- module PCap
3
- class ReadError < RuntimeError
4
- end
5
- end
6
- end
@@ -1,29 +0,0 @@
1
- require 'pcap/data_link'
2
-
3
- require 'spec_helper'
4
-
5
- describe DataLink do
6
- before(:all) do
7
- @datalink = DataLink.new(0)
8
- end
9
-
10
- it "should be initialized from a pcap datalink value" do
11
- @datalink.name.should == 'NULL'
12
- end
13
-
14
- it "should map datalink names to pcap datalink values" do
15
- DataLink[:en10mb].should == 1
16
- end
17
-
18
- it "should have a description" do
19
- @datalink.description.should_not be_empty
20
- end
21
-
22
- it "should be able to convert to an Integer" do
23
- @datalink.to_i.should == 0
24
- end
25
-
26
- it "should be able to convert to a String" do
27
- @datalink.to_s.should == 'NULL'
28
- end
29
- end
Binary file
@@ -1,18 +0,0 @@
1
- require 'pcap/error_buffer'
2
-
3
- require 'spec_helper'
4
-
5
- describe PCap::ErrorBuffer do
6
- before(:all) do
7
- @errbuf = PCap::ErrorBuffer.new
8
- end
9
-
10
- it "should have a size of 256" do
11
- @errbuf.size.should == 256
12
- end
13
-
14
- it "should return the error message for to_s" do
15
- @errbuf.write_string('test')
16
- @errbuf.to_s.should == 'test'
17
- end
18
- end
@@ -1,71 +0,0 @@
1
- require 'pcap/handler'
2
-
3
- require 'spec_helper'
4
-
5
- shared_examples_for "Handler" do
6
- it "must have a datalink" do
7
- datalink = @pcap.datalink
8
-
9
- datalink.value.should_not be_nil
10
- datalink.name.should_not be_empty
11
- end
12
-
13
- it "should pass packets to a callback" do
14
- @pcap.callback do |user,header,bytes|
15
- header.captured.should_not == 0
16
- header.length.should_not == 0
17
-
18
- bytes.should_not be_null
19
- end
20
-
21
- @pcap.loop
22
- end
23
-
24
- it "should be able to get the next packet" do
25
- header, data = @pcap.next
26
-
27
- header.should_not be_nil
28
- header.captured.should_not == 0
29
- header.length.should_not == 0
30
-
31
- data.should_not be_nil
32
- data.should_not be_null
33
- end
34
-
35
- it "should be able to open a dump file" do
36
- lambda {
37
- dumper = @pcap.open_dump(Tempfile.new.path)
38
- dumper.close
39
- }.should_not raise_error(RuntimeError)
40
- end
41
-
42
- it "should raise an exception when opening a bad dump file" do
43
- lambda {
44
- @pcap.open_dump(File.join('','obviously','not','there'))
45
- }.should raise_error(RuntimeError)
46
- end
47
-
48
- it "should return an empty String when an error has not occurred" do
49
- @pcap.error.should be_empty
50
- end
51
-
52
- it "should be able to break out of the Handler#loop" do
53
- stopped = false
54
-
55
- @pcap.loop do |user,pkthdr,bytes|
56
- stopped = true
57
- @pcap.stop
58
- end
59
-
60
- stopped.should == true
61
- end
62
-
63
- it "should prevent double closes" do
64
- @pcap.close
65
- @pcap.should be_closed
66
-
67
- lambda {
68
- @pcap.close
69
- }.should_not raise_error(StandardError)
70
- end
71
- end
@@ -1,80 +0,0 @@
1
- require 'pcap/handler'
2
-
3
- require 'spec_helper'
4
- require 'helpers/dumps'
5
- require 'handler_examples'
6
-
7
- describe PCap::Handler do
8
- describe "offline" do
9
- before(:each) do
10
- @pcap = PCap.open_offline(dump_path('simple_tcp'))
11
- end
12
-
13
- after(:each) do
14
- @pcap.close
15
- end
16
-
17
- it_should_behave_like "Handler"
18
-
19
- it "should not support non-blocking mode" do
20
- @pcap.non_blocking = true
21
- @pcap.should_not be_non_blocking
22
- end
23
-
24
- it "should return a nil if there are no packets left in the dump file" do
25
- @pcap.loop
26
-
27
- header, data = @pcap.next
28
-
29
- header.should be_nil
30
- data.should be_nil
31
- end
32
-
33
- it "should raise a ReadError when reading past the end of a dump file" do
34
- @pcap.loop
35
-
36
- lambda {
37
- @pcap.next_extra
38
- }.should raise_error(ReadError)
39
- end
40
- end
41
-
42
- describe "live" do
43
- before(:each) do
44
- @pcap = PCap.open_live(:count => 2)
45
- end
46
-
47
- after(:each) do
48
- @pcap.close
49
- end
50
-
51
- it_should_behave_like "Handler"
52
-
53
- it "should support non-blocking mode" do
54
- @pcap.non_blocking = true
55
- @pcap.should be_non_blocking
56
- end
57
-
58
- it "should provide statistics about packets received/dropped" do
59
- @pcap.loop
60
-
61
- stats = @pcap.stats
62
- stats.received.should > 0
63
- end
64
- end
65
-
66
- describe "dead" do
67
- before(:each) do
68
- @pcap = PCap.open_dead
69
- end
70
-
71
- after(:each) do
72
- @pcap.close
73
- end
74
-
75
- it "should support non-blocking mode" do
76
- @pcap.non_blocking = true
77
- @pcap.should be_non_blocking
78
- end
79
- end
80
- end
@@ -1,3 +0,0 @@
1
- def dump_path(name)
2
- File.expand_path(File.join(File.dirname(__FILE__),'..','dumps',"#{name}.pcap"))
3
- end
@@ -1,51 +0,0 @@
1
- require 'pcap/pcap'
2
- require 'pcap/version'
3
-
4
- require 'spec_helper'
5
- require 'helpers/dumps'
6
-
7
- describe PCap do
8
- it "should define a VERSION constant" do
9
- PCap.const_defined?('VERSION').should == true
10
- end
11
-
12
- it "should have a library version" do
13
- PCap.lib_version.should_not be_empty
14
- end
15
-
16
- it "should return the name of a device suitable for open_live" do
17
- dev = PCap.device
18
-
19
- dev.should_not be_nil
20
- dev.should_not be_empty
21
- end
22
-
23
- it "should enumerate over all usable devices" do
24
- PCap.each_device do |dev|
25
- dev.should_not be_nil
26
- dev.should_not be_null
27
- dev.class.should == PCap::IF
28
- end
29
- end
30
-
31
- it "should be able to open a live pcap handler" do
32
- lambda {
33
- pcap = PCap.open_live
34
- pcap.close
35
- }.should_not raise_error(StandardError)
36
- end
37
-
38
- it "should be able to open a dead pcap handler" do
39
- lambda {
40
- pcap = PCap.open_dead('null')
41
- pcap.close
42
- }.should_not raise_error(StandardError)
43
- end
44
-
45
- it "should be able to open a pcap dump file" do
46
- lambda {
47
- pcap = PCap.open_offline(dump_path('simple_tcp'))
48
- pcap.close
49
- }.should_not raise_error(StandardError)
50
- end
51
- end
@@ -1,8 +0,0 @@
1
- require 'rubygems'
2
- gem 'rspec', '>=1.1.12'
3
- require 'spec'
4
-
5
- require 'pcap/version'
6
-
7
- include FFI
8
- include FFI::PCap
@@ -1,9 +0,0 @@
1
- require 'spec/rake/spectask'
2
-
3
- desc "Run all specifications"
4
- Spec::Rake::SpecTask.new(:spec) do |t|
5
- t.libs += ['lib', 'spec']
6
- t.spec_opts = ['--colour', '--format', 'specdoc']
7
- end
8
-
9
- task :default => :spec