packetgen 3.3.3 → 4.0.0

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.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -21
  3. data/lib/packetgen/capture.rb +2 -2
  4. data/lib/packetgen/config.rb +0 -1
  5. data/lib/packetgen/deprecation.rb +7 -7
  6. data/lib/packetgen/header/arp.rb +13 -13
  7. data/lib/packetgen/header/asn1_base.rb +1 -1
  8. data/lib/packetgen/header/base.rb +17 -18
  9. data/lib/packetgen/header/bootp.rb +32 -34
  10. data/lib/packetgen/header/dhcp/option.rb +19 -19
  11. data/lib/packetgen/header/dhcp/options.rb +1 -1
  12. data/lib/packetgen/header/dhcp.rb +3 -3
  13. data/lib/packetgen/header/dhcpv6/duid.rb +16 -16
  14. data/lib/packetgen/header/dhcpv6/option.rb +53 -53
  15. data/lib/packetgen/header/dhcpv6/options.rb +1 -1
  16. data/lib/packetgen/header/dhcpv6/relay.rb +5 -5
  17. data/lib/packetgen/header/dhcpv6.rb +6 -6
  18. data/lib/packetgen/header/dns/name.rb +14 -10
  19. data/lib/packetgen/header/dns/opt.rb +2 -2
  20. data/lib/packetgen/header/dns/option.rb +11 -11
  21. data/lib/packetgen/header/dns/qdsection.rb +1 -1
  22. data/lib/packetgen/header/dns/question.rb +6 -8
  23. data/lib/packetgen/header/dns/rr.rb +56 -43
  24. data/lib/packetgen/header/dns/rrsection.rb +4 -4
  25. data/lib/packetgen/header/dns.rb +27 -30
  26. data/lib/packetgen/header/dot11/control.rb +11 -11
  27. data/lib/packetgen/header/dot11/data.rb +20 -20
  28. data/lib/packetgen/header/dot11/element.rb +4 -4
  29. data/lib/packetgen/header/dot11/management.rb +8 -8
  30. data/lib/packetgen/header/dot11/sub_mngt.rb +39 -53
  31. data/lib/packetgen/header/dot11.rb +88 -93
  32. data/lib/packetgen/header/dot1q.rb +10 -12
  33. data/lib/packetgen/header/dot1x.rb +9 -9
  34. data/lib/packetgen/header/eap/fast.rb +4 -4
  35. data/lib/packetgen/header/eap/md5.rb +6 -6
  36. data/lib/packetgen/header/eap/tls.rb +13 -15
  37. data/lib/packetgen/header/eap/ttls.rb +13 -15
  38. data/lib/packetgen/header/eap.rb +22 -22
  39. data/lib/packetgen/header/eth.rb +18 -18
  40. data/lib/packetgen/header/gre.rb +8 -10
  41. data/lib/packetgen/header/http/headers.rb +2 -2
  42. data/lib/packetgen/header/http/request.rb +17 -16
  43. data/lib/packetgen/header/http/response.rb +18 -17
  44. data/lib/packetgen/header/http/verbs.rb +1 -3
  45. data/lib/packetgen/header/icmp.rb +8 -8
  46. data/lib/packetgen/header/icmpv6.rb +3 -3
  47. data/lib/packetgen/header/igmp.rb +8 -8
  48. data/lib/packetgen/header/igmpv3/group_record.rb +12 -12
  49. data/lib/packetgen/header/igmpv3/mq.rb +16 -18
  50. data/lib/packetgen/header/igmpv3/mr.rb +4 -4
  51. data/lib/packetgen/header/igmpv3.rb +7 -7
  52. data/lib/packetgen/header/ip/addr.rb +13 -13
  53. data/lib/packetgen/header/ip/option.rb +31 -33
  54. data/lib/packetgen/header/ip/options.rb +1 -1
  55. data/lib/packetgen/header/ip.rb +37 -72
  56. data/lib/packetgen/header/ipv6/addr.rb +14 -14
  57. data/lib/packetgen/header/ipv6/extension.rb +8 -8
  58. data/lib/packetgen/header/ipv6/hop_by_hop.rb +9 -9
  59. data/lib/packetgen/header/ipv6.rb +20 -22
  60. data/lib/packetgen/header/llc.rb +17 -17
  61. data/lib/packetgen/header/mdns.rb +1 -1
  62. data/lib/packetgen/header/mld.rb +6 -6
  63. data/lib/packetgen/header/mldv2/mcast_address_record.rb +11 -11
  64. data/lib/packetgen/header/mldv2/mlq.rb +21 -23
  65. data/lib/packetgen/header/mldv2/mlr.rb +8 -8
  66. data/lib/packetgen/header/ospfv2/db_description.rb +11 -12
  67. data/lib/packetgen/header/ospfv2/hello.rb +11 -11
  68. data/lib/packetgen/header/ospfv2/ls_ack.rb +1 -1
  69. data/lib/packetgen/header/ospfv2/ls_request.rb +9 -9
  70. data/lib/packetgen/header/ospfv2/ls_update.rb +3 -3
  71. data/lib/packetgen/header/ospfv2/lsa.rb +54 -58
  72. data/lib/packetgen/header/ospfv2/lsa_header.rb +9 -9
  73. data/lib/packetgen/header/ospfv2.rb +27 -29
  74. data/lib/packetgen/header/ospfv3/db_description.rb +13 -14
  75. data/lib/packetgen/header/ospfv3/hello.rb +12 -12
  76. data/lib/packetgen/header/ospfv3/ipv6_prefix.rb +17 -19
  77. data/lib/packetgen/header/ospfv3/ls_ack.rb +2 -2
  78. data/lib/packetgen/header/ospfv3/ls_request.rb +9 -9
  79. data/lib/packetgen/header/ospfv3/ls_update.rb +4 -4
  80. data/lib/packetgen/header/ospfv3/lsa.rb +48 -51
  81. data/lib/packetgen/header/ospfv3/lsa_header.rb +9 -9
  82. data/lib/packetgen/header/ospfv3.rb +25 -27
  83. data/lib/packetgen/header/sctp/chunk.rb +44 -41
  84. data/lib/packetgen/header/sctp/error.rb +52 -52
  85. data/lib/packetgen/header/sctp/parameter.rb +38 -38
  86. data/lib/packetgen/header/sctp.rb +5 -5
  87. data/lib/packetgen/header/snmp.rb +2 -2
  88. data/lib/packetgen/header/tcp/option.rb +45 -39
  89. data/lib/packetgen/header/tcp/options.rb +2 -2
  90. data/lib/packetgen/header/tcp.rb +55 -44
  91. data/lib/packetgen/header/tftp.rb +16 -16
  92. data/lib/packetgen/header/udp.rb +8 -8
  93. data/lib/packetgen/header.rb +9 -10
  94. data/lib/packetgen/headerable.rb +13 -3
  95. data/lib/packetgen/inspect.rb +2 -2
  96. data/lib/packetgen/packet.rb +54 -37
  97. data/lib/packetgen/pcap.rb +15 -4
  98. data/lib/packetgen/pcapng/block.rb +18 -17
  99. data/lib/packetgen/pcapng/epb.rb +13 -15
  100. data/lib/packetgen/pcapng/file.rb +3 -97
  101. data/lib/packetgen/pcapng/idb.rb +9 -11
  102. data/lib/packetgen/pcapng/shb.rb +13 -15
  103. data/lib/packetgen/pcapng/spb.rb +8 -10
  104. data/lib/packetgen/pcapng/unknown_block.rb +6 -17
  105. data/lib/packetgen/pcapng.rb +4 -4
  106. data/lib/packetgen/pcaprub_wrapper.rb +17 -1
  107. data/lib/packetgen/proto.rb +1 -1
  108. data/lib/packetgen/unknown_packet.rb +2 -2
  109. data/lib/packetgen/utils/arp_spoofer.rb +18 -19
  110. data/lib/packetgen/utils.rb +2 -2
  111. data/lib/packetgen/version.rb +1 -1
  112. data/lib/packetgen.rb +4 -3
  113. metadata +29 -38
  114. data/lib/packetgen/types/abstract_tlv.rb +0 -278
  115. data/lib/packetgen/types/array.rb +0 -287
  116. data/lib/packetgen/types/cstring.rb +0 -109
  117. data/lib/packetgen/types/enum.rb +0 -171
  118. data/lib/packetgen/types/fieldable.rb +0 -66
  119. data/lib/packetgen/types/fields.rb +0 -622
  120. data/lib/packetgen/types/int.rb +0 -473
  121. data/lib/packetgen/types/int_string.rb +0 -102
  122. data/lib/packetgen/types/length_from.rb +0 -54
  123. data/lib/packetgen/types/oui.rb +0 -52
  124. data/lib/packetgen/types/string.rb +0 -97
  125. data/lib/packetgen/types/tlv.rb +0 -161
  126. data/lib/packetgen/types.rb +0 -26
