packetgen 4.0.0 → 4.1.1

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 (117) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -9
  3. data/lib/packetgen/capture.rb +3 -6
  4. data/lib/packetgen/config.rb +1 -1
  5. data/lib/packetgen/deprecation.rb +7 -1
  6. data/lib/packetgen/header/arp.rb +7 -8
  7. data/lib/packetgen/header/asn1_base.rb +3 -2
  8. data/lib/packetgen/header/base.rb +39 -27
  9. data/lib/packetgen/header/bootp.rb +15 -15
  10. data/lib/packetgen/header/dhcp/option.rb +9 -9
  11. data/lib/packetgen/header/dhcp/options.rb +3 -3
  12. data/lib/packetgen/header/dhcp.rb +7 -8
  13. data/lib/packetgen/header/dhcpv6/duid.rb +3 -5
  14. data/lib/packetgen/header/dhcpv6/option.rb +38 -16
  15. data/lib/packetgen/header/dhcpv6/options.rb +4 -4
  16. data/lib/packetgen/header/dhcpv6/relay.rb +2 -1
  17. data/lib/packetgen/header/dhcpv6.rb +14 -15
  18. data/lib/packetgen/header/dns/name.rb +10 -9
  19. data/lib/packetgen/header/dns/opt.rb +4 -1
  20. data/lib/packetgen/header/dns/option.rb +8 -8
  21. data/lib/packetgen/header/dns/qdsection.rb +3 -3
  22. data/lib/packetgen/header/dns/question.rb +2 -1
  23. data/lib/packetgen/header/dns/rr.rb +2 -4
  24. data/lib/packetgen/header/dns/rrsection.rb +3 -3
  25. data/lib/packetgen/header/dns.rb +77 -61
  26. data/lib/packetgen/header/dot11/control.rb +6 -6
  27. data/lib/packetgen/header/dot11/data.rb +12 -11
  28. data/lib/packetgen/header/dot11/element.rb +2 -2
  29. data/lib/packetgen/header/dot11/management.rb +19 -16
  30. data/lib/packetgen/header/dot11/sub_mngt.rb +23 -22
  31. data/lib/packetgen/header/dot11.rb +39 -39
  32. data/lib/packetgen/header/dot1q.rb +6 -5
  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 +12 -4
  36. data/lib/packetgen/header/eap/tls.rb +10 -9
  37. data/lib/packetgen/header/eap/ttls.rb +14 -11
  38. data/lib/packetgen/header/eap.rb +59 -34
  39. data/lib/packetgen/header/eth.rb +27 -13
  40. data/lib/packetgen/header/gre.rb +27 -3
  41. data/lib/packetgen/header/http/headers.rb +7 -6
  42. data/lib/packetgen/header/http/request.rb +25 -17
  43. data/lib/packetgen/header/http/response.rb +23 -16
  44. data/lib/packetgen/header/http/verbs.rb +1 -1
  45. data/lib/packetgen/header/http.rb +1 -1
  46. data/lib/packetgen/header/icmp.rb +11 -11
  47. data/lib/packetgen/header/icmpv6.rb +11 -10
  48. data/lib/packetgen/header/igmp.rb +22 -11
  49. data/lib/packetgen/header/igmpv3/group_record.rb +8 -3
  50. data/lib/packetgen/header/igmpv3/mq.rb +2 -2
  51. data/lib/packetgen/header/igmpv3/mr.rb +2 -2
  52. data/lib/packetgen/header/igmpv3.rb +12 -11
  53. data/lib/packetgen/header/ip/addr.rb +7 -3
  54. data/lib/packetgen/header/ip/option.rb +19 -6
  55. data/lib/packetgen/header/ip/options.rb +1 -1
  56. data/lib/packetgen/header/ip.rb +53 -36
  57. data/lib/packetgen/header/ipv6/addr.rb +15 -14
  58. data/lib/packetgen/header/ipv6/extension.rb +10 -8
  59. data/lib/packetgen/header/ipv6/hop_by_hop.rb +27 -8
  60. data/lib/packetgen/header/ipv6.rb +32 -23
  61. data/lib/packetgen/header/llc.rb +21 -14
  62. data/lib/packetgen/header/mdns.rb +10 -3
  63. data/lib/packetgen/header/mld.rb +12 -10
  64. data/lib/packetgen/header/mldv2/mcast_address_record.rb +7 -2
  65. data/lib/packetgen/header/mldv2/mlq.rb +9 -9
  66. data/lib/packetgen/header/mldv2/mlr.rb +5 -5
  67. data/lib/packetgen/header/mldv2.rb +2 -2
  68. data/lib/packetgen/header/ospfv2/db_description.rb +11 -11
  69. data/lib/packetgen/header/ospfv2/hello.rb +12 -11
  70. data/lib/packetgen/header/ospfv2/ls_ack.rb +6 -7
  71. data/lib/packetgen/header/ospfv2/ls_request.rb +8 -7
  72. data/lib/packetgen/header/ospfv2/ls_update.rb +8 -8
  73. data/lib/packetgen/header/ospfv2/lsa.rb +34 -11
  74. data/lib/packetgen/header/ospfv2/lsa_header.rb +4 -3
  75. data/lib/packetgen/header/ospfv2.rb +32 -27
  76. data/lib/packetgen/header/ospfv3/db_description.rb +13 -14
  77. data/lib/packetgen/header/ospfv3/hello.rb +11 -10
  78. data/lib/packetgen/header/ospfv3/ipv6_prefix.rb +7 -3
  79. data/lib/packetgen/header/ospfv3/ls_ack.rb +6 -7
  80. data/lib/packetgen/header/ospfv3/ls_request.rb +11 -11
  81. data/lib/packetgen/header/ospfv3/ls_update.rb +8 -8
  82. data/lib/packetgen/header/ospfv3/lsa.rb +24 -10
  83. data/lib/packetgen/header/ospfv3/lsa_header.rb +4 -3
  84. data/lib/packetgen/header/ospfv3.rb +39 -35
  85. data/lib/packetgen/header/sctp/chunk.rb +39 -18
  86. data/lib/packetgen/header/sctp/error.rb +170 -198
  87. data/lib/packetgen/header/sctp/padded32.rb +4 -4
  88. data/lib/packetgen/header/sctp/parameter.rb +86 -133
  89. data/lib/packetgen/header/sctp.rb +15 -4
  90. data/lib/packetgen/header/snmp.rb +111 -10
  91. data/lib/packetgen/header/tcp/option.rb +8 -1
  92. data/lib/packetgen/header/tcp/options.rb +12 -4
  93. data/lib/packetgen/header/tcp.rb +34 -27
  94. data/lib/packetgen/header/tftp.rb +17 -11
  95. data/lib/packetgen/header/udp.rb +16 -14
  96. data/lib/packetgen/header.rb +20 -14
  97. data/lib/packetgen/headerable.rb +10 -4
  98. data/lib/packetgen/inject.rb +1 -1
  99. data/lib/packetgen/inspect.rb +3 -8
  100. data/lib/packetgen/packet.rb +95 -37
  101. data/lib/packetgen/pcap.rb +1 -1
  102. data/lib/packetgen/pcapng/block.rb +3 -2
  103. data/lib/packetgen/pcapng/epb.rb +1 -1
  104. data/lib/packetgen/pcapng/file.rb +42 -15
  105. data/lib/packetgen/pcapng/idb.rb +3 -2
  106. data/lib/packetgen/pcapng/shb.rb +3 -2
  107. data/lib/packetgen/pcapng/spb.rb +2 -2
  108. data/lib/packetgen/pcapng/unknown_block.rb +1 -1
  109. data/lib/packetgen/pcapng.rb +3 -1
  110. data/lib/packetgen/pcaprub_wrapper.rb +1 -1
  111. data/lib/packetgen/proto.rb +5 -1
  112. data/lib/packetgen/unknown_packet.rb +4 -4
  113. data/lib/packetgen/utils/arp_spoofer.rb +1 -1
  114. data/lib/packetgen/utils.rb +4 -5
  115. data/lib/packetgen/version.rb +2 -2
  116. data/lib/packetgen.rb +9 -3
  117. metadata +8 -9
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # This file is part of PacketGen
5
- # See https://github.com/lemontree55/packetgen for more informations
5
+ # See https://codeberg.org/lemontree55/packetgen for more informations
6
6
  # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
