packetgen 2.8.6 → 2.8.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ee37bbcc3ffa4d0ba19838f04c4c57ee5de15244a7bf6e2c78101148cff0026
4
- data.tar.gz: 02afc1072186723ec5d16424e3fcb0a832e2e2ab114fd6232ace7dedba873fde
3
+ metadata.gz: a9619d169e7a064e415e479dd208f15339f59700baf805bbc7a79437967c1cd5
4
+ data.tar.gz: 4d1ceeeee51b56dab91331e43672b7fe15ddeb87971bb36bc5670399f2e55080
5
5
  SHA512:
6
- metadata.gz: 5198cc85801daf880d3ac32313ac2f611ceebfa8c8023aedfe2d95021563d620234f363be048c279e3b8d2f121e465854525c2707d6fba6e82479c3beb88ff3f
7
- data.tar.gz: 98c6e9b198b1e8294b9dc38a13d3efb7cd81c0b9dafe9d6bc0998dbff07da02deca5bb7efd2bdc7f83507dc46d20d3b658620dc6f5444739485f3a9704bf9c5b
6
+ metadata.gz: a0a27dd879ec6c9362bade001b6f6701686f80a589d2dd75478f5894dbaf8bd5b766f00f692437dca4ecbf96ceb830d4fcfeaef2e2354bccec7addd76f4b7ab8
7
+ data.tar.gz: bfb2b7de3b541c85cd1d367b4d8976d78d47c9872cabafd46cba12751926128f6a664c687520b28b7224af8439829219f9f6ad5a950de5878c9ee6f1d9b14243
@@ -132,18 +132,11 @@ module PacketGen
132
132
 
133
133
  # @return [String]
134
134
  def inspect
135
- str = Inspect.dashed_line(self.class, 1)
136
- fields.each do |attr|
137
- next if attr == :body
138
- next unless is_present?(attr)
139
-
140
- str << if (attr == :chaddr) && (self.hlen == 6)
141
- Inspect.inspect_attribute(attr, Eth::MacAddr.new.read(self[:chaddr][0, 6]), 1)
142
- else
143
- Inspect.inspect_attribute(attr, self[attr], 1)
144
- end
135
+ super do |attr|
136
+ next unless (attr == :chaddr) && (self.hlen == 6)
137
+
138
+ Inspect.inspect_attribute(attr, Eth::MacAddr.new.read(self[:chaddr][0, 6]))
145
139
  end
146
- str
147
140
  end
148
141
 
149
142
  # Invert opcode, if known
@@ -250,24 +250,20 @@ module PacketGen
250
250
 
251
251
  # @return [String]
252
252
  def inspect
253
- str = Inspect.dashed_line(self.class, 1)
254
- fields.each do |attr|
255
- if attr == :u16
256
- flags = %i[qr aa tc rd ra].select! { |flag| send "#{flag}?" }
257
- .map(&:to_s).join(',')
258
- str << Inspect.shift_level(1)
259
- str << Inspect::FMT_ATTR % ['Flags', 'flags', flags]
260
- opcode = '%-16s (%u)' % [OPCODES.key(self.opcode), self.opcode]
261
- str << Inspect.shift_level(1)
262
- str << Inspect::FMT_ATTR % ['Integer', 'opcode', opcode]
263
- rcode = '%-16s (%u)' % [RCODES.key(self.rcode), self.rcode]
264
- str << Inspect.shift_level(1)
265
- str << Inspect::FMT_ATTR % ['Integer', 'rcode', rcode]
266
- else
267
- str << Inspect.inspect_attribute(attr, self[attr], 1)
268
- end
253
+ super do |attr|
254
+ next unless attr == :u16
255
+
256
+ flags = %i[qr aa tc rd ra].select! { |flag| send "#{flag}?" }
257
+ .map(&:to_s).join(',')
258
+ str = Inspect.shift_level
259
+ str << Inspect::FMT_ATTR % ['Flags', 'flags', flags]
260
+ opcode = '%-16s (%u)' % [OPCODES.key(self.opcode), self.opcode]
261
+ str << Inspect.shift_level
262
+ str << Inspect::FMT_ATTR % ['Integer', 'opcode', opcode]
263
+ rcode = '%-16s (%u)' % [RCODES.key(self.rcode), self.rcode]
264
+ str << Inspect.shift_level
265
+ str << Inspect::FMT_ATTR % ['Integer', 'rcode', rcode]
269
266
  end
