pcaprub 0.13.2 → 0.13.3
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/extconf.rb +12 -2
- data/ext/pcaprub_c/pcaprub.c +10 -7
- data/lib/pcaprub/version.rb +1 -1
- data/lib/pcaprub.rb +25 -1
- data/test/test_pcaprub_unit.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c07274578544377dda665e39affdcb19979c7497887ce37f807390c3cdb3ff8
|
4
|
+
data.tar.gz: eb637469104d446bacebae7c670e0dea91621bbc27f99e35c9bbeadbe09c78bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a816e68c66133672c2e33f2800130fecd3570345dd59bd9da5d068d0b2dee6b64a63bdd32418c327638e978e8120f5b9be30be8ac0e34d51d27badbb4bbf4168
|
7
|
+
data.tar.gz: 5c8b31ca16e5d34dec166fa5cacedb976285b0b7ccf8ddf42d9da1d3c9ab4c30058e6cc7fcb8a53bab9de9bde2c448eb974682bcc7af9e895b9b907071474937
|
data/ext/pcaprub_c/extconf.rb
CHANGED
@@ -3,6 +3,10 @@ extension_name = 'pcaprub_c'
|
|
3
3
|
|
4
4
|
puts "\n[*] Running checks for #{extension_name} code..."
|
5
5
|
puts("platform is #{RUBY_PLATFORM}")
|
6
|
+
default_npcap_sdk = 'C:/npcap-sdk'
|
7
|
+
default_winpcap_sdk = 'C:/WpdPack'
|
8
|
+
# Default to npcap if it exists, otherwise fallback to winpcap
|
9
|
+
default_pcap_sdk = File.directory?(default_npcap_sdk) ? default_npcap_sdk : default_winpcap_sdk
|
6
10
|
|
7
11
|
if /i386-mingw32/ =~ RUBY_PLATFORM || /x64-mingw32/ =~ RUBY_PLATFORM || /x64-mingw-ucrt/ =~ RUBY_PLATFORM
|
8
12
|
unless have_library("ws2_32" ) and
|
@@ -14,7 +18,7 @@ if /i386-mingw32/ =~ RUBY_PLATFORM || /x64-mingw32/ =~ RUBY_PLATFORM || /x64-min
|
|
14
18
|
exit
|
15
19
|
end
|
16
20
|
|
17
|
-
pcap_dir = with_config("pcap-dir",
|
21
|
+
pcap_dir = with_config("pcap-dir", default_pcap_sdk)
|
18
22
|
pcap_includedir = with_config("pcap-includedir", pcap_dir + "/include")
|
19
23
|
pcap_libdir = with_config("pcap-libdir", pcap_dir + "/lib")
|
20
24
|
|
@@ -28,12 +32,15 @@ if /i386-mingw32/ =~ RUBY_PLATFORM || /x64-mingw32/ =~ RUBY_PLATFORM || /x64-min
|
|
28
32
|
$LDFLAGS += " -g" if with_config("debug")
|
29
33
|
|
30
34
|
have_header("ruby/thread.h")
|
35
|
+
if have_header(pcap_includedir + "/Win32-Extensions.h", pcap_includedir + "/pcap.h")
|
36
|
+
append_cflags("-DHAVE_WIN32_EXTENSIONS_H")
|
37
|
+
end
|
31
38
|
have_func("rb_thread_blocking_region") # Pre ruby 2.2
|
32
39
|
have_func("rb_thread_call_without_gvl") # Post ruby 2.2
|
33
40
|
have_library("wpcap", "pcap_open_live")
|
34
41
|
have_library("wpcap", "pcap_setnonblock")
|
35
42
|
elsif /i386-mswin32/ =~ RUBY_PLATFORM || /x64-mswin32/ =~ RUBY_PLATFORM
|
36
|
-
pcap_dir = with_config("pcap-dir",
|
43
|
+
pcap_dir = with_config("pcap-dir", default_pcap_sdk)
|
37
44
|
pcap_includedir = with_config("pcap-includedir", pcap_dir + "\\include")
|
38
45
|
pcap_libdir = with_config("pcap-libdir", pcap_dir + "\\lib")
|
39
46
|
|
@@ -46,6 +53,9 @@ elsif /i386-mswin32/ =~ RUBY_PLATFORM || /x64-mswin32/ =~ RUBY_PLATFORM
|
|
46
53
|
$LDFLAGS = "/link /LIBPATH:#{pcap_libdir}"
|
47
54
|
$LDFLAGS += " -g" if with_config("debug")
|
48
55
|
have_header("ruby/thread.h")
|
56
|
+
if have_header(pcap_includedir + "/Win32-Extensions.h", pcap_includedir + "/pcap.h")
|
57
|
+
append_cflags("-DHAVE_WIN32_EXTENSIONS_H")
|
58
|
+
end
|
49
59
|
have_func("rb_thread_blocking_region") # Pre ruby 2.2
|
50
60
|
have_func("rb_thread_call_without_gvl") # Post ruby 2.2
|
51
61
|
|
data/ext/pcaprub_c/pcaprub.c
CHANGED
@@ -9,8 +9,11 @@
|
|
9
9
|
#endif
|
10
10
|
|
11
11
|
#include <pcap.h>
|
12
|
+
// Win32-Extensions only exist in winpcap not npcap
|
12
13
|
#if defined(WIN32)
|
13
|
-
#
|
14
|
+
#ifdef HAVE_WIN32_EXTENSIONS_H
|
15
|
+
#include <Win32-Extensions.h>
|
16
|
+
#endif
|
14
17
|
#endif
|
15
18
|
|
16
19
|
#if !defined(WIN32)
|
@@ -407,7 +410,7 @@ rbpcap_setfilter(VALUE self, VALUE filter)
|
|
407
410
|
{
|
408
411
|
char eb[PCAP_ERRBUF_SIZE];
|
409
412
|
rbpcap_t *rbp;
|
410
|
-
|
413
|
+
bpf_u_int32 mask = 0, netid = 0;
|
411
414
|
struct bpf_program bpf;
|
412
415
|
|
413
416
|
Data_Get_Struct(self, rbpcap_t, rbp);
|
@@ -452,7 +455,7 @@ rbpcap_setfilter(VALUE self, VALUE filter)
|
|
452
455
|
static VALUE
|
453
456
|
rbpcap_compile(VALUE self, VALUE filter) {
|
454
457
|
struct bpf_program bpf;
|
455
|
-
|
458
|
+
bpf_u_int32 mask = 0;
|
456
459
|
rbpcap_t *rbp;
|
457
460
|
|
458
461
|
Data_Get_Struct(self, rbpcap_t, rbp);
|
@@ -981,7 +984,7 @@ rbpcap_each_data(VALUE self)
|
|
981
984
|
if(! rbpcap_ready(rbp)) return self;
|
982
985
|
|
983
986
|
#if defined(WIN32)
|
984
|
-
fno = (
|
987
|
+
fno = (HANDLE)pcap_getevent(rbp->pd);
|
985
988
|
#else
|
986
989
|
fno = pcap_get_selectable_fd(rbp->pd);
|
987
990
|
#endif
|
@@ -1023,7 +1026,7 @@ rbpcap_each_packet(VALUE self)
|
|
1023
1026
|
if(! rbpcap_ready(rbp)) return self;
|
1024
1027
|
|
1025
1028
|
#if defined(WIN32)
|
1026
|
-
fno = (
|
1029
|
+
fno = (HANDLE)pcap_getevent(rbp->pd);
|
1027
1030
|
#else
|
1028
1031
|
fno = pcap_get_selectable_fd(rbp->pd);
|
1029
1032
|
#endif
|
@@ -1241,12 +1244,12 @@ rbpacket_data(VALUE self)
|
|
1241
1244
|
}
|
1242
1245
|
|
1243
1246
|
#if defined(WIN32)
|
1244
|
-
static
|
1247
|
+
static void *
|
1245
1248
|
rbpcap_thread_wait_handle_blocking(void *data)
|
1246
1249
|
{
|
1247
1250
|
VALUE result;
|
1248
1251
|
result = (VALUE)WaitForSingleObject(data, 100);
|
1249
|
-
return result;
|
1252
|
+
return (void *) result;
|
1250
1253
|
}
|
1251
1254
|
|
1252
1255
|
/*
|
data/lib/pcaprub/version.rb
CHANGED
data/lib/pcaprub.rb
CHANGED
@@ -2,7 +2,31 @@ module PCAPRUB
|
|
2
2
|
$:.unshift(File.dirname(__FILE__))
|
3
3
|
require 'pcaprub/common'
|
4
4
|
require 'pcaprub/version'
|
5
|
-
|
5
|
+
|
6
|
+
add_dll_path = proc do |path, &block|
|
7
|
+
if RUBY_PLATFORM =~/(mswin|mingw)/i && path && File.exist?(path)
|
8
|
+
begin
|
9
|
+
require 'ruby_installer/runtime'
|
10
|
+
RubyInstaller::Runtime.add_dll_directory(path, &block)
|
11
|
+
rescue LoadError
|
12
|
+
old_path = ENV['PATH']
|
13
|
+
ENV['PATH'] = "#{path};#{old_path}"
|
14
|
+
begin
|
15
|
+
block.call
|
16
|
+
ensure
|
17
|
+
ENV['PATH'] = old_path
|
18
|
+
end
|
19
|
+
end
|
20
|
+
else
|
21
|
+
block.call
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
npcap_path = "C:\\Windows\\System32\\Npcap"
|
26
|
+
add_dll_path.call(npcap_path) do
|
27
|
+
require 'pcaprub/ext'
|
28
|
+
end
|
29
|
+
|
6
30
|
end
|
7
31
|
|
8
32
|
#Force Include to allow backwards compatibility to ::PCAP.new
|
data/test/test_pcaprub_unit.rb
CHANGED
@@ -165,11 +165,12 @@ class Pcap::UnitTest < Test::Unit::TestCase
|
|
165
165
|
def test_lib_version
|
166
166
|
v = Pcap.lib_version.split
|
167
167
|
if RUBY_PLATFORM =~ /mingw/
|
168
|
-
|
168
|
+
winpcap = 'WinPcap' == v[0]
|
169
|
+
npcap = 'Npcap' == v[0]
|
170
|
+
assert winpcap || npcap
|
169
171
|
else
|
170
172
|
assert_equal "libpcap", v[0]
|
171
173
|
end
|
172
174
|
assert_equal "version", v[1]
|
173
|
-
assert_equal 3, v[2].split('.').size
|
174
175
|
end
|
175
176
|
end
|
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.13.
|
4
|
+
version: 0.13.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shadowbq
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2024-
|
14
|
+
date: 2024-07-29 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|