packetgen 4.0.0 → 4.1.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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/packetgen/deprecation.rb +7 -1
  4. data/lib/packetgen/header/arp.rb +6 -7
  5. data/lib/packetgen/header/asn1_base.rb +2 -1
  6. data/lib/packetgen/header/base.rb +27 -24
  7. data/lib/packetgen/header/bootp.rb +14 -14
  8. data/lib/packetgen/header/dhcp/option.rb +8 -8
  9. data/lib/packetgen/header/dhcp/options.rb +2 -2
  10. data/lib/packetgen/header/dhcp.rb +6 -7
  11. data/lib/packetgen/header/dhcpv6/duid.rb +1 -1
  12. data/lib/packetgen/header/dhcpv6/option.rb +37 -15
  13. data/lib/packetgen/header/dhcpv6/options.rb +3 -3
  14. data/lib/packetgen/header/dhcpv6/relay.rb +1 -0
  15. data/lib/packetgen/header/dhcpv6.rb +13 -14
  16. data/lib/packetgen/header/dns/name.rb +9 -8
  17. data/lib/packetgen/header/dns/opt.rb +3 -0
  18. data/lib/packetgen/header/dns/option.rb +7 -7
  19. data/lib/packetgen/header/dns/qdsection.rb +2 -2
  20. data/lib/packetgen/header/dns/question.rb +1 -0
  21. data/lib/packetgen/header/dns/rrsection.rb +2 -2
  22. data/lib/packetgen/header/dns.rb +76 -60
  23. data/lib/packetgen/header/dot11/control.rb +5 -5
  24. data/lib/packetgen/header/dot11/data.rb +11 -10
  25. data/lib/packetgen/header/dot11/element.rb +1 -1
  26. data/lib/packetgen/header/dot11/management.rb +18 -15
  27. data/lib/packetgen/header/dot11/sub_mngt.rb +22 -21
  28. data/lib/packetgen/header/dot11.rb +38 -38
  29. data/lib/packetgen/header/dot1q.rb +5 -4
  30. data/lib/packetgen/header/dot1x.rb +8 -8
  31. data/lib/packetgen/header/eap/fast.rb +3 -3
  32. data/lib/packetgen/header/eap/md5.rb +11 -3
  33. data/lib/packetgen/header/eap/tls.rb +9 -8
  34. data/lib/packetgen/header/eap/ttls.rb +13 -10
  35. data/lib/packetgen/header/eap.rb +58 -33
  36. data/lib/packetgen/header/eth.rb +26 -12
  37. data/lib/packetgen/header/gre.rb +26 -2
  38. data/lib/packetgen/header/http/headers.rb +6 -5
  39. data/lib/packetgen/header/http/request.rb +24 -16
  40. data/lib/packetgen/header/http/response.rb +22 -15
  41. data/lib/packetgen/header/icmp.rb +10 -10
  42. data/lib/packetgen/header/icmpv6.rb +10 -9
  43. data/lib/packetgen/header/igmp.rb +21 -10
  44. data/lib/packetgen/header/igmpv3/group_record.rb +7 -2
  45. data/lib/packetgen/header/igmpv3/mq.rb +1 -1
  46. data/lib/packetgen/header/igmpv3/mr.rb +1 -1
  47. data/lib/packetgen/header/igmpv3.rb +11 -10
  48. data/lib/packetgen/header/ip/addr.rb +6 -2
  49. data/lib/packetgen/header/ip/option.rb +18 -5
  50. data/lib/packetgen/header/ip.rb +52 -35
  51. data/lib/packetgen/header/ipv6/addr.rb +14 -13
  52. data/lib/packetgen/header/ipv6/extension.rb +9 -7
  53. data/lib/packetgen/header/ipv6/hop_by_hop.rb +26 -7
  54. data/lib/packetgen/header/ipv6.rb +31 -22
  55. data/lib/packetgen/header/llc.rb +20 -13
  56. data/lib/packetgen/header/mdns.rb +9 -2
  57. data/lib/packetgen/header/mld.rb +11 -9
  58. data/lib/packetgen/header/mldv2/mcast_address_record.rb +6 -1
  59. data/lib/packetgen/header/mldv2/mlq.rb +8 -8
  60. data/lib/packetgen/header/mldv2/mlr.rb +4 -4
  61. data/lib/packetgen/header/mldv2.rb +1 -1
  62. data/lib/packetgen/header/ospfv2/db_description.rb +10 -10
  63. data/lib/packetgen/header/ospfv2/hello.rb +11 -10
  64. data/lib/packetgen/header/ospfv2/ls_ack.rb +5 -6
  65. data/lib/packetgen/header/ospfv2/ls_request.rb +7 -6
  66. data/lib/packetgen/header/ospfv2/ls_update.rb +7 -7
  67. data/lib/packetgen/header/ospfv2/lsa.rb +33 -10
  68. data/lib/packetgen/header/ospfv2/lsa_header.rb +3 -2
  69. data/lib/packetgen/header/ospfv2.rb +31 -26
  70. data/lib/packetgen/header/ospfv3/db_description.rb +12 -13
  71. data/lib/packetgen/header/ospfv3/hello.rb +10 -9
  72. data/lib/packetgen/header/ospfv3/ipv6_prefix.rb +6 -2
  73. data/lib/packetgen/header/ospfv3/ls_ack.rb +5 -6
  74. data/lib/packetgen/header/ospfv3/ls_request.rb +10 -10
  75. data/lib/packetgen/header/ospfv3/ls_update.rb +7 -7
  76. data/lib/packetgen/header/ospfv3/lsa.rb +23 -9
  77. data/lib/packetgen/header/ospfv3/lsa_header.rb +3 -2
  78. data/lib/packetgen/header/ospfv3.rb +38 -34
  79. data/lib/packetgen/header/sctp/chunk.rb +38 -17
  80. data/lib/packetgen/header/sctp/error.rb +169 -197
  81. data/lib/packetgen/header/sctp/padded32.rb +3 -3
  82. data/lib/packetgen/header/sctp/parameter.rb +85 -132
  83. data/lib/packetgen/header/sctp.rb +14 -3
  84. data/lib/packetgen/header/snmp.rb +108 -7
  85. data/lib/packetgen/header/tcp/option.rb +7 -0
  86. data/lib/packetgen/header/tcp/options.rb +11 -3
  87. data/lib/packetgen/header/tcp.rb +33 -26
  88. data/lib/packetgen/header/tftp.rb +16 -10
  89. data/lib/packetgen/header/udp.rb +15 -13
  90. data/lib/packetgen/header.rb +19 -13
  91. data/lib/packetgen/headerable.rb +9 -3
  92. data/lib/packetgen/inspect.rb +2 -7
  93. data/lib/packetgen/packet.rb +94 -36
  94. data/lib/packetgen/pcapng/block.rb +2 -1
  95. data/lib/packetgen/pcapng/file.rb +41 -14
  96. data/lib/packetgen/pcapng/idb.rb +2 -1
  97. data/lib/packetgen/pcapng/shb.rb +2 -1
  98. data/lib/packetgen/pcapng/spb.rb +1 -1
  99. data/lib/packetgen/pcapng.rb +2 -0
  100. data/lib/packetgen/proto.rb +4 -0
  101. data/lib/packetgen/unknown_packet.rb +3 -3
  102. data/lib/packetgen/utils.rb +2 -1
  103. data/lib/packetgen/version.rb +1 -1
  104. data/lib/packetgen.rb +8 -2
  105. metadata +4 -4