7
7
  # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
8
8
  # This program is published under MIT license.
@@ -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]
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # This file is part of PacketGen
5
- # See https://github.com/lemontree55/packetgen for more informations
5
+ # See https://codeberg.org/lemontree55/packetgen for more informations
6
6
  # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
7
7
  # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
8
8
  # This program is published under MIT license.
@@ -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
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # This file is part of PacketGen
5
- # See https://github.com/lemontree55/packetgen for more informations
5
+ # See https://codeberg.org/lemontree55/packetgen for more informations
6
6
  # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
7
7
  # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
8
8
  # This program is published under MIT license.
@@ -103,58 +103,54 @@ module PacketGen
103
103
  end
104
104
  self.add_class RadioTap
105
105
 
106
- # IEEE 802.11 header
107
106
  # @abstract This is a base class to demultiplex different IEEE 802.11 frames when
108
107
  # parsing.
109
108
  # A IEEE 802.11 header may consist of at least:
110
- # * a {#frame_ctrl} ({BinStruct::Int16}),
111
- # * a {#id}/duration ({BinStruct::Int16le}),
109
+ # * a {#frame_ctrl} (+BinStruct::Int16+),
110
+ # * a {#id}/duration (+BinStruct::Int16le+),
112
111
  # * and a {#mac1} ({Eth::MacAddr}).
