packetgen 1.0.0 → 1.0.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
  SHA1:
3
- metadata.gz: 45af460b696e393ab1c89b3e27fba605246eafc5
4
- data.tar.gz: 18f621d8edd0c5c5fee18a97c5ffb9c1d31043c3
3
+ metadata.gz: 3cb4095a7e2fda39a7560ad82d4296016c5a633a
4
+ data.tar.gz: aed1db17fd5274a7d842ac6ba855ed73b7d271fe
5
5
  SHA512:
6
- metadata.gz: dfc16c31052743888efb32945d26d16995e975d6affb47c3a52f4fa4338e7906b75548f8d87e14c963ea89d21e08d877e3f9b62cfa723cf35da90b33a42d3cd4
7
- data.tar.gz: d88d482c4eb651b4175453b29c1e71215935d8ff630598dfcb44c33662b272227bda2aea46f7c219c52cd57c9f5093cf2d03dc668e097c03c58f4a89f725dbf3
6
+ metadata.gz: a520f1dfaf0a6960c33fb27c5f564923c4de11c8d310b77c7dcf151c688df70d15396b1ce74987b7a8ca811e86f58a2f6eaf1d0a18ba03613ed02aebde9f9730
7
+ data.tar.gz: e8396d8782c437335f50a3b8ee2e63138a9b0c4ea874b46838249fcb58e8f1acc89f1a7c24c6fd0fda5169c856f9724296e2c285c826223c91eebca5eba60a95
data/README.md CHANGED
@@ -16,13 +16,16 @@ Yes. But PacketFu is limited:
16
16
  * parse packets top-down, and sometimes bad parse down layers
17
17
  * cannot send packet on wire at IP/IPv6 level (Ethernet header is mandatory)
18
18
 
19
- ## use cases
19
+ ## Installation
20
+ Via RubyGems:
20
21
 
21
- These use cases are the roadmap for PacketGen.
22
+ $ gem install packetgen
22
23
 
23
- Not yet implemented:
24
- - encapsulation/decapsulation
25
- - some protocols...
24
+ Or add it to a Gemfile:
25
+ ```ruby
26
+ gem 'packetgen'
27
+ ```
28
+ ## Usage
26
29
 
27
30
  ### Easily create packets
28
31
  ```
@@ -91,7 +94,7 @@ pkt.is? 'TCP' # => true
91
94
  pkt.is? 'IP' # => true
92
95
  pkt.is? 'UDP' # => false
93
96
 
94
- # encapulsate/decapsulate packets
97
+ # encapulsate/decapsulate packets (TODO)
95
98
  pkt2 = PacketGen.gen('IP').add('ESP', spi: 1234)
96
99
  pkt.encap pkt2 # pkt is now a IP/ESP/IP/TCP packet
97
100
  # eq. to pkt.encap('IP', 'ESP', esp_spi: 1234)
@@ -109,6 +112,10 @@ pkt.write('one_packet.pcapng')
109
112
  PacketGen.write('more_packets.pcapng', packets)
110
113
  ```
111
114
 
115
+ ## Pull requests?
116
+
117
+ yes
118
+
112
119
  ## License
113
120
  MIT License (see [LICENSE](https://github.com/sdaubert/packetgen/LICENSE))
114
121
 
@@ -118,4 +125,4 @@ Copyright © 2016 Sylvain Daubert
118
125
  All original code maintains its copyright from its original authors and licensing.
119
126
 
120
127
  This is mainly for StrucFu (copied from [PacketFu](https://github.com/packetfu/packetfu))
121
- and PcapNG module (also copied from PacketFu, but I am the author).
128
+ and PcapNG module (also copied from PacketFu, but I am the author).
@@ -42,7 +42,7 @@ module PacketGen
42
42
  # @yieldparam [Packet] packet
43
43
  # @return [Array<Packet>]
44
44
  def self.capture(iface, options={})
45
- Packet.capture(iface, options) { |packet| yield packet }
45
+ Packet.capture(iface, options) { |packet| yield packet if block_given? }
46
46
  end
47
47
 
48
48
  # Shortcut for {Packet.read}
@@ -65,7 +65,7 @@ module PacketGen
65
65
  @cap_thread.join(@timeout)
66
66
  end
67
67
 
68
- # Stop capture. Should be used from another thread, as {#start} blocs.
68
+ # Stop capture. Should be used from another thread, as {#start} blocks.
69
69
  #
70
70
  # BEWARE: multiple capture should not be started in different threads. No effort
71
71
  # has been made to make Capture nor PacketGen thread-safe.
@@ -79,11 +79,7 @@ module PacketGen
79
79
  def set_options(options)
80
80
  @max = options[:max] if options[:max]
81
81
  @filter = options[:filter] if options[:filter]
82
- if options[:timeout]
83
- @timeout = options[:timeout]
84
- else
85
- @timeout ||= 0
86
- end
82
+ @timeout = options[:timeout] if options[:timeout]
87
83
  if options[:promisc]
88
84
  @promisc = options[:promisc]
89
85
  else
@@ -52,6 +52,12 @@ module PacketGen
52
52
  iph
53
53
  end
54
54
 
55
+ # Return header protocol name
56
+ # @return [String]
57
+ def protocol_name
58
+ self.class.to_s.sub(/.*::/, '')
59
+ end
60
+
55
61
  # Common inspect method for headers
56
62
  # @return [String]
57
63
  def inspect
@@ -169,7 +169,7 @@ module PacketGen
169
169
  if binding.nil?
170
170
  msg = "#{prev_header.class} knowns no layer association with #{protocol}. "
171
171
  msg << "Try #{prev_header.class}.bind_layer(PacketGen::Header::#{protocol}, "
172
- msg << "#{prev_header.class.to_s.gsub(/(.*)::/, '').downcase}_proto_field: "
172
+ msg << "#{prev_header.protocol_name.downcase}_proto_field: "
173
173
  msg << "value_for_#{protocol.downcase})"
174
174
  raise ArgumentError, msg
175
175
  end
@@ -252,7 +252,7 @@ module PacketGen
252
252
  if @headers.first.respond_to? :to_w
253
253
  @headers.first.to_w(iface)
254
254
  else
255
- type = @headers.first.class.to_s.gsub(/.*::/, '')
255
+ type = @headers.first.protocol_name
256
256
  raise WireError, "don't known how to send a #{type} packet on wire"
257
257
  end
258
258
  end
@@ -8,5 +8,5 @@
8
8
  # @author Sylvain Daubert
9
9
  module PacketGen
10
10
  # PacketGen version
11
- VERSION = "1.0.0"
11
+ VERSION = "1.0.1"
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: packetgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Daubert
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-18 00:00:00.000000000 Z
11
+ date: 2016-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pcaprub