@@ -11,18 +11,18 @@ module PacketGen
11
11
  class DNS
12
12
  # @!parse
13
13
  # # DNS option is a TLV object:
14
- # # * {#code} is a {BinStruct::Int16},
15
- # # * {#length} is a {BinStruct::Int16},
16
- # # * {#data} is a {BinStruct::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 {BinStruct::AbstractTLV}
19
+ # # @since 3.1.0 defined with BinStruct::AbstractTLV
20
20
  # # @!parse class Option < BinStruct::AbstractTLV; end
21
21
  # # @!attribute code
22
- # # Alias for {#type}
22
+ # # Alias for +#type+
23
23
  # # @return [Integer]
24
24
  # # @!attribute data
25
- # # Alias for {#value}
25
+ # # Alias for +#value+
26
26
  # # @return [BinStruct::String]
27
27
  # class Option < BinStruct::AbstractTLV; end
28
28
  # @private
@@ -30,7 +30,7 @@ module PacketGen
30
30
  length_class: BinStruct::Int16,
31
31
  aliases: { code: :type, data: :value })
32
32
 
33
- # Array of {Option}.
33
+ # Array of {Option}s.
34
34
  # @since 3.1.1
35
35
  class ArrayOfOptions < BinStruct::Array
36
36
  set_of Option