270
- str
271
267
  end
272
268
  end
273
269
 
@@ -47,23 +47,15 @@ module PacketGen
47
47
 
48
48
  # @return [String]
49
49
  def inspect
50
- str = Inspect.dashed_line(self.class, 1)
51
- fields.each do |attr|
52
- next if attr == :body
53
- next unless present?(attr)
50
+ super do |attr|
51
+ next unless attr == :flags
54
52
 
55
- if attr == :flags
56
- shift = Inspect.shift_level(1)
57
- value = %i[l m s].map { |f| send("#{f}?") ? f.to_s : '.' }.join
58
- value = '%-16s (0x%02x)' % [value, self.flags]
59
- str << shift
60
- str << Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''),
61
- attr, value]
62
- else
63
- str << Inspect.inspect_attribute(attr, self[attr], 1)
64
- end
53
+ str = Inspect.shift_level
54
+ value = %i[l m s].map { |f| send("#{f}?") ? f.to_s : '.' }.join
55
+ value = '%-16s (0x%02x)' % [value, self.flags]
56
+ str << Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''),
57
+ attr, value]
65
58
  end
66
- str
67
59
  end
68
60
  end
69
61
  end
@@ -51,24 +51,18 @@ module PacketGen
51
51
 
52
52
  # @return [String]
53
53
  def inspect
54
- str = Inspect.dashed_line(self.class, 1)
55
- fields.each do |attr|
56
- next if attr == :body
57
- next unless is_present?(attr)
54
+ super do |attr|
55
+ next unless attr == :flags
58
56
 
59
- if attr == :flags
60
- shift = Inspect.shift_level(1)
61
- value = %i[l m s].map { |f| send("#{f}?") ? f.to_s : '.' }.join
62
- value = '%-16s (0x%02x)' % [value, self.flags]
63
- str << shift
64
- str << Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''),
65
- attr, value]
66
- str << Inspect::FMT_ATTR % ['', 'version', self.version]
67
- else
68
- str << Inspect.inspect_attribute(attr, self[attr], 1)
69
- end
57
+ shift = Inspect.shift_level
58
+ str = shift.dup
59
+ value = %i[l m s].map { |f| send("#{f}?") ? f.to_s : '.' }.join
60
+ value = '%-16s (0x%02x)' % [value, self.flags]
61
+ str << Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''),
62
+ attr, value]
63
+ str << shift
64
+ str << Inspect::FMT_ATTR % ['', 'version', self.version]
70
65
  end
71
- str
72
66
  end
73
67
  end
74
68
  end
@@ -189,28 +189,18 @@ module PacketGen
189
189
 
190
190
  # @return [String]
191
191
  def inspect
192
- str = Inspect.dashed_line(self.class, )
193
- fields.each do |attr|
194
- next if attr == :body
195
-
192
+ super do |attr|
196
193
  case attr
197
194
  when :flags
198
195
  str_flags = ''.dup
199
196
  %w[r v i].each do |flag|
200
197
  str_flags << (send("flag_#{flag}?") ? flag.upcase : '.')
201
198
  end
202
- str << Inspect.shift_level(2)
199
+ str = Inspect.shift_level
203
200
  str << Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''), attr,
204
201
  str_flags]
205
- when :exchange_type
206
- str << Inspect.shift_level(2)
207
- str << Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''), attr,
208
- human_exchange_type]
209
- else
210
- str << Inspect.inspect_attribute(attr, self[attr], 2)
211
202
  end
212
203
  end
213
- str
214
204
  end
215
205
 
216
206
  # Toggle +I+ and +R+ flags.
@@ -68,24 +68,6 @@ module PacketGen
68
68
  def human_encoding
69
69
  self[:encoding].to_human
70
70
  end
71
-
72
- # @return [String]
73
- def inspect
74
- str = Inspect.dashed_line(self.class, 1)
75
- fields.each do |attr|
76
- case attr
77
- when :body
78
- next
79
- when :encoding
80
- str << Inspect.shift_level(1)
81
- str << Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''), attr,
82
- human_encoding]
83
- else
84
- str << Inspect.inspect_attribute(attr, self[attr], 1)
85
- end
86
- end
87
- str
88
- end
89
71
  end