113
112
  # Depending on frame type and subtype, it may also contains:
114
113
  # * a {#mac2} ({Eth::MacAddr}),
115
114
  # * a {#mac3} ({Eth::MacAddr}),
116
- # * a {#sequence_ctrl} ({BinStruct::Int16}),
115
+ # * a {#sequence_ctrl} (+BinStruct::Int16+),
117
116
  # * a {#mac4} ({Eth::MacAddr}),
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})
117
+ # * a {#qos_ctrl} (+BinStruct::Int16+),
118
+ # * a {#ht_ctrl} (+BinStruct::Int32+),
119
+ # * a {#body} (a +BinStruct::String+ or another {Headerable} class),
120
+ # * a Frame check sequence ({#fcs}, of type +BinStruct::Int32le+)
122
121
  #
123
122
  # == Header accessors
124
123
  # As Dot11 header types are defined under Dot11 namespace, Dot11 header accessors
125
- # have a specific name. By example, to access to a {Dot11::Beacon} header,
124
+ # have a specific name. For example, to access to a {Dot11::Beacon} header,
126
125
  # accessor is +#dot11_beacon+.
127
126
  #
128
127
  # == Create Dot11 packets
129
128
  # As {Dot11} is an abstract class, you have to use one of its subclasses to
130
- # instanciate a IEEE802.11 header.
129
+ # instanciate a IEEE802.11 header (see examples below).
131
130
  #
132
- # === IEEE802.11 control frames
133
- # Control frames may be created this way:
131
+ # @example Create IEEE802.11 control frames
134
132
  # pkt = PacketGen.gen('Dot11::Control', subtype: 13) # Ack control frame
135
- # pkt.dot11_control # => PacketGen::Header::Dot11::Control
133
+ # pkt.dot11_control.class # => PacketGen::Header::Dot11::Control
136
134
  # # #dot11 is a shortcut for #dot11_control
137
- # pkt.dot11 # => PacketGen::Header::Dot11::Control
135
+ # pkt.dot11.class # => PacketGen::Header::Dot11::Control
138
136
  #
139
- # === IEEE802.11 management frames
140
- # Management frames may be created this way:
137
+ # @example Create IEEE802.11 management frames
141
138
  # pkt = PacketGen.gen('Dot11::Management')
142
- # pkt.dot11_management # => PacketGen::Header::Dot11::Management
139
+ # pkt.dot11_management.class # => PacketGen::Header::Dot11::Management
143
140
  # # #dot11 is a shortcut for #dot11_management
144
- # pkt.dot11 # => PacketGen::Header::Dot11::Management
145
- # Management frames are usually specialized, AssociationRequest by example:
141
+ # pkt.dot11.class # => PacketGen::Header::Dot11::Management
142
+ # # Management frames are usually specialized, AssociationRequest by example
146
143
  # pkt.add('Dot11::AssoReq')
147
- # pkt.dot11_assoreq # => PacketGen::Header::Dot11::AssoReq
148
- # Management frames also may contain some elements (see IEEE 802.11 standard):
149
- # pkt.dot11_assoreq.add_elements(type: 'SSID', value: "My SSID")
150
- # pkt.dot11_assoreq.add_elements(type: 'Rates', value: supported_rates)
144
+ # pkt.dot11_assoreq .class # => PacketGen::Header::Dot11::AssoReq
145
+ # # Management frames also may contain some elements (see IEEE 802.11 standard)
146
+ # pkt.dot11_assoreq.elements << { type: 'SSID', value: "My SSID" }
147
+ # pkt.dot11_assoreq.elements << { type: 'Rates', value: "\x8c\x12\x98\x24\xb0" }
151
148
  #