@@ -17,25 +17,24 @@ module PacketGen
17
17
  class PPI < Base
18
18
  # @!attribute version
19
19
  # @return [Integer] 8-bit PPI version
20
- define_field :version, Types::Int8, default: 0
20
+ define_attr :version, BinStruct::Int8, default: 0
21
21
  # @!attribute flags
22
22
  # @return [Integer] 8-bit PPI flags
23
- define_field :flags, Types::Int8
23
+ # @!attribute align
24
+ # @return [Boolean] align flag from {#flags} attribute
25
+ define_bit_attr :flags, reserved: 7, align: 1
24
26
  # @!attribute length
25
27
  # @return [Integer] 16-bit PPI header length
26
- define_field :length, Types::Int16le, default: 8
28
+ define_attr :length, BinStruct::Int16le, default: 8
27
29
  # @!attribute dlt
28
30
  # @return [Integer] 32-bit PPI data link type
29
- define_field :dlt, Types::Int32le
31
+ define_attr :dlt, BinStruct::Int32le
30
32
  # @!attribute ppi_fields
31
33
  # @return [Type::String] concatenation of PPI fields
32
- define_field :ppi_fields, Types::String, builder: ->(h, t) { t.new(length_from: -> { h.length - 8 }) }
34
+ define_attr :ppi_fields, BinStruct::String, builder: ->(h, t) { t.new(length_from: -> { h.length - 8 }) }
33
35
  # @!attribute body
