ruby-pcap 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +26 -0
- data/README.md +2 -3
- data/examples/capture_duration.rb +28 -0
- data/ext/pcap/Pcap.c +27 -0
- data/ruby-pcap.gemspec +2 -2
- metadata +5 -3
- data/.travis.yml +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c416ece1a8344e1f07c5170957aab941a4670eb422727dce36fc5c346db048f
|
4
|
+
data.tar.gz: 4b8f52b6059947608699b8fa125351990504ac027b8fdbf47780e76809885a99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c82fc770ddec96e61b75b099991a33a59d9fca0a575958d5101aff095acd4e81242c09d8a22a773a2b2348a9c7dcae23fed9d9f458179d57e6ffc626c7f4d6bf
|
7
|
+
data.tar.gz: cc556bf0383bf6babec625a01db347ea421894d67f45d0f69c33b3e9d847cda66abf60b1ede6c1ee8ce6186846e1cec4f2324ed74bb0e54603c785576079af40
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: build
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- master
|
6
|
+
pull_request:
|
7
|
+
branches:
|
8
|
+
- master
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
ruby-version: ['3.1', '3.0', '2.7','2.4','2.1']
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up ruby ${{ matrix.ruby_version}}
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby-version }}
|
21
|
+
- name: Install system libs dependencies
|
22
|
+
run: sudo apt-get update -qq && sudo apt-get install -y libpcap-dev
|
23
|
+
- name: Get deps
|
24
|
+
run: bundle install
|
25
|
+
- name: Build it
|
26
|
+
run: bundle exec rake
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
|
2
2
|
## ruby-pcap
|
3
3
|
|
4
|
-
[](https://github.com/vitoshalabs/ruby-pcap/actions/workflows/build.yml)
|
5
5
|
|
6
6
|
ruby-pcap is a ruby extension to LBL libpcap (Packet Capture library).
|
7
7
|
This library also includes classes to access TCP/IP header.
|
@@ -14,8 +14,7 @@ gem install ruby-pcap
|
|
14
14
|
|
15
15
|
### Requirements
|
16
16
|
|
17
|
-
* ruby-1
|
18
|
-
* May work with older ruby version but not being tested
|
17
|
+
* ruby-2.1 or higher
|
19
18
|
* libpcap (http://www.tcpdump.org/)
|
20
19
|
|
21
20
|
## Usage
|
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'pcap'
|
5
|
+
require 'pcap/pcaplet'
|
6
|
+
|
7
|
+
iface = ARGV[0] || 'en0'
|
8
|
+
duration = (ARGV[1] || 10).to_i
|
9
|
+
count = 0
|
10
|
+
capture = Pcap::Capture.open_live(iface, 65_535, true)
|
11
|
+
Thread.new do
|
12
|
+
sleep duration
|
13
|
+
if capture.closed?
|
14
|
+
puts 'device is already closed!'
|
15
|
+
else
|
16
|
+
puts 'signaling OS to stop capture!'
|
17
|
+
capture.breakloop
|
18
|
+
end
|
19
|
+
end
|
20
|
+
puts "starting capture on #{iface} for #{duration} seconds"
|
21
|
+
start_time = Time.now
|
22
|
+
capture.loop do |pkt|
|
23
|
+
puts "Got #{pkt}"
|
24
|
+
count += 1
|
25
|
+
end
|
26
|
+
capture.close
|
27
|
+
end_time = Time.now
|
28
|
+
puts "packets count #{count} completed in #{end_time - start_time} seconds"
|
data/ext/pcap/Pcap.c
CHANGED
@@ -308,6 +308,19 @@ capture_close(self)
|
|
308
308
|
return Qnil;
|
309
309
|
}
|
310
310
|
|
311
|
+
static VALUE
|
312
|
+
is_capture_closed(self)
|
313
|
+
VALUE self;
|
314
|
+
{
|
315
|
+
struct capture_object *cap;
|
316
|
+
DEBUG_PRINT("is_capture_closed");
|
317
|
+
Data_Get_Struct(self, struct capture_object, cap);
|
318
|
+
if (cap->pcap == NULL) {
|
319
|
+
return Qtrue;
|
320
|
+
}
|
321
|
+
return Qfalse;
|
322
|
+
}
|
323
|
+
|
311
324
|
static void
|
312
325
|
handler(cap, pkthdr, data)
|
313
326
|
struct capture_object *cap;
|
@@ -442,6 +455,18 @@ capture_fh(argc, argv, self)
|
|
442
455
|
return rb_funcall(rb_path2class("IO"), rb_intern("new"), 1, INT2FIX(pcap_fileno(cap->pcap)));
|
443
456
|
}
|
444
457
|
|
458
|
+
static VALUE
|
459
|
+
capture_breakloop(self)
|
460
|
+
VALUE self;
|
461
|
+
{
|
462
|
+
struct capture_object *cap;
|
463
|
+
|
464
|
+
DEBUG_PRINT("capture_breakloop");
|
465
|
+
GetCapture(self, cap);
|
466
|
+
pcap_breakloop(cap->pcap);
|
467
|
+
return Qnil;
|
468
|
+
}
|
469
|
+
|
445
470
|
static VALUE
|
446
471
|
capture_loop(argc, argv, self)
|
447
472
|
int argc;
|
@@ -1007,6 +1032,8 @@ Init_pcap(void)
|
|
1007
1032
|
rb_define_method(cCapture, "stats", capture_stats, 0);
|
1008
1033
|
rb_define_method(cCapture, "inject", capture_inject, 1);
|
1009
1034
|
rb_define_method(cCapture, "direction", capture_direction, 1);
|
1035
|
+
rb_define_method(cCapture, "breakloop", capture_breakloop, 0);
|
1036
|
+
rb_define_method(cCapture, "closed?", is_capture_closed, 0);
|
1010
1037
|
|
1011
1038
|
/* define class Dumper */
|
1012
1039
|
cDumper = rb_define_class_under(mPcap, "Dumper", rb_cObject);
|
data/ruby-pcap.gemspec
CHANGED
@@ -4,8 +4,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "ruby-pcap"
|
7
|
-
gem.version = "0.8.
|
8
|
-
gem.authors = [%q{Masaki Fukushima}, %q{Andrew Hobson}, %q{Marcus Barczak}]
|
7
|
+
gem.version = "0.8.1"
|
8
|
+
gem.authors = [%q{Masaki Fukushima}, %q{Andrew Hobson}, %q{Marcus Barczak}, %q{Vitosha Labs Open Source team}]
|
9
9
|
gem.email = ["opensource@vitosha-labs.bg"]
|
10
10
|
gem.description = %q{Ruby interface to LBL Packet Capture library. This library also includes classes to access packet header fields.}
|
11
11
|
gem.summary = %q{Ruby interface to LBL Packet Capture library.}
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-pcap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masaki Fukushima
|
8
8
|
- Andrew Hobson
|
9
9
|
- Marcus Barczak
|
10
|
+
- Vitosha Labs Open Source team
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2022-
|
14
|
+
date: 2022-10-04 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: rake-compiler
|
@@ -35,8 +36,8 @@ extensions:
|
|
35
36
|
- ext/pcap/extconf.rb
|
36
37
|
extra_rdoc_files: []
|
37
38
|
files:
|
39
|
+
- ".github/workflows/build.yml"
|
38
40
|
- ".gitignore"
|
39
|
-
- ".travis.yml"
|
40
41
|
- COPYING
|
41
42
|
- ChangeLog
|
42
43
|
- Gemfile
|
@@ -71,6 +72,7 @@ files:
|
|
71
72
|
- doc/TruncatedPacket.html
|
72
73
|
- doc/UDPPacket.html
|
73
74
|
- doc/index.html
|
75
|
+
- examples/capture_duration.rb
|
74
76
|
- examples/httpdump.rb
|
75
77
|
- examples/rewrite_time.rb
|
76
78
|
- examples/tcpdump.rb
|