152
- # === IEEE802.11 data frames
153
- # Data frames may be created this way:
149
+ # @example Create IEEE802.11 data frames
154
150
  # pkt = PacketGen.gen('Dot11::Data')
155
- # pkt.dot11_data # => PacketGen::Header::Dot11::Data
151
+ # pkt.dot11_data.class # => PacketGen::Header::Dot11::Data
156
152
  # # #dot11 is a shortcut for #dot11_data
157
- # pkt.dot11 # => PacketGen::Header::Dot11::Data
153
+ # pkt.dot11.class # => PacketGen::Header::Dot11::Data
158
154
  #
159
155
  # == Parse Dot11 packets
160
156
  # When parsing a Dot11 packet, Dot11 subclass is created from +type+ value.
@@ -163,13 +159,12 @@ module PacketGen
163
159
  # for a control frame, +Packet#dot11_control+ may also be used.
164
160
  #
165
161
  # == Send Dot11 packets
166
- # To send a Dot11 packet, a RadioTap header is needed:
162
+ # To send a Dot11 packet, a RadioTap or PPI header is needed (depending on your hardware):
167
163
  # pkt = PacketGen.gen('RadioTap')
168
164
  # pkt.add('Dot11::Management', mac1: client, mac2: bssid, mac3: bssid)
169
165
  # pkt.add('Dot11::Beacon')
170
- # pkt.dot11_beacon.add_element(type: 'SSID', value: 'My SSID')
171
- # pkt.dot11_beacon.add_element(type: 'Rates', value: "\x85\x0c")
172
- # pkt.calc
166
+ # pkt.dot11_management.add_element(type: 'SSID', value: 'My SSID')
167
+ # pkt.dot11_management.add_element(type: 'Rates', value: "\x85\x0c")
173
168
  # pkt.to_w('wlan0')
174
169
  # @author Sylvain Daubert
175
170
  # @since 1.4.0
@@ -226,10 +221,12 @@ module PacketGen
226
221
  define_attr :mac3, Eth::MacAddr
227
222
  # @!attribute sequence_ctrl
228
223
  # @return [Integer] 16-bit sequence control word
229
- # @!attribute sequence_number (12-bit field from {#sequence_ctrl})
224
+ # @!attribute sequence_number
225
+ # 12-bit field from {#sequence_ctrl}
230
226
  # @return [Integer]
231
227
  # @since 2.1.3
232
- # @!attribute fragment_number (4-bit field from {#sequence_ctrl})
228
+ # @!attribute fragment_number
229
+ # 4-bit attribute from {#sequence_ctrl}
233
230
  # @return [Integer]
234
231
  # @since 2.1.3
235
232
  define_bit_attr :sequence_ctrl, sequence_number: 12, fragment_number: 4
@@ -243,9 +240,11 @@ module PacketGen
243
240
  # @return [Integer] 16-bit HT control word
244
241
  define_attr :ht_ctrl, BinStruct::Int32
245
242
  # @!attribute body
243
+ # Dot11 body, if any
246
244
  # @return [BinStruct::String]
247
245
  define_attr :body, BinStruct::String
248
246
  # @!attribute fcs
247
+ # Checksum of the Dot11 frame.
249
248
  # @return [BinStruct::Int32le]
250
249
  define_attr :fcs, BinStruct::Int32le
251
250
 
@@ -260,7 +259,7 @@ module PacketGen
260
259
  @applicable_attributes = old_attributes
261
260
  end
262
261
 
263
- # Get all used field names
262
+ # Get all used attribute names
264
263
  # @return [Array<Symbol>]
265
264
  def attributes
266
265
  @applicable_attributes
@@ -279,7 +278,7 @@ module PacketGen
279
278
  if self.instance_of?(Dot11)
280
279
  return self if str.nil?
281
280
 
282
- force_binary str
281
+ str = str.b unless str.encoding == Encoding::BINARY
283
282
  self[:frame_ctrl].read(str[0, 2])
284
283
 
285
284
  case type