34
36
  # @return [Type::String]
35
- define_field :body, Types::String
36
- # @!attribute align
37
- # @return [Boolean] align flag from {#flags} attribute
38
- define_bit_fields_on :flags, :reserved, 7, :align
37
+ define_attr :body, BinStruct::String
39
38
 
40
39
  # Check version field
41
40
  # @see [Base#parse?]
@@ -65,22 +64,22 @@ module PacketGen
65
64
  class RadioTap < Base
66
65
  # @!attribute version
67
66
  # @return [Integer] 8-bit version
68
- define_field :version, Types::Int8, default: 0
67
+ define_attr :version, BinStruct::Int8, default: 0
69
68
  # @!attribute pad
70
69
  # @return [Integer] 8-bit pad
71
- define_field :pad, Types::Int8, default: 0
70
+ define_attr :pad, BinStruct::Int8, default: 0
72
71
  # @!attribute length
73
72
  # @return [Integer] 16-bit RadioTap header length
74
- define_field :length, Types::Int16le, default: 8
73
+ define_attr :length, BinStruct::Int16le, default: 8
75
74
  # @!attribute present_flags
76
75
  # @return [Integer] 32-bit integer
77
- define_field :present_flags, Types::Int32le
76
+ define_attr :present_flags, BinStruct::Int32le
78
77
  # @!attribute radio_fields
79
78
  # @return [Type::String] concatenation of RadioTap fields
80
- define_field :radio_fields, Types::String, builder: ->(h, t) { t.new(length_from: -> { h.length - 8 }) }
79
+ define_attr :radio_fields, BinStruct::String, builder: ->(h, t) { t.new(length_from: -> { h.length - 8 }) }
81
80
  # @!attribute body
82
81
  # @return [Type::String]
83
- define_field :body, Types::String
82
+ define_attr :body, BinStruct::String
84
83
 
85
84
  # Check version field
86
85
  # @see [Base#parse?]
@@ -108,18 +107,18 @@ module PacketGen
108
107
  # @abstract This is a base class to demultiplex different IEEE 802.11 frames when
109
108
  # parsing.
110
109
  # A IEEE 802.11 header may consist of at least:
111
- # * a {#frame_ctrl} ({Types::Int16}),
112
- # * a {#id}/duration ({Types::Int16le}),
110
+ # * a {#frame_ctrl} ({BinStruct::Int16}),
111
+ # * a {#id}/duration ({BinStruct::Int16le}),
113
112
  # * and a {#mac1} ({Eth::MacAddr}).
114
113
  # Depending on frame type and subtype, it may also contains:
115
114
  # * a {#mac2} ({Eth::MacAddr}),
116
115
  # * a {#mac3} ({Eth::MacAddr}),
117
- # * a {#sequence_ctrl} ({Types::Int16}),
116
+ # * a {#sequence_ctrl} ({BinStruct::Int16}),
118
117
  # * a {#mac4} ({Eth::MacAddr}),