@@ -25,14 +25,14 @@ module PacketGen
25
25
  # @param [Question] q
26
26
  # @return [Question]
27
27
 
28
- # Read Question section from a string
28
+ # Read Question section from a binary string
29
29
  # @param [String] str binary string
30
30
  # @return [QDSection] self
31
31
  def read(str)
32
32
  clear
33
33
  return self if str.nil?
34
34
 
35
- PacketGen.force_binary str
35
+ str = str.b unless str.encoding == Encoding::ASCII_8BIT
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)
@@ -120,6 +120,7 @@ module PacketGen
120
120
  end
121
121
  end
122
122
 
123
+ # Human-readable string for this question
123
124
  # @return [String]
124
125
  def to_human
125
126
  if self[:name].dns.is_a? MDNS
@@ -21,13 +21,13 @@ module PacketGen
21
21
  end
22
22
 
23
23
  # Read RR section from a string
24
- # @param [String] str binary string
24
+ # @param [String] str binary binary string
25
25
  # @return [RRSection] self
26
26
  def read(str)
27
27
  clear
28
28
  return self if str.nil?
29
29
 
30
- PacketGen.force_binary str
30
+ str = str.b unless str.encoding == Encoding::BINARY
31
31
  while !str.empty? && (self.size < @counter.to_i)
32
32
  rr = RR.new(@dns).read(str)
33
33
  rr = OPT.new(@dns).read(str) if rr.type?('OPT')
@@ -33,70 +33,77 @@ module PacketGen
33
33
  # * {#ns}, authoritary section,
34
34
  # * {#ar}, additional information section.
35
35
  #
36
- # == Create a DNS header
37
- # # standalone
38
- # dns = PacketGen::Header::DNS.new
39
- # # in a IP packet
40
- # pkt = PacketGen.gen('IP').add('DNS')
41
- # # access to DNS header
42
- # pkt.dns # => PacketGen::Header::DNS
36
+ # @example Create a DNS header
37
+ # # standalone
38
+ # dns = PacketGen::Header::DNS.new
39
+ # # in a IP packet
40
+ # pkt = PacketGen.gen('IP').add('UDP').add('DNS')
41
+ # # access to DNS header
42
+ # pkt.dns.class # => PacketGen::Header::DNS
43
43
  #
44
- # == DNS attributes
45
- # dns.id = 0x1234
46
- # dns.qr = false
47
- # # opcode may be set as an Integer (all values are possible)
48
- # # or as a String (only keys from PacketGen::Header::DNS::OPCODES)
49
- # dns.opcode = 0xe # set as integer, value not defined in standard
50
- # dns.opcode = 'query' # set as string
51
- # dns.aa = dns.tc = dns.rd = dns.ra = false
52
- # # rcode may be set as an Integer (all values are possible)
53
- # # or as a String (only keys from PacketGen::Header::DNS::RCODES)
54
- # dns.rcode = 11
55
- # dns.rcode = 'refused'
56
- # dns.qdcount = 123
57
- # dns.ancount = 0x1234
58
- # dns.nscount = 1
59
- # dns.arcount = 0
60
- # One can also access to DNS sections:
61
- # dns.qd # => PacketGen::Header::DNS::QDSection
62
- # dns.an # => PacketGen::Header::DNS::RRSection
63
- # dns.ns # => PacketGen::Header::DNS::RRSection
64
- # dns.ar # => PacketGen::Header::DNS::RRSection
44
+ # @example DNS attributes
45
+ # dns = PacketGen::Header::DNS.new
46
+ # dns.id = 0x1234
47
+ # dns.qr = false
48
+ # # opcode may be set as an Integer (all values are possible)
49
+ # # or as a String (only keys from PacketGen::Header::DNS::OPCODES)
50
+ # dns.opcode = 0xe # set as integer, value not defined in standard
51
+ # dns.opcode = 'query' # set as string
52
+ # # Set flags
53
+ # dns.aa = dns.tc = dns.rd = dns.ra = false
54
+ # # rcode may be set as an Integer (all values are possible)
55
+ # # or as a String (only keys from PacketGen::Header::DNS::RCODES)
56
+ # dns.rcode = 11
57
+ # dns.rcode = 'refused'
58
+ # # Section counts may be set by hand. They also be set automatically when adding
59
+ # # an element to a section.
60
+ # dns.qdcount = 123
61
+ # dns.ancount = 0x1234
62
+ # dns.nscount = 1
63
+ # dns.arcount = 0
64
+ # # Access to DNS sections:
65
+ # dns.qd.class # => PacketGen::Header::DNS::QDSection
66
+ # dns.an.class # => PacketGen::Header::DNS::RRSection
67
+ # dns.ns.class # => PacketGen::Header::DNS::RRSection
68
+ # dns.ar.class # => PacketGen::Header::DNS::RRSection
65
69
  #
