packetgen 3.3.2 → 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 +34 -29
  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
@@ -12,7 +12,7 @@ module PacketGen
12
12
  # RFC 2131}
13
13
  #
14
14
  # A DHCP header is quite simple. It is composed of:
15
- # * a {#magic} field ({Types::Int32}) to retrieve it in a BOOTP header,
15
+ # * a {#magic} field ({BinStruct::Int32}) to retrieve it in a BOOTP header,
16
16
  # * a, {#options} field ({Options} type, which is a collection of DHCP
17
17
  # options).
18
18
  #
@@ -50,10 +50,10 @@ module PacketGen
50
50
 
51
51
  # @!attribute magic
52
52
  # @return [Integer]
53
- define_field :magic, Types::Int32, default: 0x63825563
53
+ define_attr :magic, BinStruct::Int32, default: 0x63825563
54
54
  # @!attribute options
55
55
  # @return [DHCP::Options]
56
- define_field :options, DHCP::Options
56
+ define_attr :options, DHCP::Options
57
57
 
58
58
  # differentiate from BOOTP by checking presence of DHCP magic
59
59
  # @return [Boolean]
@@ -11,8 +11,8 @@ module PacketGen
11
11
  class DHCPv6
12
12
  # @abstract Base class for DUID (DHCP Unique ID)
13
13
  # @author Sylvain Daubert
14
- class DUID < Types::Fields
15
- include Types::Fieldable
14
+ class DUID < BinStruct::Struct
15
+ include BinStruct::Structable
16
16
 