119
- # * a {#qos_ctrl} ({Types::Int16}),
120
- # * a {#ht_ctrl} ({Types::Int32}),
121
- # * a {#body} (a {Types::String} or another {Base} class),
122
- # * a Frame check sequence ({#fcs}, of type {Types::Int32le})
118
+ # * a {#qos_ctrl} ({BinStruct::Int16}),
119
+ # * a {#ht_ctrl} ({BinStruct::Int32}),
120
+ # * a {#body} (a {BinStruct::String} or another {Base} class),
121
+ # * a Frame check sequence ({#fcs}, of type {BinStruct::Int32le})
123
122
  #
124
123
  # == Header accessors
125
124
  # As Dot11 header types are defined under Dot11 namespace, Dot11 header accessors
@@ -189,38 +188,6 @@ module PacketGen
189
188
 
190
189
  # @!attribute frame_ctrl
191
190
  # @return [Integer] 16-bit frame control word
192
- define_field :frame_ctrl, Types::Int16, default: 0
193
- # @!attribute id
194
- # @return [Integer] 16-bit ID/Duration word
195
- define_field :id, Types::Int16le, default: 0
196
- # @!attribute mac1
197
- # @return [Eth::MacAddr]
198
- define_field :mac1, Eth::MacAddr
199
- # @!attribute mac2
200
- # @return [Eth::MacAddr]
201
- define_field :mac2, Eth::MacAddr
202
- # @!attribute mac3
203
- # @return [Eth::MacAddr]
204
- define_field :mac3, Eth::MacAddr
205
- # @!attribute sequence_ctrl
206
- # @return [Integer] 16-bit sequence control word
207
- define_field :sequence_ctrl, Types::Int16le, default: 0
208
- # @!attribute mac4
209
- # @return [Eth::MacAddr]
210
- define_field :mac4, Eth::MacAddr
211
- # @!attribute qos_ctrl
212
- # @return [Integer] 16-bit QoS control word
213
- define_field :qos_ctrl, Types::Int16
214
- # @!attribute ht_ctrl
215
- # @return [Integer] 16-bit HT control word
216
- define_field :ht_ctrl, Types::Int32
217
- # @!attribute body
218
- # @return [Types::String]
219
- define_field :body, Types::String
220
- # @!attribute fcs
221
- # @return [Types::Int32le]
222
- define_field :fcs, Types::Int32le
223
-
224
191
  # @!attribute subtype
225
192
  # @return [Integer] 4-bit frame subtype from {#frame_ctrl}
226
193
  # @!attribute type
@@ -243,32 +210,60 @@ module PacketGen
243
210
  # @return [Boolean] from_ds flag from {#frame_ctrl}
244
211
  # @!attribute to_ds
245
212
  # @return [Boolean] to_ds flag from {#frame_ctrl}
246
- define_bit_fields_on :frame_ctrl, :subtype, 4, :type, 2, :proto_version, 2,
247
- :order, :wep, :md, :pwmngt, :retry, :mf, :from_ds, :to_ds
248
-
213
+ define_bit_attr :frame_ctrl, subtype: 4, type: 2, proto_version: 2, order: 1,
214
+ wep: 1, md: 1, pwmngt: 1, retry: 1, mf: 1, from_ds: 1, to_ds: 1
215
+ # @!attribute id
216
+ # @return [Integer] 16-bit ID/Duration word
217
+ define_attr :id, BinStruct::Int16le, default: 0
218
+ # @!attribute mac1
219
+ # @return [Eth::MacAddr]
220
+ define_attr :mac1, Eth::MacAddr
221
+ # @!attribute mac2
222
+ # @return [Eth::MacAddr]
223
+ define_attr :mac2, Eth::MacAddr
224
+ # @!attribute mac3
225
+ # @return [Eth::MacAddr]
226
+ define_attr :mac3, Eth::MacAddr
227
+ # @!attribute sequence_ctrl
228
+ # @return [Integer] 16-bit sequence control word
249
229
  # @!attribute sequence_number (12-bit field from {#sequence_ctrl})
250
230
  # @return [Integer]
251
231
  # @since 2.1.3
252
232
  # @!attribute fragment_number (4-bit field from {#sequence_ctrl})
253
233
  # @return [Integer]
254
234
  # @since 2.1.3