90
72
  end
91
73
 
@@ -52,19 +52,11 @@ module PacketGen
52
52
 
53
53
  # @return [String]
54
54
  def inspect
55
- str = Inspect.dashed_line(self.class, 1)
56
- fields.each do |attr|
57
- case attr
58
- when :body
59
- next
60
- when :content
61
- str << Inspect.shift_level(1)
62
- str << Inspect::FMT_ATTR % ['hashes', :content, human_content]
63
- else
64
- str << Inspect.inspect_attribute(attr, self[attr], 1)
65
- end
55
+ super do |attr|
56
+ next unless attr == :content
57
+ str = Inspect.shift_level
58
+ str << Inspect::FMT_ATTR % ['hashes', :content, human_content]
66
59
  end
67
- str
68
60
  end
69
61
  end
70
62
  end
@@ -160,19 +160,13 @@ module PacketGen
160
160
 
161
161
  # @return [String]
162
162
  def inspect
163
- str = Inspect.dashed_line(self.class, 1)
164
- fields.each do |attr|
165
- next if attr == :body
163
+ super do |attr|
164
+ next unless attr == :protocol
166
165
 
167
- if %i[protocol message_type].include? attr
168
- str << Inspect.shift_level(1)
169
- str << Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''), attr,
170
- send("human_#{attr}")]
171
- else
172
- str << Inspect.inspect_attribute(attr, self[attr], 1)
173
- end
166
+ str = Inspect.shift_level
167
+ str << Inspect::FMT_ATTR % [self[attr].class.to_s.sub(/.*::/, ''), attr,
168
+ human_protocol]
174
169
  end
175
- str
176
170
  end
177
171
  end
178
172
  end
@@ -235,26 +235,25 @@ module PacketGen
235
235
 
236
236
  # @return [String]
237
237
  def inspect
238
- str = Inspect.dashed_line(self.class, 1)
239
- shift = Inspect.shift_level(1)
240
- fields.each do |attr|
241
- next if attr == :body
242
-
243
- str << Inspect.inspect_attribute(attr, self[attr], 1)
244
- if attr == :u8
245
- str << shift + Inspect::FMT_ATTR % ['', 'version', version]
246
- str << shift + Inspect::FMT_ATTR % ['', 'ihl', ihl]
247
- elsif attr == :frag
238
+ super do |attr|
239
+ case attr
240
+ when :u8
241
+ shift = Inspect.shift_level
242
+ str = Inspect.inspect_attribute(attr, self[attr])
243
+ str << shift << Inspect::FMT_ATTR % ['', 'version', version]
244
+ str << shift << Inspect::FMT_ATTR % ['', 'ihl', ihl]
245
+ when :frag
246
+ shift = Inspect.shift_level
247
+ str = Inspect.inspect_attribute(attr, self[attr])
248
248
  flags = flag_rsv? ? %w[RSV] : []
249
249
  flags << 'DF' if flag_df?
250
250
  flags << 'MF' if flag_mf?
251
251
  flags_str = flags.empty? ? 'none' : flags.join(',')
252
- str << shift + Inspect::FMT_ATTR % ['', 'flags', flags_str]
252
+ str << shift << Inspect::FMT_ATTR % ['', 'flags', flags_str]
253
253
  foff = Inspect.int_dec_hex(fragment_offset, 4)
254
- str << shift + Inspect::FMT_ATTR % ['', 'frag_offset', foff]
254
+ str << shift << Inspect::FMT_ATTR % ['', 'frag_offset', foff]
255
255
  end
256
256
  end
257
- str
258
257
  end
259
258
 
260
259
  # Check version field
@@ -137,21 +137,17 @@ module PacketGen
137
137
 
138
138
  # @return [String]
139
139
  def inspect