66
- # == Add a question to DNS question section
67
- # Adding a {Question} with {QDSection#<<} automagically increments {#qdcount}.
68
- # To not modify +qdcount+, use {QDSection#push}.
69
- # # add a question about example.net IP address. Increment qdcount
70
- # dns.qd << PacketGen::Header::DNS::Question.new(dns, name: 'example.net')
71
- # # or
72
- # dns.qd << { rtype: 'Question', name: 'example.net' }
73
- # # add a question about example.net IPv6 address. Dot not modify qdcount
74
- # dns.qd.push PacketGen::Header::DNS::Question.new(dns, name: 'example.net', type: 'AAAA')
75
- # # or
76
- # dns.qd.push({ rtype: 'Question', name: 'example.net', type: 'AAAA' })
70
+ # @example Add a question to DNS question section
71
+ # dns = PacketGen::Header::DNS.new
72
+ # # add a question about example.net IP address. Increment qdcount
73
+ # dns.qd << PacketGen::Header::DNS::Question.new(dns, name: 'example.net')
74
+ # # or
75
+ # dns.qd << { rtype: 'Question', name: 'example.net' }
76
+ # dns.qdcount #=> 2
77
+ # # add a question about example.net IPv6 address. Dot not modify qdcount
78
+ # dns.qd.push(PacketGen::Header::DNS::Question.new(dns, name: 'example.net', type: 'AAAA'))
79
+ # # or
80
+ # dns.qd.push(rtype: 'Question', name: 'example.net', type: 'AAAA')
81
+ # dns.qdcount #=> 2
77
82
  #
78
- # == Add a ressource record to a DNS section
79
- # Adding a {RR} with {RRSection#<< RRSection#<<} automagically increments section counter.
80
- # To not modify it, use {RRSection#push RRSection#push}
81
- # # add a RR to answer section. Increment ancount
82
- # dns.an << PacketGen::Header::DNS::RR.new(dns, name: 'example.net', rdata: IPAddr.new('1.2.3.4').hton)
83
- # # or
84
- # dns.an << { rtype: 'RR', name: 'example.net', rdata: IPAddr.new('1.2.3.4').hton }
85
- # # add a RR to NS section. Dot not modify nscount
86
- # rdata = PacketGen::Header::DNS::Name.new(dns).parse('dns.net')
87
- # dns.ns.push PacketGen::Header::DNS::RR.new(dns, name: 'example.net', type: 'NS', rdata: rdata)
88
- # # or
89
- # dns.ns.push(rtype: 'RR', name: 'example.net', type: 'NS', rdata: rdata)
83
+ # @example Add a ressource record to a DNS section
84
+ # dns = PacketGen::Header::DNS.new
85
+ # # add a RR to answer section. Increment ancount
86
+ # dns.an << PacketGen::Header::DNS::RR.new(dns, name: 'example.net', rdata: IPAddr.new('1.2.3.4').hton)
87
+ # # or
88
+ # dns.an << { rtype: 'RR', name: 'example.net', rdata: IPAddr.new('1.2.3.4').hton }
89
+ # dns.ancount #=> 2
90
+ # # add a RR to NS section. Dot not modify nscount
91
+ # rdata = PacketGen::Header::DNS::Name.new(dns: dns).from_human('dns.net')
92
+ # dns.ns.push(PacketGen::Header::DNS::RR.new(dns, name: 'example.net', type: 'NS', rdata: rdata))
93
+ # # or
94
+ # dns.ns.push(rtype: 'RR', name: 'example.net', type: 'NS', rdata: rdata)
95
+ # dns.nscount #=> 0
90
96
  #