255
- define_bit_fields_on :sequence_ctrl, :sequence_number, 12, :fragment_number, 4
235
+ define_bit_attr :sequence_ctrl, sequence_number: 12, fragment_number: 4
236
+ # @!attribute mac4
237
+ # @return [Eth::MacAddr]
238
+ define_attr :mac4, Eth::MacAddr
239
+ # @!attribute qos_ctrl
240
+ # @return [Integer] 16-bit QoS control word
241
+ define_attr :qos_ctrl, BinStruct::Int16
242
+ # @!attribute ht_ctrl
243
+ # @return [Integer] 16-bit HT control word
244
+ define_attr :ht_ctrl, BinStruct::Int32
245
+ # @!attribute body
246
+ # @return [BinStruct::String]
247
+ define_attr :body, BinStruct::String
248
+ # @!attribute fcs
249
+ # @return [BinStruct::Int32le]
250
+ define_attr :fcs, BinStruct::Int32le
256
251
 
257
252
  alias duration id
258
253
  # @private
259
- alias old_fields fields
254
+ alias old_attributes attributes
260
255
 
261
256
  # @param [Hash] options
262
257
  # @see Base#initialize
263
258
  def initialize(options={})
264
259
  super
265
- @applicable_fields = old_fields
260
+ @applicable_attributes = old_attributes
266
261
  end
267
262
 
268
263
  # Get all used field names
269
264
  # @return [Array<Symbol>]
270
- def fields
271
- @applicable_fields
265
+ def attributes
266
+ @applicable_attributes
272
267
  end
273
268
 
274
269
  # @private
@@ -281,24 +276,24 @@ module PacketGen
281
276
  def read(str)
282
277
  fcs = Dot11.fcs?
283
278
 
284
- if self.instance_of? Dot11
279
+ if self.instance_of?(Dot11)
285
280
  return self if str.nil?
286
281
 
287
282
  force_binary str
288
- self[:frame_ctrl].read str[0, 2]
283
+ self[:frame_ctrl].read(str[0, 2])
289
284
 
290
285
  case type
291
286
  when 0
292
- Dot11::Management.new.read str
287
+ Dot11::Management.new.read(str)
293
288
  when 1
294
- Dot11::Control.new.read str
289
+ Dot11::Control.new.read(str)
295
290
  when 2
296
- Dot11::Data.new.read str
291
+ Dot11::Data.new.read(str)
297
292
  else
298
- private_read str, fcs
293
+ private_read(str, fcs)
299
294
  end
300
295
  else
301
- private_read str, fcs
296
+ private_read(str, fcs)
302
297
  end
303
298
  end
304
299
 
@@ -312,8 +307,8 @@ module PacketGen
312
307
 
313
308
  # @return [String]
314
309
  def to_s
315
- define_applicable_fields
316
- @applicable_fields.map { |f| force_binary @fields[f].to_s }.join
310
+ define_applicable_attributes
311
+ @applicable_attributes.map { |f| force_binary @attributes[f].to_s }.join
317
312
  end
318
313
 
319
314
  # Get human readable type
@@ -324,19 +319,19 @@ module PacketGen
324
319
 
325
320
  # @return [String]
326
321
  def inspect
327
- str = if self.instance_of? Dot11
322
+ str = if self.instance_of?(Dot11)
328
323
  Inspect.dashed_line("#{self.class} #{human_type}", 1)
329
- elsif self.respond_to? :human_subtype
324
+ elsif self.respond_to?(:human_subtype)
330
325
  Inspect.dashed_line("#{self.class} #{human_subtype}", 1)
331
326
  else
332
327
  Inspect.dashed_line(self.class.to_s, 1)
333
328
  end
334
329
 
335
- define_applicable_fields
336
- @applicable_fields.each do |attr|
330
+ define_applicable_attributes
331
+ @applicable_attributes.each do |attr|
337
332
  next if attr == :body
338
333
 
339
- str << Inspect.inspect_attribute(attr, @fields[attr], 1)
334
+ str << Inspect.inspect_attribute(attr, @attributes[attr], 1)
340
335
  end
341
336
  str
342
337
  end
@@ -354,46 +349,46 @@ module PacketGen
354
349
  # @param [Packet] packet
355
350
  # @return [void]
356
351
  def added_to_packet(packet)
357
- return if packet.respond_to? :dot11
352
+ return if packet.respond_to?(:dot11)
358
353
 
359
354
  packet.instance_eval("def dot11(arg=nil); header(#{self.class}, arg); end") # def dot11(arg=nil); header(Dot11, arg); end
360
355
  end
361
356
 
362
357
  private
363
358
 
364
- def remove_from_applicable_fields(fields)
365
- fields = [fields] unless fields.is_a? Array
366
- @applicable_fields -= fields
359
+ def remove_from_applicable_attributes(attributes)
360
+ attributes = [attributes] unless attributes.is_a? Array
361
+ @applicable_attributes -= attributes
367
362
  end