140
- str = Inspect.dashed_line(self.class, 1)
141
- fields.each do |attr|
142
- next if attr == :body
143
-
144
- str << Inspect.inspect_attribute(attr, self[attr], 1)
145
- if attr == :u32
146
- shift = Inspect.shift_level(2)
147
- str << shift + Inspect::FMT_ATTR % ['', 'version', version]
148
- tclass = Inspect.int_dec_hex(traffic_class, 2)
149
- str << shift + Inspect::FMT_ATTR % ['', 'tclass', tclass]
150
- fl_value = Inspect.int_dec_hex(flow_label, 5)
151
- str << shift + Inspect::FMT_ATTR % ['', 'flow_label', fl_value]
152
- end
140
+ super do |attr|
141
+ next unless attr == :u32
142
+
143
+ str = Inspect.inspect_attribute(attr, self[attr])
144
+ shift = Inspect.shift_level
145
+ str << shift + Inspect::FMT_ATTR % ['', 'version', version]
146
+ tclass = Inspect.int_dec_hex(traffic_class, 2)
147
+ str << shift + Inspect::FMT_ATTR % ['', 'tclass', tclass]
148
+ fl_value = Inspect.int_dec_hex(flow_label, 5)
149
+ str << shift + Inspect::FMT_ATTR % ['', 'flow_label', fl_value]
153
150
  end
154
- str
155
151
  end
156
152
 
157
153
  # Check version field
@@ -113,7 +113,7 @@ module PacketGen
113
113
  sequence :pdu,
114
114
  implicit: SNMP::PDU_GET, constructed: true,
115
115
  content: [integer(:id, value: 0),
116
- enumerated(:error, value: 0, enum: ERRORS),
116
+ integer(:error, value: 0, enum: ERRORS),
117
117
  integer(:error_index, value: 0),
118
118
  model(:varbindlist, VariableBindings)]
119
119
  end
@@ -162,13 +162,13 @@ module PacketGen
162
162
  implicit: SNMP::PDU_TRAPv1, constructed: true,
163
163
  content: [objectid(:enterprise),
164
164
  octet_string(:agent_addr),
165
- enumerated(:generic_trap, enum: { 'cold_start' => 0,
166
- 'warm_start' => 1,
167
- 'link_down' => 2,
168
- 'link_up' => 3,
169
- 'auth_failure' => 4,
170
- 'egp_neighbor_loss' => 5,
171
- 'specific' => 6 }),
165
+ integer(:generic_trap, enum: { 'cold_start' => 0,
166
+ 'warm_start' => 1,
167
+ 'link_down' => 2,
168
+ 'link_up' => 3,
169
+ 'auth_failure' => 4,
170
+ 'egp_neighbor_loss' => 5,
171
+ 'specific' => 6 }),
172
172
  integer(:specific_trap),
173
173
  integer(:timestamp),
174
174
  model(:varbindlist, VariableBindings)]
@@ -243,8 +243,8 @@ module PacketGen
243
243
  end
244
244
 
245
245
  sequence :message,