91
- # == Extended DNS EDNS(0)
92
- # # Add an OPT to ar section
93
- # dns.ar << PacketGen::Header::DNS::OPT.new(dns, udp_size: 4096, ext_rcode: 43)
94
- # # or
95
- # dns.ar << { rtype: 'OPT', udp_size: 4096, ext_rcode: 43 }
96
- # # add an option to OPT record
97
- # dns.ar.last.options << PacketGen::Header::DNS::Option.new(code: 48, data: '12')
98
- # # or
99
- # dns.ar.last.options << { code: 48, data: '12' }
97
+ # @example Extended DNS (EDNS(0)) options
98
+ # dns = PacketGen::Header::DNS.new
99
+ # # Add an OPT to ar section
100
+ # dns.ar << PacketGen::Header::DNS::OPT.new(dns, udp_size: 4096, ext_rcode: 43)
101
+ # # or
102
+ # dns.ar << { rtype: 'OPT', udp_size: 4096, ext_rcode: 43 }
103
+ # # add an option to OPT record
104
+ # dns.ar.last.options << PacketGen::Header::DNS::Option.new(code: 48, data: '12')
105
+ # # or
106
+ # dns.ar.last.options << { code: 48, data: '12' }
100
107
  # @author Sylvain Daubert
101
108
  # @since 1.3.0
102
109
  class DNS < Base
@@ -140,6 +147,7 @@ module PacketGen
140
147
  }.freeze
141
148
 
142
149
  # @!attribute id
150
+ # 16-bit identifier to match up replies and queries
143
151
  # @return [Integer]
144
152
  define_attr :id, BinStruct::Int16
145
153
  # @!attribute u16
@@ -166,27 +174,35 @@ module PacketGen
166
174
  undef opcode=, rcode=
167
175
 
168
176
  # @!attribute qdcount
177
+ # Number of entries in {#qd question section}
169
178
  # @return [Integer]
170
179
  define_attr :qdcount, BinStruct::Int16
171
180
  # @!attribute ancount
181
+ # Number of ressource recors in {#an answer section}
172
182
  # @return [Integer]
173
183
  define_attr :ancount, BinStruct::Int16
174
184
  # @!attribute nscount
185
+ # Number of name resource recors in {#ns authority records section}
175
186
  # @return [Integer]
176
187
  define_attr :nscount, BinStruct::Int16
177
188
  # @!attribute arcount
189
+ # Number of ressources recors in {#ar additional records section}
178
190
  # @return [Integer]
179
191
  define_attr :arcount, BinStruct::Int16
180
192
  # @!attribute qd
193
+ # Question section
181
194
  # @return [QDSection]
182
195
  define_attr :qd, QDSection, builder: ->(h, t) { t.new(h, h[:qdcount]) }
183
196
  # @!attribute an
197
+ # Answer section
184
198
  # @return [RRSection]
185
199
  define_attr :an, RRSection, builder: ->(h, t) { t.new(h, h[:ancount]) }
186
200
  # @!attribute ns
201
+ # Authority records section
187
202
  # @return [RRSection]
188
203
  define_attr :ns, RRSection, builder: ->(h, t) { t.new(h, h[:nscount]) }
189
204
  # @!attribute ar
205
+ # Additional record section
190
206
  # @return [RRSection]
191
207
  define_attr :ar, RRSection, builder: ->(h, t) { t.new(h, h[:arcount]) }
192
208
 
@@ -12,16 +12,16 @@ module PacketGen
12
12
  class Dot11
13
13
  # IEEE 802.11 control frame header
14
14
  #
15
- # This class make a {Dot11} header with {#type} set to +1+
15
+ # This class makes a {Dot11} header with {#type} set to +1+
16
16
  # (control frame).
17
17
  #
18
18
  # A IEEE 802.11 control header consists of:
19
- # * a {#frame_ctrl} ({BinStruct::Int16}),
20
- # * a {#id}/duration ({BinStruct::Int16le}),
19
+ # * a {#frame_ctrl} (+BinStruct::Int16+),
20
+ # * a {#id}/duration (+BinStruct::Int16le+),
21
21
  # * a {#mac1} ({Eth::MacAddr}).
22
22
  # * sometimes a {#mac2} ({Eth::MacAddr}),
23
- # * a {#body} (a {BinStruct::String} or another {Base} class),
24
- # * and a Frame check sequence ({#fcs}, of type {BinStruct::Int32le}).
23
+ # * a {#body} (a +BinStruct::String+ or another {Headerable} class),
24
+ # * and a Frame check sequence ({#fcs}, of type +BinStruct::Int32le+).
25
25
  # @author Sylvain Daubert