@@ -305,10 +304,11 @@ module PacketGen
305
304
  fcs
306
305
  end
307
306
 
307
+ # Generate binary string
308
308
  # @return [String]
309
309
  def to_s
310
310
  define_applicable_attributes
311
- @applicable_attributes.map { |f| force_binary @attributes[f].to_s }.join
311
+ @applicable_attributes.map { |f| @attributes[f].to_s.b }.join
312
312
  end
313
313
 
314
314
  # Get human readable type
@@ -343,7 +343,7 @@ module PacketGen
343
343
  Inject.inject(iface: iface, data: self)
344
344
  end
345
345
 
346
- # Callback called when a Dot11 header is added to a packet
346
+ # Callback called when a Dot11 header is added to a packet.
347
347
  # Here, add +#dot11+ method as a shortcut to existing
348
348
  # +#dot11_(control|management|data)+.
349
349
  # @param [Packet] packet
@@ -357,7 +357,7 @@ module PacketGen
357
357
  private
358
358
 
359
359
  def remove_from_applicable_attributes(attributes)
360
- attributes = [attributes] unless attributes.is_a? Array
360
+ attributes = [attributes] unless attributes.is_a?(Array)
361
361
  @applicable_attributes -= attributes
362
362
  end
363
363
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # This file is part of PacketGen
4
- # See https://github.com/lemontree55/packetgen for more informations
4
+ # See https://codeberg.org/lemontree55/packetgen for more informations
5
5
  # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
6
6
  # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
7
7
  # This program is published under MIT license.
@@ -11,13 +11,14 @@ module PacketGen
11
11
  # IEEE 802.1Q VLAN tagging
12
12
  #
13
13
  # A VLAN tag consists of:
14
- # * a {#tci Tag Control Information} ({BinStruct::Int16}),
15
- # * a {#ethertype} ({BinStruct::Int16}),
16
- # * and a body (a {BinStruct::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 {Headerable} class).
17
17
  #
18
- # == Create a Dot1q header
18
+ # @example Create a Dot1q header
19
19
  # # Create a IP packet in VLAN #43
20
20
  # pkt = PacketGen.gen('Eth').add('Dot1q', vid: 43).add('IP')
21
+ # pkt.is?('Dot1q') #=> true
21
22
  # @author Sylvain Daubert
22
23
  # @since 1.4.0
23
24
  class Dot1q < Base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # This file is part of PacketGen
4
- # See https://github.com/lemontree55/packetgen for more informations
4
+ # See https://codeberg.org/lemontree55/packetgen for more informations
5
5
  # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
6
6
  # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
7
7
  # This program is published under MIT license.
@@ -11,15 +11,15 @@ module PacketGen
11
11
  # IEEE 802.1X / EAPOL
12
12
  #
13
13
  # A IEEE 802.1X header consists of:
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
- # == Create a Dot1x header
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 {Headerable} class).
18
+ # @example Create a Dot1x header
19
+ # # Create with integer type
19
20
  # pkt1 = PacketGen.gen('Eth').add('Dot1x', type: 1)
20
- # pkt2 = PacketGen.gen('Eth').add('Dot1x')
21
- # pkt2.dot1x.type = 'EAP Packet'
22
- # pkt2.dot1x.body.read 'body'
21
+ # # Create with human-readable type
22
+ # pkt2 = PacketGen.gen('Eth').add('Dot1x', type: 'EAP Packet')
23
23
  # @author Sylvain Daubert
24
24
  # @since 1.4.0
25
25
  class Dot1x < Base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # This file is part of PacketGen
4
- # See https://github.com/lemontree55/packetgen for more informations
4
+ # See https://codeberg.org/lemontree55/packetgen for more informations
5
5
  # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
6
6
  # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
7
7
  # This program is published under MIT license.
@@ -13,9 +13,9 @@ 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} ({BinStruct::Int8}),
17
- # * optionally {#message_length} ({BinStruct::Int32}), if +#l?+ is +true+,
18
- # * {#body} ({BinStruct::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
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # This file is part of PacketGen
4
- # See https://github.com/lemontree55/packetgen for more informations
4
+ # See https://codeberg.org/lemontree55/packetgen for more informations
5
5
  # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
6
6
  # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
7
7
  # This program is published under MIT license.
@@ -18,15 +18,23 @@ module PacketGen
18
18
  remove_attr :body
19
19
 
20
20
  # @!attribute value_size