246
- content: [enumerated(:version, value: 'v2c',
247
- enum: { 'v1' => 0, 'v2c' => 1, 'v2' => 2, 'v3' => 3 }),
246
+ content: [integer(:version, value: 'v2c',
247
+ enum: { 'v1' => 0, 'v2c' => 1, 'v2' => 2, 'v3' => 3 }),
248
248
  octet_string(:community, value: 'public'),
249
249
  model(:data, PDUs)]
250
250
 
@@ -280,13 +280,13 @@ module PacketGen
280
280
 
281
281
  def inspect
282
282
  str = super
283
- str << Inspect.shift_level(1)
283
+ str << Inspect.shift_level
284
284
  if self[:data].chosen.nil?
285
285
  str << Inspect::FMT_ATTR % [self[:data].type, :data, '']
286
286
  else
287
287
  data = self[:data]
288
288
  str << Inspect::FMT_ATTR % [data.type, :data, data.chosen_value.type]
289
- str << Inspect.dashed_line('ASN.1 content', 1)
289
+ str << Inspect.dashed_line('ASN.1 content')
290
290
  str << data.chosen_value.inspect(1)
291
291
  begin
292
292
  str << Inspect.inspect_body(self[:message].to_der, 'ASN.1 DER')
@@ -206,24 +206,20 @@ module PacketGen
206
206
 
207
207
  # @return [String]
208
208
  def inspect
209
- str = Inspect.dashed_line(self.class, 1)
210
- shift = Inspect.shift_level(1)
211
- fields.each do |attr|
212
- next if attr == :body
213
-
214
- str << Inspect.inspect_attribute(attr, self[attr], 1)
215
- if attr == :u16
216
- doff = Inspect.int_dec_hex(data_offset, 1)
217
- str << shift + Inspect::FMT_ATTR % ['', 'data_offset', doff]
218
- str << shift + Inspect::FMT_ATTR % ['', 'reserved', reserved]
219
- flags = ''.dup
220
- %w[ns cwr ece urg ack psh rst syn fin].each do |fl|
221
- flags << (send("flag_#{fl}?") ? fl[0].upcase : '.')
222
- end
223
- str << shift + Inspect::FMT_ATTR % ['', 'flags', flags]
209
+ super do |attr|
210
+ next unless attr == :u16
211
+
212
+ shift = Inspect.shift_level
213
+ str = Inspect.inspect_attribute(attr, self[attr])
214
+ doff = Inspect.int_dec_hex(data_offset, 1)
215
+ str<< shift << Inspect::FMT_ATTR % ['', 'data_offset', doff]
216
+ str << shift << Inspect::FMT_ATTR % ['', 'reserved', reserved]
217
+ flags = ''.dup
218
+ %w[ns cwr ece urg ack psh rst syn fin].each do |fl|
219
+ flags << (send("flag_#{fl}?") ? fl[0].upcase : '.')
224
220
  end
221
+ str << shift << Inspect::FMT_ATTR % ['', 'flags', flags]
225
222
  end
226
- str
227
223
  end
228
224
 
229
225
  # Invert source and destination port numbers
@@ -356,7 +356,9 @@ module PacketGen
356
356
  @fields = {}
357
357
  @optional_fields = {}
358
358
 
359
- self.class.class_eval { @field_defs }.each do |field, ary|
359
+ field_defs = self.class.class_eval { @field_defs }
360
+ self.class.fields.each do |field|
361
+ ary = field_defs[field]
360
362
  type, default, builder, optional, enum, field_options = ary
361
363
  default = default.to_proc.call(self) if default.is_a?(Proc)
362
364
  @fields[field] = if builder
@@ -480,7 +482,13 @@ module PacketGen
480
482
  self
481
483
  end
482
484
 
483
- # Common inspect method for headers
485
+ # Common inspect method for headers.
486
+ #
487
+ # A block may be given to differently format some attributes. This
488
+ # may be used by subclasses to handle specific fields.
489
+ # @yieldparam attr [Symbol] attribute to inspect
490
+ # @yieldreturn [String,nil] the string to print for +attr+, or +nil+
491
+ # to let +inspect+ generate it
484
492
  # @return [String]
485
493
  def inspect
486
494
  str = Inspect.dashed_line(self.class, 1)
@@ -488,7 +496,8 @@ module PacketGen
488
496
  next if attr == :body
489
497
  next unless present?(attr)
490
498
 
491
- str << Inspect.inspect_attribute(attr, self[attr], 1)
499
+ result = yield(attr)if block_given?
500
+ str << (result || Inspect.inspect_attribute(attr, self[attr], 1))
492
501
  end
493
502
  str
494
503
  end
@@ -10,5 +10,5 @@
10
10
  # @author Sylvain Daubert
11
11
  module PacketGen
12
12
  # PacketGen version
13
- VERSION = '2.8.6'
13
+ VERSION = '2.8.7'
14
14
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_dependency 'interfacez', '~>1.0'
28
28
  spec.add_dependency 'pcaprub', '~>0.12.4'
29
- spec.add_dependency 'rasn1', '~>0.5', '>= 0.6.3'
29
+ spec.add_dependency 'rasn1', '~>0.5', '>= 0.6.6'
30
30
 
31
31
  spec.add_development_dependency 'bundler', '~> 1.16'
32
32
  spec.add_development_dependency 'rake', '~> 12.3'
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: 2.8.6
4
+ version: 2.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Daubert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-09 00:00:00.000000000 Z
11
+ date: 2018-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: interfacez
@@ -47,7 +47,7 @@ dependencies:
47
47
  version: '0.5'
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: 0.6.3
50
+ version: 0.6.6
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -57,7 +57,7 @@ dependencies:
57
57
  version: '0.5'
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 0.6.3
60
+ version: 0.6.6
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: bundler
63
63
  requirement: !ruby/object:Gem::Requirement