26
26
  class Control < Dot11
27
27
  # Control subtypes
@@ -16,15 +16,16 @@ module PacketGen
16
16
  # (data frame).
17
17
  #
18
18
  # A IEEE 802.11 data header consists of:
19
- # * a {#frame_ctrl} ({BinStruct::Int16}),
20
- # * a {#id}/duration ({BinStruct::Int16le}),
19
+ # * a {#frame_ctrl} (+BinStruct::Int16+),
20
+ # * a {#id}/duration (+BinStruct::Int16le+),
21
+ # * a {#mac1} ({Eth::MacAddr}),
21
22
  # * a {#mac2} ({Eth::MacAddr}),
22
23
  # * a {#mac3} ({Eth::MacAddr}),
23
- # * a {#sequence_ctrl} ({BinStruct::Int16}),
24
+ # * a {#sequence_ctrl} (+BinStruct::Int16+),
24
25
  # * sometimes a {#mac4} ({Eth::MacAddr}),
25
- # * sometimes a {#qos_ctrl} ({BinStruct::Int16}),
26
- # * a {#body} (a {BinStruct::String} or another {Base} class),
27
- # * and a Frame check sequence ({#fcs}, of type {BinStruct::Int32le}).
26
+ # * sometimes a {#qos_ctrl} (+BinStruct::Int16+),
27
+ # * a {#body} (a +BinStruct::String+ or another {Headerable} class),
28
+ # * and a Frame check sequence ({#fcs}, of type +BinStruct::Int32le+).
28
29
  # @author Sylvain Daubert
29
30
  class Data < Dot11
30
31
  # @param [Hash] options
@@ -65,14 +66,14 @@ module PacketGen
65
66
  self
66
67
  end
67
68
 
68
- # Get destination MAC address
69
+ # Get destination MAC address. {#from_ds} and {#to_ds} must be set before using these method.
69
70
  # @return [String]
70
71
  def dst
71
72
  _src_mac, dst_mac = src_dst_from_mac
72
73
  self.send(dst_mac)
73
74
  end
74
75
 
75
- # Set destination MAC address
76
+ # Set destination MAC address. {#from_ds} and {#to_ds} must be set before using these method.
76
77
  # @param [String] mac MAC address to set
77
78
  # @return [String]
78
79
  def dst=(mac)
@@ -80,14 +81,14 @@ module PacketGen
80
81
  self.send(:"#{dst_mac}=", mac)
81
82
  end
82
83
 
83
- # Get source MAC address
84
+ # Get source MAC address. {#from_ds} and {#to_ds} must be set before using these method.
84
85
  # @return [String]
85
86
  def src
86
87
  src_mac, = src_dst_from_mac
87
88
  self.send(src_mac)
88
89
  end
89
90
 
90
- # Set source MAC address
91
+ # Set source MAC address. {#from_ds} and {#to_ds} must be set before using these method.
91
92
  # @param [String] mac MAC address to set
92
93
  # @return [String]
93
94
  def src=(mac)
@@ -15,7 +15,7 @@ module PacketGen
15
15
  # #
16
16
  # # An {Element} is a piece of data contained in a Dot11 management frame.
17
17
  # # @since 1.4.0
18
- # # @since 3.1.0 subclass of {BinStruct::AbstractTLV}
18
+ # # @since 3.1.0 subclass of +BinStruct::AbstractTLV+
19
19
  # class Element < BinStruct::AbstractTLV; end
20
20
  # @private
21
21
  Element = BinStruct::AbstractTLV.create
@@ -16,28 +16,31 @@ module PacketGen
16
16
  # (management frame).
17
17
  #
18
18
  # A IEEE 802.11 management header consists of:
19
- # * a {#frame_ctrl} ({BinStruct::Int16}),
20
- # * a {#id}/duration ({BinStruct::Int16le}),
19
+ # * a {#frame_ctrl} (+BinStruct::Int16+),
20
+ # * a {#id}/duration (+BinStruct::Int16le+),
21
21
  # * a {#mac1} ({Eth::MacAddr}).
22
22
  # * a {#mac2} ({Eth::MacAddr}),
23
23
  # * a {#mac3} ({Eth::MacAddr}),