368
363
 
369
364
  def handle_mac4
370
365
  if to_ds? && from_ds?
371
- @applicable_fields[6, 0] = :mac4 unless @applicable_fields.include? :mac4
366
+ @applicable_attributes[6, 0] = :mac4 unless @applicable_attributes.include?(:mac4)
372
367
  else
373
- remove_from_applicable_fields :mac4
368
+ remove_from_applicable_attributes(:mac4)
374
369
  end
375
370
  end
376
371
 
377
372
  def handle_ht_ctrl
378
373
  if order?
379
- unless @applicable_fields.include? :ht_ctrl
380
- idx = @applicable_fields.index(:body)
381
- @applicable_fields[idx, 0] = :ht_ctrl
374
+ unless @applicable_attributes.include?(:ht_ctrl)
375
+ idx = @applicable_attributes.index(:body)
376
+ @applicable_attributes[idx, 0] = :ht_ctrl
382
377
  end
383
378
  else
384
- remove_from_applicable_fields %i[ht_ctrl]
379
+ remove_from_applicable_attributes %i[ht_ctrl]
385
380
  end
386
381
  end
387
382
 
388
383
  def handle_fcs
389
384
  if Dot11.fcs?
390
- @applicable_fields << :fcs unless @applicable_fields.include? :fcs
385
+ @applicable_attributes << :fcs unless @applicable_attributes.include?(:fcs)
391
386
  else
392
- remove_from_applicable_fields :fcs
387
+ remove_from_applicable_attributes(:fcs)
393
388
  end
394
389
  end
395
390
 
396
- def define_applicable_fields
391
+ def define_applicable_attributes
397
392
  handle_mac4
398
393
  handle_ht_ctrl
399
394
  handle_fcs
@@ -401,12 +396,12 @@ module PacketGen
401
396
 
402
397
  def private_read(str, fcs)
403
398
  self[:frame_ctrl].read str[0, 2]
404
- define_applicable_fields
399
+ define_applicable_attributes
405
400
  if fcs
406
- old_read str[0...-4]
407
- self[:fcs].read str[-4..]
401
+ old_read(str[0...-4])
402
+ self[:fcs].read(str[-4..])
408
403
  else
409
- old_read str
404
+ old_read(str)
410
405
  end
411
406
  self
412
407
  end
@@ -11,9 +11,9 @@ module PacketGen
11
11
  # IEEE 802.1Q VLAN tagging
12
12
  #
13
13
  # A VLAN tag consists of:
14
- # * a {#tci Tag Control Information} ({Types::Int16}),
15
- # * a {#ethertype} ({Types::Int16}),
16
- # * and a body (a {Types::String} or another Header class).
14
+ # * a {#tci Tag Control Information} ({BinStruct::Int16}),
15
+ # * a {#ethertype} ({BinStruct::Int16}),
16
+ # * and a body (a {BinStruct::String} or another Header class).
17
17
  #
18
18
  # == Create a Dot1q header
19
19
  # # Create a IP packet in VLAN #43
@@ -23,21 +23,19 @@ module PacketGen
23
23
  class Dot1q < Base
24
24
  # @!attribute tci
25
25
  # @return [Integer] 16-bit Tag Control Information
26
- define_field :tci, Types::Int16
27
- # @!attribute ethertype
28
- # @return [Integer] 16-bit EtherType
29
- define_field :ethertype, Types::Int16
30
- # @!attribute body
31
- # @return [Types::String,Header::Base]
32
- define_field :body, Types::String
33
-
34
26
  # @!attribute pcp
35
27
  # @return [Integer] 3-bit Priority Code Point from {#tci}
36
28
  # @!attribute dei
37
29
  # @return [Boolean] Drop Eligible Indicator from {#tci}
38
30
  # @!attribute vid
39
31
  # @return [Integer] 12-bit VLAN ID from {#tci}
40
- define_bit_fields_on :tci, :pcp, 3, :dei, :vid, 12
32
+ define_bit_attr :tci, pcp: 3, dei: 1, vid: 12
33
+ # @!attribute ethertype
34
+ # @return [Integer] 16-bit EtherType
35
+ define_attr :ethertype, BinStruct::Int16
36
+ # @!attribute body
37
+ # @return [BinStruct::String,Header::Base]
38
+ define_attr :body, BinStruct::String
41
39
  end
42
40
 
43
41
  Eth.bind Dot1q, ethertype: 0x8100