21
- # @return [Integer] 8-bit value size
21
+ # 8-bit size of the {#value} attribute.
22
+ # @return [Integer]
22
23
  define_attr :value_size, BinStruct::Int8
23
24
  # @!attribute value
25
+ # MD5 challenge value, as an octet stream, as per {https://datatracker.ietf.org/doc/html/rfc1994#section-4 RFC1994}
24
26
  # @return [::String]
25
27
  define_attr :value, BinStruct::String,
26
28
  builder: ->(h, t) { t.new(length_from: h[:value_size]) }
27
- # @!attribute optional_name
29
+ # @!attribute name
30
+ # Name identifying the system sending the packet. It is or or more octets. Its size is
31
+ # determined from the {#length} attribute.
28
32
  # @return [::String]
29
- define_attr :optional_name, BinStruct::String
33
+ # @since 4.1.0 Attribute renamed from +optioanl_name+ to +name+
34
+ define_attr :name, BinStruct::String
35
+
36
+ # @deprecated
37
+ alias optional_name name
30
38
  end
31
39
  end
32
40
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # This file is part of PacketGen
4
- # See https://github.com/lemontree55/packetgen for more informations
4
+ # See https://codeberg.org/lemontree55/packetgen for more informations
5
5
  # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
6
6
  # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
7
7
  # This program is published under MIT license.
@@ -13,22 +13,23 @@ module PacketGen
13
13
  # {https://tools.ietf.org/html/rfc5216 RFC 5216}
14
14
  #
15
15
  # {EAP::TLS} has following fields:
16
- # * {#flags} ({BinStruct::Int8}),
17
- # * optionally {#tls_length} ({BinStruct::Int32}), if +#l?+ is +true+,
18
- # * {#body} ({BinStruct::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
22
  update_attr :type, default: 13
23
23
  # @!attribute flags
24
- # @return [Integer] 8-bit flags
25
- # @!attribute l
26
- # Say if length field is included
24
+ # 8-bit flags
27
25
  # @return [Integer]
28
- # @!attribute m
26
+ # @!attribute l?
27
+ # Say if {#tls_length 32-bit TLS length attribute} is included.
28
+ # @return [Integer]
29
+ # @!attribute m?
29
30
  # Say if there are more fragments
30
31
  # @return [Integer]
31
- # @!attribute s
32
+ # @!attribute s?
32
33
  # If set, this message is a TLS-Start
33
34
  # @return [Integer]
34
35
  define_bit_attr_before :body, :flags, l: 1, m: 1, s: 1, reserved: 5
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # This file is part of PacketGen
4
- # See https://github.com/lemontree55/packetgen for more informations
4
+ # See https://codeberg.org/lemontree55/packetgen for more informations
5
5
  # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
6
6
  # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
7
7
  # This program is published under MIT license.
@@ -13,28 +13,31 @@ module PacketGen
13
13
  # {https://tools.ietf.org/html/rfc5281 RFC 5281}
14
14
  #
15
15
  # {EAP::TTLS} has following fields:
16
- # * {#flags} ({BinStruct::Int8}),
17
- # * optionally {#message_length} ({BinStruct::Int32}), if +#l?+ is +true+,
18
- # * {#body} ({BinStruct::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
22
  update_attr :type, default: 21
23
23
  # @!attribute flags
24
- # @return [Integer] 8-bit flags
25
- # @!attribute l
26
- # Say if length field is included
24
+ # 8-bit flags
27
25
  # @return [Integer]
28
- # @!attribute m
26
+ # @!attribute l?
27
+ # Say if {#message_length} field is included
28
+ # @return [Integer]
29
+ # @!attribute m?
29
30
  # Say if there are more fragments
30
31
  # @return [Integer]
31
- # @!attribute s
32
+ # @!attribute s?
32
33
  # If set, this message is a TLS-Start
33
34
  # @return [Integer]
34
35
  # @!attribute reserved
35
- # @return [Integer] 2-bit reserved integer
36
+ # 2-bit reserved integer
37
+ # @return [Integer]
36
38
  # @!attribute version
37
- # @return [Integer] 3-bit version
39
+ # 3-bit version
40
+ # @return [Integer]
38
41
  define_bit_attr_before :body, :flags, l: 1, m: 1, s: 1, reserved: 2, version: 3
39
42
  alias length_present? l?
40
43
  alias more_fragments? m?