17
17
  TYPES = {
18
18
  'DUID-LLT' => 1,
@@ -23,12 +23,12 @@ module PacketGen
23
23
  # @!attribute type
24
24
  # 16-bit DUID type
25
25
  # @return [Integer]
26
- define_field :type, Types::Int16Enum, enum: TYPES
26
+ define_attr :type, BinStruct::Int16Enum, enum: TYPES
27
27
  # @!attribute body
28
- # @abstract replaced by specific fields in subclasses
28
+ # @abstract replaced by specific attributes.in subclasses
29
29
  # DUID data.
30
30
  # @return [String]
31
- define_field :body, Types::String
31
+ define_attr :body, BinStruct::String
32
32
 
33
33
  alias private_read read
34
34
  private :private_read
@@ -50,7 +50,7 @@ module PacketGen
50
50
  self
51
51
  end
52
52
  else
53
- private_read str
53
+ private_read(str)
54
54
  end
55
55
  end
56
56
 
@@ -72,7 +72,7 @@ module PacketGen
72
72
  # DUID Based on Link-layer Address Plus Time
73
73
  # @author Sylvain Daubert
74
74
  class DUID_LLT < DUID
75
- remove_field :body
75
+ remove_attr :body
76
76
 
77
77
  # Base time for time computation
78
78
  BASE_TIME = Time.utc(2000, 1, 1)
@@ -80,14 +80,14 @@ module PacketGen
80
80
  # @!attribute htype
81
81
  # 16-bit hardware protocol type
82
82
  # @return [Integer]
83
- define_field :htype, Types::Int16, default: 1
83
+ define_attr :htype, BinStruct::Int16, default: 1
84
84
  # @!attribute time
85
85
  # 32-bit time information
86
86
  # @return [Time]
87
- define_field :time, Types::Int32, default: (Time.now - BASE_TIME).to_i
87
+ define_attr :time, BinStruct::Int32, default: (Time.now - BASE_TIME).to_i
88
88
  # @!attribute link_addr
89
89
  # @return [Eth::MacAddr]
90
- define_field :link_addr, Eth::MacAddr
90
+ define_attr :link_addr, Eth::MacAddr
91
91
 
92
92
  undef time, time=
93
93
 
@@ -112,15 +112,15 @@ module PacketGen
112
112
  # DUID Based on Enterprise Number
113
113
  # @author Sylvain Daubert
114
114
  class DUID_EN < DUID
115
- remove_field :body
115
+ remove_attr :body
116
116
 
117
117
  # @!attribute en
118
118
  # 32-bit entreprise number
119
119
  # @return [Integer]
120
- define_field :en, Types::Int32
120
+ define_attr :en, BinStruct::Int32
121
121
  # @!attribute identifier
122
122
  # @return [String]
123
- define_field :identifier, Types::String
123
+ define_attr :identifier, BinStruct::String
124
124
 
125
125
  # Get human-readable DUID description
126
126
  # @return [String]
@@ -132,15 +132,15 @@ module PacketGen
132
132
  # DUID Based on Link-layer
133
133
  # @author Sylvain Daubert
134
134
  class DUID_LL < DUID
135
- remove_field :body
135
+ remove_attr :body
136
136
 
137
137
  # @!attribute htype
138
138
  # 16-bit hardware protocol type
139
139
  # @return [Integer]
140
- define_field :htype, Types::Int16, default: 1
140
+ define_attr :htype, BinStruct::Int16, default: 1
141
141
  # @!attribute link_addr
142
142
  # @return [Eth::MacAddr]
143
- define_field :link_addr, Eth::MacAddr
143
+ define_attr :link_addr, Eth::MacAddr
144
144
 
145
145
  # Get human-readable DUID description
146
146
  # @return [String]
@@ -10,29 +10,29 @@ module PacketGen
10
10
  module Header
11
11
  class DHCPv6
12
12
  # A DHCPv6 consists of:
13
- # * a {#type} ({Types::Int16}),
14
- # * a {#length} ({Types::Int16}),
15
- # * and a {#data} ({Types::String}).
13
+ # * a {#type} ({BinStruct::Int16}),
14
+ # * a {#length} ({BinStruct::Int16}),
15
+ # * and a {#data} ({BinStruct::String}).
16
16
  #
17
17
  # Subclasses handles known options. These subclasses may remove {#data}
18
18
  # field to replace it by specific option field(s).
19
19
  # @author Sylvain Daubert
20
- class Option < Types::Fields
21
- include Types::Fieldable
20
+ class Option < BinStruct::Struct
21
+ include BinStruct::Structable
22
22
 
23
23
  # @!attribute type
24
24
  # 16-bit option type
25
25
  # @return [Integer]
26
- define_field :type, Types::Int16
26
+ define_attr :type, BinStruct::Int16
27
27
  # @!attribute length
28
28
  # 16-bit option length
29
29
  # @return [Integer]
30
- define_field :length, Types::Int16
30
+ define_attr :length, BinStruct::Int16
31
31
  # @!attribute data
32
32
  # variable length option data.
33
33
  # @return [String]
34
- define_field :data, Types::String,
35
- builder: ->(h, t) { t.new(length_from: h[:length]) }
34
+ define_attr :data, BinStruct::String,
35
+ builder: ->(h, t) { t.new(length_from: h[:length]) }
36
36
 
37
37
  class << self
38
38
  # Get Option subclasses
@@ -63,7 +63,7 @@ module PacketGen
63
63
  when String
64
64
  if DHCPv6.const_defined?(options[:type])
65
65
  klass = DHCPv6.const_get(options[:type])
66
- options.delete :type
66
+ options.delete(:type)
67
67
  klass.new(options) if klass < Option
68
68
  end
69
69
  else
@@ -96,7 +96,7 @@ module PacketGen
96
96
  # Get a human-readable string for this option
97
97
  # @return [String]
98
98
  def to_human
99
- str = +"#{human_type}:"
99
+ str = "#{human_type}:"
100
100
  if respond_to?(:human_data) && !human_data.empty?
101
101
  str << human_data
102
102
  elsif !self[:data].nil?
@@ -111,12 +111,12 @@ module PacketGen
111
111
  # DHCPv6 Client ID option
112
112
  # @author Sylvain Daubert
113
113
  class ClientID < Option
114
- update_field :type, default: 1
115
- remove_field :data
114
+ update_attr :type, default: 1
115
+ remove_attr :data
116
116
 
117
117
  # @!attribute duid
118
118
  # @return [DUID]
119
- define_field :duid, DUID
119
+ define_attr :duid, DUID
120
120
 
121
121
  # Get human-readable data (DUID)
122
122
  # @return [String]
@@ -128,32 +128,32 @@ module PacketGen
128
128
  # DHCPv6 Server ID option
129
129
  # @author Sylvain Daubert
130
130
  class ServerID < ClientID
131
- update_field :type, default: 2
131
+ update_attr :type, default: 2
132
132
  end
133
133
 
134
134
  # DHCPv6 Identity Association for Non-temporary Addresses Option
135
135
  # @author Sylvain Daubert
136
136
  class IANA < Option
137
- update_field :type, default: 3
138
- remove_field :data
137
+ update_attr :type, default: 3
138
+ remove_attr :data
139
139
 
140
140
  # @!attribute iaid
141
141
  # 32-bit IAID field
142
142
  # @return [Integer]
143
- define_field :iaid, Types::Int32
143
+ define_attr :iaid, BinStruct::Int32
144
144
  # @!attribute t1
145
145
  # 32-bit T1 field
146
146
  # @return [Integer]
147
- define_field :t1, Types::Int32
147
+ define_attr :t1, BinStruct::Int32
148
148
  # @!attribute t2
149
149
  # 32-bit T2 field
150
150
  # @return [Integer]
151
- define_field :t2, Types::Int32
151
+ define_attr :t2, BinStruct::Int32
152
152
  # @!attribute options
153
153
  # options field
154
154
  # @return [String]
155
- define_field :options, Types::String,
156
- builder: ->(h, t) { t.new length_from: -> { h[:length].to_i - 12 } }
155
+ define_attr :options, BinStruct::String,
156
+ builder: ->(h, t) { t.new length_from: -> { h[:length].to_i - 12 } }
157
157
 
158
158
  # Get human-readable data (IAID, T1 and T2)
159
159
  # @return [String]
@@ -165,18 +165,18 @@ module PacketGen
165
165
  # DHCPv6 Identity Association for Temporary Addresses Option
166
166
  # @author Sylvain Daubert
167
167
  class IATA < Option
168
- update_field :type, default: 4
169
- remove_field :data
168
+ update_attr :type, default: 4
169
+ remove_attr :data
170
170
 
171
171
  # @!attribute iaid
172
172
  # 32-bit IAID field
173
173
  # @return [Integer]
174
- define_field :iaid, Types::Int32
174
+ define_attr :iaid, BinStruct::Int32
175
175
  # @!attribute options
176
176
  # options field
177
177
  # @return [String]
178
- define_field :options, Types::String,
179
- builder: ->(h, t) { t.new length_from: -> { h[:length].to_i - 4 } }
178
+ define_attr :options, BinStruct::String,
179
+ builder: ->(h, t) { t.new length_from: -> { h[:length].to_i - 4 } }
180
180
 
181
181
  # Get human-readable data (IAID)
182
182
  # @return [String]
@@ -188,26 +188,26 @@ module PacketGen
188
188
  # DHCPv6 IA Address option
189
189
  # @author Sylvain Daubert
190
190
  class IAAddr < Option
191
- update_field :type, default: 5
192
- remove_field :data
191
+ update_attr :type, default: 5
192
+ remove_attr :data
193
193
 
194
194
  # @attribute ipv6
195
195
  # IPv6 address
196
196
  # @return [IPv6::Addr]
197
- define_field :ipv6, IPv6::Addr
197
+ define_attr :ipv6, IPv6::Addr
198
198
  # @attribute preferred_lifetime
199
199
  # 32-bit preferred lifetime
200
200
  # @return [Integer]
201
- define_field :preferred_lifetime, Types::Int32
201
+ define_attr :preferred_lifetime, BinStruct::Int32
202
202
  # @attribute valid_lifetime
203
203
  # 32-bit valid lifetime
204
204
  # @return [Integer]
205
- define_field :valid_lifetime, Types::Int32
205
+ define_attr :valid_lifetime, BinStruct::Int32
206
206
  # @!attribute options
207
207
  # options field
208
208
  # @return [String]
209
- define_field :options, Types::String,
210
- builder: ->(h, t) { t.new length_from: -> { h[:length].to_i - 24 } }
209
+ define_attr :options, BinStruct::String,
210
+ builder: ->(h, t) { t.new length_from: -> { h[:length].to_i - 24 } }
211
211
 
212
212
  # Get human-readable data (ipv6, preferred lifetime and valid lifetime)
213
213
  # @return [String]
@@ -217,21 +217,21 @@ module PacketGen
217
217
  end
218
218
 
219
219
  # List of requested options for {ORO} option.
220
- # Set of {Types::Int16}
220
+ # Set of {BinStruct::Int16}
221
221
  # @author Sylvain Daubert
222
- class RequestedOptions < Types::Array
223
- set_of Types::Int16
222
+ class RequestedOptions < BinStruct::Array
223
+ set_of BinStruct::Int16
224
224
  end
225
225
 
226
226
  # DHCPv6 Option Request Option
227
227
  # @author Sylvain Daubert
228
228
  class ORO < Option
229
- update_field :type, default: 6
230
- remove_field :data
229
+ update_attr :type, default: 6
230
+ remove_attr :data
231
231
 
232
232
  # @!attribute options
233
233
  # @return [RequestedOptions]
234
- define_field :options, RequestedOptions, builder: ->(h, t) { t.new(length_from: h[:length]) }
234
+ define_attr :options, RequestedOptions, builder: ->(h, t) { t.new(length_from: h[:length]) }
235
235
 
236
236
  # Get human-readable data
237
237
  # @return [String]
@@ -243,13 +243,13 @@ module PacketGen
243
243
  # DHCPv6 Preference option
244
244
  # @author Sylvain Daubert
245
245
  class Preference < Option
246
- update_field :type, default: 7
247
- remove_field :data
246
+ update_attr :type, default: 7
247
+ remove_attr :data
248
248
 
249
249
  # @!attribute value
250
250
  # 8-bit value
251
251
  # @return [Integer]
252
- define_field :value, Types::Int8
252
+ define_attr :value, BinStruct::Int8
253
253
 
254
254
  # Get human-readable data (value)
255
255
  # @return [String]
@@ -261,13 +261,13 @@ module PacketGen
261
261
  # DHCPv6 Elapsed Time option
262
262
  # @author Sylvain Daubert
263
263
  class ElapsedTime < Option
264
- update_field :type, default: 8
265
- remove_field :data
264
+ update_attr :type, default: 8
265
+ remove_attr :data
266
266
 
267
267
  # @!attribute value
268
268
  # 16-bit value
269
269
  # @return [Integer]
270
- define_field :value, Types::Int16
270
+ define_attr :value, BinStruct::Int16
271
271
 
272
272
  # Get human-readable data (value)
273
273
  # @return [String]
@@ -279,19 +279,19 @@ module PacketGen
279
279
  # DHCPv6 Relay Message option
280
280
  # @author Sylvain Daubert
281
281
  class RelayMessage < Option
282
- update_field :type, default: 9
282
+ update_attr :type, default: 9
283
283
  end
284
284
 
285
285
  # DHCPv6 Server Unicast option
286
286
  # @author Sylvain Daubert
287
287
  class ServerUnicast < Option
288
- update_field :type, default: 12
289
- remove_field :data
288
+ update_attr :type, default: 12
289
+ remove_attr :data
290
290
 
291
291
  # @!attribute addr
292
292
  # IPv6 server address
293
293
  # @return [IPv6::Addr]
294
- define_field :addr, IPv6::Addr
294
+ define_attr :addr, IPv6::Addr
295
295
 
296
296
  # Get human-readable data (addr)
297
297
  # @return [String]
@@ -303,14 +303,14 @@ module PacketGen
303
303
  # DHCPv6 Status Code option
304
304
  # @author Sylvain Daubert
305
305
  class StatusCode < ElapsedTime
306
- update_field :type, default: 13
306
+ update_attr :type, default: 13
307
307
  end
308
308
 
309
309
  # DHCPv6 Rapid Commit option
310
310
  # @author Sylvain Daubert
311
311
  class RapidCommit < Option
312
- update_field :type, default: 14
313
- remove_field :data
312
+ update_attr :type, default: 14
313
+ remove_attr :data
314
314
  end
315
315
  end
316
316
  end
@@ -19,7 +19,7 @@ module PacketGen
19
19
  # duid = PacketGen::Header::DHCPv6::DUID_LL.new(link_addr: '08:00:27:fe:8f:95')
20
20
  # options << { type: 1, duid: duid }
21
21
  # @author Sylvain Daubert
22
- class Options < Types::Array
22
+ class Options < BinStruct::Array
23
23
  set_of DHCPv6::Option
24
24
 
25
25
  # Separator used in {#to_human}.
@@ -21,25 +21,25 @@ module PacketGen
21
21
  # @!attribute msg_type
22
22
  # 8-bit message type
23
23
  # @return [Integer]
24
- define_field :msg_type, Types::Int8Enum, enum: MESSAGE_TYPES
24
+ define_attr :msg_type, BinStruct::Int8Enum, enum: MESSAGE_TYPES
25
25
  # @!attribute hop_count
26
26
  # 8-bit hop count (number of relay agents that have relayed
27
27
  # this message)
28
28
  # @return [Integer]
29
- define_field :hop_count, Types::Int8
29
+ define_attr :hop_count, BinStruct::Int8
30
30
  # @!attribute link
31
31
  # Link address: address that will be used by the server to identify
32
32
  # the link on which the client is located
33
33
  # @return [IPv6::Addr]
34
- define_field :link, IPv6::Addr
34
+ define_attr :link, IPv6::Addr
35
35
  # @!attribute peer
36
36
  # Peer address: the address of the client or relay agent from which
37
37
  # the message to be relayed was received
38
38
  # @return [IPv6::Addr]
39
- define_field :peer, IPv6::Addr
39
+ define_attr :peer, IPv6::Addr
40
40
  # @!attribute options
41
41
  # @return [DHCPv6::Options]
42
- define_field :options, DHCPv6::Options
42
+ define_attr :options, DHCPv6::Options
43
43
  end
44
44
  end
45
45
 
@@ -22,8 +22,8 @@ module PacketGen
22
22
  # | |
23
23
  # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24
24
  # A DHCPv6 header is made of:
25
- # * a {#msg_type} field ({Types::Int8Enum}),
26
- # * a {#transaction_id} field ({Types::Int24}),
25
+ # * a {#msg_type} field ({BinStruct::Int8Enum}),
26
+ # * a {#transaction_id} field ({BinStruct::Int24}),
27
27
  # * and an {#options} field ({DHCPv6::Options}).
28
28
  #
29
29
  # == Create a DHCPv6 header
@@ -72,20 +72,20 @@ module PacketGen
72
72
  # @!attribute msg_type
73
73
  # 8-bit message type
74
74
  # @return [Integer]
75
- define_field :msg_type, Types::Int8Enum, enum: MESSAGE_TYPES
75
+ define_attr :msg_type, BinStruct::Int8Enum, enum: MESSAGE_TYPES
76
76
  # @!attribute transaction_id
77
77
  # 24-bit transaction ID
78
78
  # @return [Integer]
79
- define_field :transaction_id, Types::Int24
79
+ define_attr :transaction_id, BinStruct::Int24
80
80
  # @!attribute options
81
81
  # @return [DHCPv6::Options]
82
- define_field :options, DHCPv6::Options
82
+ define_attr :options, DHCPv6::Options
83
83
 
84
84
  # Populate object from string
85
85
  # @param [String] str
86
86
  # @return [DHCPv6,DHCPv6::Relay]
87
87
  def read(str)
88
- msg_type = Types::Int8.new.read(str)
88
+ msg_type = BinStruct::Int8.new.read(str)
89
89
 
90
90
  case msg_type
91
91
  when 12, 13
@@ -9,26 +9,30 @@
9
9
  module PacketGen
10
10
  module Header
11
11
  class DNS
12
- # DNS Name, defined as a suite of labels. A label is of type {Types::IntString}.
12
+ # DNS Name, defined as a suite of labels. A label is of type {BinStruct::IntString}.
13
13
  # @author Sylvain Daubert
14
- class Name < Types::Array
14
+ # @author LemonTree55
15
+ class Name < BinStruct::Array
15
16
  # Mask to decode a pointer on another label
16
17
  POINTER_MASK = 0xc000
17
18
 
18
19
  # @return [DNS]
19
20
  attr_accessor :dns
20
21
 
21
- def initialize
22
+ # @param [Hash] options
23
+ # @option options [DNS] :dns
24
+ def initialize(options={})
25
+ @dns = options.delete(:dns)
22
26
  super
23
27
  @pointer = nil
24
28
  @pointer_name = nil
25
29
  end
26
30
 
27
31
  # @!method push(label)
28
- # @param [Types::IntString] label
32
+ # @param [BinStruct::IntString] label
29
33
  # @return [Name] self
30
34
  # @!method <<(label)
31
- # @param [Types::IntString] label
35
+ # @param [BinStruct::IntString] label
32
36
  # @return [Name] self
33
37
 
34
38
  # Read a set of labels form a dotted string
@@ -39,9 +43,9 @@ module PacketGen
39
43
  return self if str.nil?
40
44
 
41
45
  str.split('.').each do |label|
42
- self << Types::IntString.new(string: label)
46
+ self << BinStruct::IntString.new(value: label)
43
47
  end
44
- self << Types::IntString.new
48
+ self << BinStruct::IntString.new
45
49
  end
46
50
 
47
51
  # Clear name
@@ -59,11 +63,11 @@ module PacketGen
59
63
  clear
60
64
  return self if str.nil?
61
65
 
62
- PacketGen.force_binary str
66
+ PacketGen.force_binary(str)
63
67
  start = 0
64
68
  loop do
65
69
  index = str[start, 2].unpack1('n')
66
- if pointer? index
70
+ if pointer?(index)
67
71
  # Pointer on another label
68
72
  @pointer = str[start, 2]
69
73
  break
@@ -119,7 +123,7 @@ module PacketGen
119
123
  end
120
124
 
121
125
  def add_label_from(str)
122
- label = Types::IntString.new
126
+ label = BinStruct::IntString.new
123
127
  label.read(str)
124
128
  self << label
125
129
  label
@@ -20,7 +20,7 @@ module PacketGen
20
20
  class OPT < RR
21
21
  # @!attribute options
22
22
  # @return [ArrayOfOptions]
23
- define_field_after :rdata, :options, ArrayOfOptions
23
+ define_attr_after :rdata, :options, ArrayOfOptions
24
24
 
25
25
  # @param [DNS] dns
26
26
  # @param [Hash] options
@@ -94,7 +94,7 @@ module PacketGen
94
94
  self[:ttl].value = self[:ttl].to_i & (0xffffffff & ~(1 << 15))
95
95
  self[:ttl].value |= (b & 1) << 15
96
96
  end
97
- ((self[:ttl].to_i >> 15) & 1) == 1
97
+ self[:ttl].to_i.anybits?(0x8000)
98
98
  end
99
99
  alias do? do=
100
100
 
@@ -11,28 +11,28 @@ module PacketGen
11
11
  class DNS
12
12
  # @!parse
13
13
  # # DNS option is a TLV object:
14
- # # * {#code} is a {Types::Int16},
15
- # # * {#length} is a {Types::Int16},
16
- # # * {#data} is a {Types::String}.
14
+ # # * {#code} is a {BinStruct::Int16},
15
+ # # * {#length} is a {BinStruct::Int16},
16
+ # # * {#data} is a {BinStruct::String}.
17
17
  # #
18
18
  # # @since 1.3.0
19
- # # @since 3.1.0 defined with {Types::AbstractTLV}
20
- # # @!parse class Option < Types::AbstractTLV; end
19
+ # # @since 3.1.0 defined with {BinStruct::AbstractTLV}
20
+ # # @!parse class Option < BinStruct::AbstractTLV; end
21
21
  # # @!attribute code
22
22
  # # Alias for {#type}
23
23
  # # @return [Integer]
24
24
  # # @!attribute data
25
25
  # # Alias for {#value}
26
- # # @return [Types::String]
27
- # class Option < Types::AbstractTLV; end
26
+ # # @return [BinStruct::String]
27
+ # class Option < BinStruct::AbstractTLV; end
28
28
  # @private
29
- Option = Types::AbstractTLV.create(type_class: Types::Int16,
30
- length_class: Types::Int16,
31
- aliases: { code: :type, data: :value })
29
+ Option = BinStruct::AbstractTLV.create(type_class: BinStruct::Int16,
30
+ length_class: BinStruct::Int16,
31
+ aliases: { code: :type, data: :value })
32
32
 
33
33
  # Array of {Option}.
34
34
  # @since 3.1.1
35
- class ArrayOfOptions < Types::Array
35
+ class ArrayOfOptions < BinStruct::Array
36
36
  set_of Option
37
37
  end
38
38
  end
@@ -36,7 +36,7 @@ module PacketGen
36
36
  while !str.empty? && (self.size < @counter.to_i)
37
37
  question = Question.new(@dns).read(str)
38
38
  str.slice!(0, question.sz)
39
- push question
39
+ push(question)
40
40
  end
41
41
  self
42
42
  end
@@ -11,8 +11,8 @@ module PacketGen
11
11
  class DNS
12
12
  # DNS Question
13
13
  # @author Sylvain Daubert
14
- class Question < Types::Fields
15
- include Types::Fieldable
14
+ class Question < BinStruct::Struct
15
+ include BinStruct::Structable
16
16
 
17
17
  # Ressource Record types
18
18
  TYPES = {
@@ -59,15 +59,15 @@ module PacketGen
59
59
  # @!attribute name
60
60
  # Question domain name
61
61
  # @return [String]
62
- define_field :name, Name, default: '.'
62
+ define_attr :name, Name, default: '.'
63
63
  # @!attribute type
64
64
  # 16-bit question type
65
65
  # @return [Integer]
66
- define_field :type, Types::Int16Enum, default: 1, enum: TYPES
66
+ define_attr :type, BinStruct::Int16Enum, default: 1, enum: TYPES
67
67
  # @!attribute rrclass
68
68
  # 16-bit question class
69
69
  # @return [Integer]
70
- define_field :rrclass, Types::Int16Enum, default: 1, enum: CLASSES
70
+ define_attr :rrclass, BinStruct::Int16Enum, default: 1, enum: CLASSES
71
71
 
72
72
  # @param [DNS] dns
73
73
  # @param [Hash] options
@@ -77,8 +77,6 @@ module PacketGen
77
77
  def initialize(dns, options={})
78
78
  super(options)
79
79
  self[:name].dns = dns
80
- self.type = options[:type] if options[:type]
81
- self.rrclass = options[:rrclass] if options[:rrclass]
82
80
  end
83
81
 
84
82
  undef rrclass=
@@ -95,7 +93,7 @@ module PacketGen
95
93
  end
96
94
  raise ArgumentError, "unknown class #{val.inspect}" unless v
97
95
 
98
- self[:rrclass].read v
96
+ self[:rrclass].from_human(v)
99
97
  end
100
98
 
101
99
  # Check type