ruby-pcap 0.8.0 → 0.8.1

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
  SHA256:
3
- metadata.gz: 78bf37291d08a1c9dbe2ab08269e494dbb8f3c5d6a37932e3468ca30c4899648
4
- data.tar.gz: 42cb108300efda78d65a7f742f691863a226cd4365339ef0a68a97ebfae0987e
3
+ metadata.gz: 0c416ece1a8344e1f07c5170957aab941a4670eb422727dce36fc5c346db048f
4
+ data.tar.gz: 4b8f52b6059947608699b8fa125351990504ac027b8fdbf47780e76809885a99
5
5
  SHA512:
6
- metadata.gz: 5572b9bdb5361c4b2e5061e20af5c15257e1c22dee6c747b86edff3053949795003ab892fb1b3e4f0ce77363a1f2c046a3a696d79cc047f3d178d81360a777e7
7
- data.tar.gz: 28cb162c6fdd85499effb7c397364e1f90828292c9da9465d789a8d798c594e8f45632fd62955900a015961701f01e0ecbfb5b8c61a0440a687dd26263c786c8
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
- [![Build Status](https://travis-ci.org/ickymettle/ruby-pcap.svg)](https://travis-ci.org/ickymettle/ruby-pcap)
4
+ [![build workflow](https://github.com/vitoshalabs/ruby-pcap/actions/workflows/build.yml/badge.svg)](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.9.3 or higher
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.0"
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.0
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-01-30 00:00:00.000000000 Z
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
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1.6
6
- - 2.2.2
7
- - ruby-head
8
- os:
9
- - linux
10
- - osx
11
- before_install:
12
- - sudo apt-get update -qq
13
- - sudo apt-get install -y libpcap-dev