24
- # * a {#sequence_ctrl} ({BinStruct::Int16}),
25
- # * a {#body} (a {BinStruct::String} or another {Base} class),
26
- # * and a Frame check sequence ({#fcs}, of type {BinStruct::Int32le}).
24
+ # * a {#sequence_ctrl} (+BinStruct::Int16+),
25
+ # * a {#body} (a +BinStruct::String+ or another {Headerable} class),
26
+ # * and a Frame check sequence ({#fcs}, of type +BinStruct::Int32le+).
27
27
  #
28
28
  # Management frames should be constructed with more headers from
29
- # {SubMngt} subclasses.
29
+ # {SubMngt} subclasses. Some frames also need to have {Element}.
30
30
  #
31
- # By example, build a {DeAuth} frame:
31
+ # @example Build a {DeAuth} frame:
32
32
  # PacketGen.gen('Dot11::Management').add('Dot11::DeAuth')
33
33
  #
34
- # Some frames need to have {Element}. By example a {Beacon} frame:
35
- # pkt = PacketGen.gen('Dot11::Management', mac1: broadcast, mac2: bssid, mac3: bssid).
36
- # add('Dot11::Beacon')
37
- # pkt.dot11_beacon.add_elements(type: 'SSID', value: ssid)
38
- # pkt.dot11_beacon.add_elements(type: 'Rates', value: "\x82\x84\x8b\x96\x12\x24\x48\x6c")
39
- # pkt.dot11_beacon.add_elements(type: 'DSset', value: "\x06")
40
- # pkt.dot11_beacon.add_elements(type: 'TIM', value: "\x00\x01\x00\x00")
34
+ # @example a {Beacon} frame with elements:
35
+ # bssid = '00:01:02:03:04:05'
36
+ # pkt = PacketGen.gen('Dot11::Management', mac1: 'ff:ff:ff:ff:ff:ff', mac2: bssid, mac3: bssid)
37
+ # .add('Dot11::Beacon')
38
+ # # Directly add elements to Beacon
39
+ # pkt.dot11_beacon.elements << { type: 'SSID', value: "SSIDSSID" }
40
+ # pkt.dot11_beacon.elements << { type: 'Rates', value: "\x82\x84\x8b\x96\x12\x24\x48\x6c" }
41
+ # # Add elements to beacon through management header
42
+ # pkt.dot11_management.add_element(type: 'DSset', value: "\x06")
43
+ # pkt.dot11_management.add_element(type: 'TIM', value: "\x00\x01\x00\x00")
41
44
  # @author Sylvain Daubert
42
45
  class Management < Dot11
43
46
  # @param [Hash] options
@@ -48,7 +51,7 @@ module PacketGen
48
51
  define_applicable_attributes
49
52
  end
50
53
 
51
- # Add an {Element}
54
+ # Add an {Element} to header in body (for example, a {Dot11::Beacon})
52
55
  # @param [Integer,String] type element type
53
56
  # @param [Object] value element value
54
57
  # @return [self]
@@ -19,6 +19,7 @@ module PacketGen
19
19
  # may be accessed through {#elements}.
20
20
  # @author Sylvain Daubert
21
21
  class SubMngt < Base
22
+ # Elements of submngt header
22
23
  # @return [Array<Element>]
23
24
  define_attr :elements, ArrayOfElements
24
25
  end
@@ -28,8 +29,8 @@ module PacketGen
28
29
  # Specialize {Dot11::Management} with +subtype+ set to 0.
29
30
  #
30
31
  # Add fields:
31
- # * {#cap} ({BinStruct::Int16le}),
32
- # * {#listen_interval} ({BinStruct::Int16le}).
32
+ # * {#cap} (+BinStruct::Int16le+),
33
+ # * {#listen_interval} (+BinStruct::Int16le+).
33
34
  # @author Sylvain Daubert
34
35
  class AssoReq < SubMngt
35
36
  # @!attribute cap
@@ -47,9 +48,9 @@ module PacketGen
47
48
  # Specialize {Dot11::Management} with +subtype+ set to 1.
48
49
  #
49
50
  # Add fields:
50
- # * {#cap} ({BinStruct::Int16le}),
51
- # * {#status} ({BinStruct::Int16le}),
52
- # * {#aid} ({BinStruct::Int16le}).
51
+ # * {#cap} (+BinStruct::Int16le+),
52
+ # * {#status} (+BinStruct::Int16le+),
53
+ # * {#aid} (+BinStruct::Int16le+).
53
54
  # @author Sylvain Daubert