@@ -11,10 +11,10 @@ module PacketGen
11
11
  # IEEE 802.1X / EAPOL
12
12
  #
13
13
  # A IEEE 802.1X header consists of:
14
- # * a {#version} ({Types::Int8}),
15
- # * a packet {#type} ({Types::Int8}),
16
- # * a {#length} ({Types::Int16}),
17
- # * and a body (a {Types::String} or another Header class).
14
+ # * a {#version} ({BinStruct::Int8}),
15
+ # * a packet {#type} ({BinStruct::Int8}),
16
+ # * a {#length} ({BinStruct::Int16}),
17
+ # * and a body (a {BinStruct::String} or another Header class).
18
18
  # == Create a Dot1x header
19
19
  # pkt1 = PacketGen.gen('Eth').add('Dot1x', type: 1)
20
20
  # pkt2 = PacketGen.gen('Eth').add('Dot1x')
@@ -37,16 +37,16 @@ module PacketGen
37
37
 
38
38
  # @!attribute version
39
39
  # @return [Integer] 8-bit Protocol Version
40
- define_field :version, Types::Int8, default: 1
40
+ define_attr :version, BinStruct::Int8, default: 1
41
41
  # @!attribute type
42
42
  # @return [Integer] 8-bit Packet Type
43
- define_field :type, Types::Int8Enum, enum: TYPES
43
+ define_attr :type, BinStruct::Int8Enum, enum: TYPES
44
44
  # @!attribute length
45
45
  # @return [Integer] 16-bit body length
46
- define_field :length, Types::Int16
46
+ define_attr :length, BinStruct::Int16
47
47
  # @!attribute body
48
- # @return [Types::String,Header::Base]
49
- define_field :body, Types::String, builder: ->(h, t) { t.new(length_from: h[:length]) }
48
+ # @return [BinStruct::String,Header::Base]
49
+ define_attr :body, BinStruct::String, builder: ->(h, t) { t.new(length_from: h[:length]) }
50
50
 
51
51
  # Get human readable type
52
52
  # @return [String]
@@ -13,13 +13,13 @@ module PacketGen
13
13
  # Secure Tunneling, {https://tools.ietf.org/html/rfc4851 RFC 4851}
14
14
  #
15
15
  # {EAP::FAST} has following fields:
16
- # * {#flags} ({Types::Int8}),
17
- # * optionally {#message_length} ({Types::Int32}), if +#l?+ is +true+,
18
- # * {#body} ({Types::String}).
16
+ # * {#flags} ({BinStruct::Int8}),
17
+ # * optionally {#message_length} ({BinStruct::Int32}), if +#l?+ is +true+,
18
+ # * {#body} ({BinStruct::String}).
19
19
  # @author Sylvain Daubert
20
20
  # @since 2.1.4
21
21
  class FAST < TTLS
22
- update_field :type, default: 43
22
+ update_attr :type, default: 43
23
23
  end
24
24
  end
25
25
  end
@@ -14,19 +14,19 @@ module PacketGen
14
14
  # @author Sylvain Daubert
15
15
  # @since 2.1.4
16
16
  class MD5 < EAP
17
- update_field :type, default: 4
18
- remove_field :body
17
+ update_attr :type, default: 4
18
+ remove_attr :body
19
19
 
20
20
  # @!attribute value_size
21
21
  # @return [Integer] 8-bit value size
22
- define_field :value_size, Types::Int8
22
+ define_attr :value_size, BinStruct::Int8
23
23
  # @!attribute value
24
24
  # @return [::String]
25
- define_field :value, Types::String,
26
- builder: ->(h, t) { t.new(length_from: h[:value_size]) }
25
+ define_attr :value, BinStruct::String,
26
+ builder: ->(h, t) { t.new(length_from: h[:value_size]) }
27
27
  # @!attribute optional_name
28
28
  # @return [::String]
29
- define_field :optional_name, Types::String
29
+ define_attr :optional_name, BinStruct::String
30
30
  end
31
31
  end
32
32
  end
@@ -13,27 +13,25 @@ module PacketGen
13
13
  # {https://tools.ietf.org/html/rfc5216 RFC 5216}
14
14
  #
15
15
  # {EAP::TLS} has following fields:
16
- # * {#flags} ({Types::Int8}),
17
- # * optionally {#tls_length} ({Types::Int32}), if +#l?+ is +true+,
18
- # * {#body} ({Types::String}).
16
+ # * {#flags} ({BinStruct::Int8}),
17
+ # * optionally {#tls_length} ({BinStruct::Int32}), if +#l?+ is +true+,
18
+ # * {#body} ({BinStruct::String}).
19
19
  # @author Sylvain Daubert