54
55
  class AssoResp < SubMngt
55
56
  # @!attribute cap
@@ -70,8 +71,8 @@ module PacketGen
70
71
  # Specialize {Dot11::Management} with +subtype+ set to 2.
71
72
  #
72
73
  # Add fields:
73
- # * {#cap} ({BinStruct::Int16le}),
74
- # * {#listen_interval} ({BinStruct::Int16le}),
74
+ # * {#cap} (+BinStruct::Int16le+),
75
+ # * {#listen_interval} (+BinStruct::Int16le+),
75
76
  # * {#current_ap} ({Eth::MacAddr}).
76
77
  # @author Sylvain Daubert
77
78
  class ReAssoReq < AssoReq
@@ -87,9 +88,9 @@ module PacketGen
87
88
  # Specialize {Dot11::Management} with +subtype+ set to 3.
88
89
  #
89
90
  # Add fields:
90
- # * {#cap} ({BinStruct::Int16le}),
91
- # * {#status} ({BinStruct::Int16le}),
92
- # * {#aid} ({BinStruct::Int16le}).
91
+ # * {#cap} (+BinStruct::Int16le+),
92
+ # * {#status} (+BinStruct::Int16le+),
93
+ # * {#aid} (+BinStruct::Int16le+).
93
94
  # @author Sylvain Daubert
94
95
  class ReAssoResp < AssoResp
95
96
  end
@@ -112,9 +113,9 @@ module PacketGen
112
113
  # Specialize {Dot11::Management} with +subtype+ set to 5.
113
114
  #
114
115
  # Add fields:
115
- # * {#timestamp} ({BinStruct::Int64le}),
116
- # * {#beacon_interval} ({BinStruct::Int16le}),
117
- # * {#cap} ({BinStruct::Int16le}).
116
+ # * {#timestamp} (+BinStruct::Int64le+),
117
+ # * {#beacon_interval} (+BinStruct::Int16le+),
118
+ # * {#cap} (+BinStruct::Int16le+).
118
119
  # @author Sylvain Daubert
119
120
  class ProbeResp < SubMngt
120
121
  # @!attribute timestamp
@@ -135,9 +136,9 @@ module PacketGen
135
136
  # Specialize {Dot11::Management} with +subtype+ set to 8.
136
137
  #
137
138
  # Add fields:
138
- # * {#timestamp} ({BinStruct::Int64le}),
139
- # * {#interval} ({BinStruct::Int16le}),
140
- # * {#cap} ({BinStruct::Int16le}).
139
+ # * {#timestamp} (+BinStruct::Int64le+),
140
+ # * {#interval} (+BinStruct::Int16le+),
141
+ # * {#cap} (+BinStruct::Int16le+).
141
142
  # @author Sylvain Daubert
142
143
  class Beacon < SubMngt
143
144
  # @!attribute timestamp
@@ -168,7 +169,7 @@ module PacketGen
168
169
  # Specialize {Dot11::Management} with +subtype+ set to 10.
169
170
  #
170
171
  # Add fields:
171
- # * {#reason} ({BinStruct::Int16le}).
172
+ # * {#reason} (+BinStruct::Int16le+).
172
173
  # @author Sylvain Daubert
173
174
  class Disas < SubMngt
174
175
  # @!attribute reason
@@ -183,9 +184,9 @@ module PacketGen
183
184
  # Specialize {Dot11::Management} with +subtype+ set to 11.
184
185
  #
185
186
  # Add fields:
186
- # * {#algo} ({BinStruct::Int16le}),
187
- # * {#seqnum} ({BinStruct::Int16le}),
188
- # * {#status} ({BinStruct::Int16le}).
187
+ # * {#algo} (+BinStruct::Int16le+),
188
+ # * {#seqnum} (+BinStruct::Int16le+),
189
+ # * {#status} (+BinStruct::Int16le+).
189
190
  # @author Sylvain Daubert
190
191
  class Auth < SubMngt
191
192
  # @!attribute algo
@@ -206,7 +207,7 @@ module PacketGen
206
207
  # Specialize {Dot11::Management} with +subtype+ set to 12.
207
208
  #
208
209
  # Add fields:
209
- # * {#reason} ({BinStruct::Int16le}).
210
+ # * {#reason} (+BinStruct::Int16le+).
210
211
  # @author Sylvain Daubert
211
212
  class DeAuth < SubMngt
212
213
  # @!attribute reason