20
20
  # @since 2.1.4
21
21
  class TLS < EAP
22
- update_field :type, default: 13
22
+ update_attr :type, default: 13
23
23
  # @!attribute flags
24
24
  # @return [Integer] 8-bit flags
25
- define_field_before :body, :flags, Types::Int8
26
-
27
25
  # @!attribute l
28
- # Say if length field is included. Defined on {#flags} field.
29
- # @return [Boolean]
26
+ # Say if length field is included
27
+ # @return [Integer]
30
28
  # @!attribute m
31
- # Say if there are more fragments. Defined on {#flags} field.
32
- # @return [Boolean]
29
+ # Say if there are more fragments
30
+ # @return [Integer]
33
31
  # @!attribute s
34
- # If set, this message is a TLS-Start. Defined on {#flags} field.
35
- # @return [Boolean]
36
- define_bit_fields_on :flags, :l, :m, :s, :reserved, 5
32
+ # If set, this message is a TLS-Start
33
+ # @return [Integer]
34
+ define_bit_attr_before :body, :flags, l: 1, m: 1, s: 1, reserved: 5
37
35
  alias length_present? l?
38
36
  alias more_fragments? m?
39
37
  alias tls_start? s?
@@ -43,8 +41,8 @@ module PacketGen
43
41
  # TLS message or set of messages that is being fragmented. So, it
44
42
  # cannot be automatically calculated (no +#calc_length+ method).
45
43
  # @return [Integer] 32-bit TLS length
46
- define_field_before :body, :tls_length, Types::Int32,
47
- optional: ->(h) { h.l? }
44
+ define_attr_before :body, :tls_length, BinStruct::Int32,
45
+ optional: lambda(&:l?)
48
46
 
49
47
  # @return [String]
50
48
  def inspect
@@ -13,31 +13,29 @@ module PacketGen
13
13
  # {https://tools.ietf.org/html/rfc5281 RFC 5281}
14
14
  #
15
15
  # {EAP::TTLS} has following fields:
16
- # * {#flags} ({Types::Int8}),
17
- # * optionally {#message_length} ({Types::Int32}), if +#l?+ is +true+,
18
- # * {#body} ({Types::String}).
16
+ # * {#flags} ({BinStruct::Int8}),
17
+ # * optionally {#message_length} ({BinStruct::Int32}), if +#l?+ is +true+,
18
+ # * {#body} ({BinStruct::String}).
19
19
  # @author Sylvain Daubert
20
20
  # @since 2.1.4
21
21
  class TTLS < EAP
22
- update_field :type, default: 21
22
+ update_attr :type, default: 21
23
23
  # @!attribute flags
24
24
  # @return [Integer] 8-bit flags
25
- define_field_before :body, :flags, Types::Int8
26
-
27
25
  # @!attribute l
28
- # Say if length field is included. Defined on {#flags} field.
29
- # @return [Boolean]
26
+ # Say if length field is included
27
+ # @return [Integer]
30
28
  # @!attribute m
31
- # Say if there are more fragments. Defined on {#flags} field.
32
- # @return [Boolean]
29
+ # Say if there are more fragments
30
+ # @return [Integer]
33
31
  # @!attribute s
34
- # If set, this message is a TLS-Start. Defined on {#flags} field.
35
- # @return [Boolean]
32
+ # If set, this message is a TLS-Start
33
+ # @return [Integer]
36
34
  # @!attribute reserved
37
35
  # @return [Integer] 2-bit reserved integer
38
36
  # @!attribute version
39
37
  # @return [Integer] 3-bit version
40
- define_bit_fields_on :flags, :l, :m, :s, :reserved, 2, :version, 3
38
+ define_bit_attr_before :body, :flags, l: 1, m: 1, s: 1, reserved: 2, version: 3
41
39
  alias length_present? l?
42
40
  alias more_fragments? m?
43
41
  alias tls_start? s?
@@ -47,8 +45,8 @@ module PacketGen
47
45
  # raw data message sequence prior to fragmentation. So, it
48
46
  # cannot be automatically calculated (no +#calc_length+ method).
49
47
  # @return [Integer] 32-bit message length
50
- define_field_before :body, :message_length, Types::Int32,
51
- optional: ->(h) { h.l? }
48
+ define_attr_before :body, :message_length, BinStruct::Int32,
49
+ optional: lambda(&:l?)
52
50
 
53
51
  # @return [String]
54
52
  def inspect