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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 984125cdf335b4573a862ed481c155740f07588e10263da4a35455a9d2d4f803
4
- data.tar.gz: 01df13a9c405ba0887a540b952eb8ddea6c1dd8f58adfc1689b8ec0c628b14f4
3
+ metadata.gz: 11149bb0024ad38f2d0f4ac06031055dd95300ae544955bdd40cdce2c78bcb7f
4
+ data.tar.gz: 8215f9e3dd7de35ee9b1bf69defebd6c0b554aa7c17fbc7fec2068207018db36
5
5
  SHA512:
6
- metadata.gz: bec2e6720c1a658f777826dc2b7ad81b3cc1addeee5dd99b147357b005151b69d4df3b9c02fd529644a9dd9634106da3fb2b5d73d892769d85d7ef480347e7d7
7
- data.tar.gz: 897ebe8f59b88ad3b72eb8edc5a9a23f46228fda646453e2878a3b6a534d53620d58c5ec1396f5632727577a41cbab565d42f50714d9138e907a63de7e3d804d
6
+ metadata.gz: 1df25d3a9e0419ce41aa74e7ad3b1319a5d6b32f3d4021b9f2be05d4cfa5b2d2979a75ca068505a020a8cf653085f37ab98f5608d101b8be5d713d1c21748869
7
+ data.tar.gz: 0a772252254761f1dd7be1115fbacb10706ec11c6024ea73f3d7c27d1337b4e1e66cf07a656d9977fba07fb560e1eeda817261e5bde01c004de0b25017e305c1
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  [![Gem Version](https://badge.fury.io/rb/packetgen.svg)](https://badge.fury.io/rb/packetgen)
3
- [![Action status](https://github.com/lemontree55/packetgen/workflows/ci/badge.svg?branch=master)](https://github.com/lemontree55/packetgen/actions?query=workflow%3Aci)
3
+ [![status-badge](https://ci.codeberg.org/api/badges/15065/status.svg)](https://ci.codeberg.org/repos/15065)
4
4
 
5
5
  # PacketGen
6
6
 
@@ -176,26 +176,24 @@ If `pry` gem is installed, it is used as backend for `pgconsole`, else IRB is us
176
176
 
177
177
  ## Plugins
178
178
 
179
- PacketGen provides a plugin system (see [wiki](https://github.com/lemontree55/packetgen/wiki/Create-Custom-Protocol)).
179
+ PacketGen provides a plugin system (see [wiki](https://codeberg.org/lemontree55/packetgen/wiki/Create-Custom-Protocol)).
180
180
 
181
181
  Available plugins (available as gem) are:
182
182
 
183
- * [packetgen-plugin-ipsec](https://github.com/lemontree55/packetgen-plugin-ipsec): add support for ESP and IKEv2 protocols. Before PacketGen3, these protocols were included in packetgen.
184
- * [packetgen-plugin-smb](https://github.com/lemontree55/packetgen-plugin-smb): add support for SMB protocol suite.
183
+ * [packetgen-plugin-ipsec](https://github.com/sdaubert/packetgen-plugin-ipsec): add support for ESP and IKEv2 protocols. Before PacketGen3, these protocols were included in packetgen.
184
+ * [packetgen-plugin-smb](https://github.com/sdaubert/packetgen-plugin-smb): add support for SMB protocol suite.
185
185
 
186
186
  ## See also
187
187
 
188
- Wiki: <https://github.com/lemontree55/packetgen/wiki>
189
-
190
- API documentation: <http://www.rubydoc.info/gems/packetgen>
188
+ Wiki: <https://codeberg.org/lemontree55/packetgen/wiki>
191
189
 
192
190
  ## Contributing
193
191
 
194
- Bug reports and pull requests are welcome on GitHub at <https://github.com/lemontree55/packetgen>.
192
+ Bug reports and pull requests are welcome on Codeberg at <https://codeberg.org/lemontree55/packetgen>.
195
193
 
196
194
  ## License
197
195
 
198
- MIT License (see [LICENSE](https://github.com/lemontree55/packetgen/blob/master/LICENSE))
196
+ MIT License (see [LICENSE](https://codeberg.org/lemontree55/packetgen/blob/master/LICENSE))
199
197
 
200
198
  ### Other sources
201
199
 
@@ -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.
@@ -16,9 +16,7 @@ module PacketGen
16
16
 
17
17
  attr_reader :filter, :cap_thread, :snaplen, :promisc, :monitor
18
18
 
19
- # rubocop:disable Metrics/ParameterLists
20
-
21
- public
19
+ public
22
20
 
23
21
  # Get captured packets.
24
22
  # @return [Array<Packets>]
@@ -97,8 +95,7 @@ module PacketGen
97
95
 
98
96
  private
99
97
 
100
- # rubocop:disable Metrics/CyclomaticComplexity
101
- # rubocop:disable Metrics/PerceivedComplexity
98
+
102
99
 
103
100
  def set_options(iface, max, timeout, filter, promisc, parse, snaplen, monitor)
104
101
  @max = max if max
@@ -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.
@@ -29,7 +29,13 @@ module PacketGen
29
29
  def self.deprecated(klass, deprecated_method, new_method=nil, klass_method: false, remove_version: REMOVE_VERSION)
30
30
  base_name = "#{klass}#{klass_method ? '.' : '#'}"
31
31
  complete_deprecated_method_name = "#{base_name}#{deprecated_method}"
32
- complete_new_method_name = "#{base_name}#{new_method}" unless new_method.nil?
32
+ unless new_method.nil?
33
+ complete_new_method_name = if %w[# .].any? { |punct| new_method.include?(punct) }
34
+ new_method
35
+ else
36
+ "#{base_name}#{new_method}"
37
+ end
38
+ end
33
39
 
34
40
  file, line = caller(2..2).first.split(':')[0, 2]
35
41
  message = "#{file}:#{line}: #{complete_deprecated_method_name} is deprecated"
@@ -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.
@@ -9,9 +9,9 @@
9
9
  module PacketGen
10
10
  module Header
11
11
  # An ARP header consists of:
12
- # * a hardware type ({#hrd} or {#htype}) field ({BinStruct::Int16}),
12
+ # * a hardware type ({#hrd} or {#htype}) field (+BinStruct::Int16+),
13
13
  # * a protocol type ({#pro} or {#ptype}) field (+Int16+),
14
- # * a hardware address length ({#hln} or {#hlen}) field ({BinStruct::Int8}),
14
+ # * a hardware address length ({#hln} or {#hlen}) field (+BinStruct::Int8+),
15
15
  # * a protocol address length ({#pln} or {#plen}) field (+Int8+),
16
16
  # * a {#opcode} (or {#op}) field (+Int16+),
17
17
  # * a source hardware address ({#sha} or {#src_mac}) field ({Eth::MacAddr}),
@@ -20,13 +20,13 @@ module PacketGen
20
20
  # * a target protocol address ({#tpa} or {#dst_ip}) field (+IP::Addr+),
21
21
  # * and a {#body}.
22
22
  #
23
- # == Create a ARP header
23
+ # @example Create a ARP header
24
24
  # # standalone
25
25
  # arp = PacketGen::Header::ARP.new
26
26
  # # in a packet
27
27
  # pkt = PacketGen.gen('Eth').add('ARP')
28
28
  # # access to ARP header
29
- # pkt.arp # => PacketGen::Header::ARP
29
+ # pkt.arp.protocol_name # => "ARP"
30
30
  #
31
31
  # @author Sylvain Daubert
32
32
  class ARP < Base
@@ -122,8 +122,7 @@ module PacketGen
122
122
 
123
123
  private
124
124
 
125
- # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
126
- def handle_options(options)
125
+ def handle_options(options)
127
126
  options[:hrd] ||= options[:htype]
128
127
  options[:pro] ||= options[:ptype]
129
128
  options[:hln] ||= options[:hlen]
@@ -134,7 +133,7 @@ module PacketGen
134
133
  options[:tha] ||= options[:dst_mac]
135
134
  options[:tpa] ||= options[:dst_ip]
136
135
  end
137
- # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
136
+ # rubocop:enable Metrics
138
137
 
139
138
  def invert_addresses
140
139
  self.spa, self.tpa = self.tpa, self.spa
@@ -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.
@@ -21,7 +21,7 @@ module PacketGen
21
21
  include Headerable
22
22
 
23
23
  class << self
24
- # Define some methods from given ASN.1 attributes.to mimic {Base} attributes
24
+ # Define some methods from given ASN.1 attributes to mimic {Base} attributes
25
25
  # @param [Array<Symbol>] attributes
26
26
  # @return [void]
27
27
  def define_attributes(*attributes)
@@ -32,6 +32,7 @@ module PacketGen
32
32
  end
33
33
  end
34
34
 
35
+ # @return [Hash]
35
36
  def known_headers
36
37
  @known_headers ||= {}.freeze
37
38
  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,14 +13,25 @@ module PacketGen
13
13
  # * +#calc_checksum+, which computes header checksum,
14
14
  # * +#calc_length+, which computes header length,
15
15
  # * {#parse?},
16
- # * +#reply!+, which inverts needed attributes.to forge a response.
16
+ # * +#reply!+, which inverts needed attributes to forge a response.
17
+ # {Base} class defines {.bind} method, to bind headers to outer ones.
17
18
  # @author Sylvain Daubert
19
+ # @author LemonTree55
18
20
  class Base < BinStruct::Struct
19
21
  include Headerable
20
22
 
21
23
  # @api private
22
- # Simple class to handle a header association
23
- class Binding < ::Struct.new(:key, :value)
24
+ # @!parse
25
+ # # Simple class to handle a header association
26
+ # class Binding < ::Struct
27
+ # # attribute name in a header
28
+ # # @return [Symbol]
29
+ # attr_accessor :key
30
+ # # Value associated with the attribute to create a binding
31
+ # # @return [Integer,String,Proc]
32
+ # attr_accessor :value
33
+ # end
34
+ Binding = Struct.new(:key, :value) do
24
35
  # Check +fields+ responds to binding
25
36
  # @param [BinStruct::Struct] fields
26
37
  # @return [Boolean]
@@ -54,7 +65,7 @@ module PacketGen
54
65
  # @api private
55
66
  # Class to handle a header association from procs
56
67
  class ProcBinding
57
- # @param [Array<Proc>] procs first proc is used to set fields, second proc is
68
+ # @param [Array(Proc,Proc)] procs first proc is used to set fields, second proc is
58
69
  # used to check binding
59
70
  def initialize(procs)
60
71
  @set = procs.shift
@@ -77,11 +88,11 @@ module PacketGen
77
88
  end
78
89
 
79
90
  # @api private
80
- # Class to handle header associations
91
+ # Class to handle a set of header associations ({Binding} or/and {ProcBinding})
81
92
  class Bindings
82
93
  include Enumerable
83
94
 
84
- # @return [Array<Binding>]
95
+ # @return [Array<Binding,ProcBinding>]
85
96
  attr_accessor :bindings
86
97
 
87
98
  def initialize
@@ -92,7 +103,7 @@ module PacketGen
92
103
  @bindings << []
93
104
  end
94
105
 
95
- # @param [Object] arg
106
+ # @param [Binding,ProcBinding] arg
96
107
  # @return [Bindings] self
97
108
  def <<(arg)
98
109
  @bindings.last << arg
@@ -100,6 +111,7 @@ module PacketGen
100
111
 
101
112
  # each iterator
102
113
  # @return [void]
114
+ # @yieldparam [Binding,ProcBinding] binding
103
115
  def each(&block)
104
116
  @bindings.each(&block)
105
117
  end
@@ -109,7 +121,7 @@ module PacketGen
109
121
  @bindings.empty?
110
122
  end
111
123
 
112
- # Return binding as a hash.
124
+ # Return bindings as a hash.
113
125
  # @return [Hash]
114
126
  def to_h
115
127
  hsh = {}
@@ -146,12 +158,12 @@ module PacketGen
146
158
  class << self
147
159
  # @api private
148
160
  # Get known headers
149
- # @return [Hash] keys: header classes, values: hashes
161
+ # @return [Hash{Headerable => Bindings}]
150
162
  attr_reader :known_headers
151
163
 
152
164
  # Bind a upper header to current one.
153
165
  # @param [Class] header_klass header class to bind to current class
154
- # @param [Hash] args current class attributes.and their value when +header_klass+
166
+ # @param [Hash] args current class attributes and their value when +header_klass+
155
167
  # is embedded in current class.
156
168
  #
157
169
  # Given value may be a lambda, whose alone argument is the value extracted
@@ -163,23 +175,23 @@ module PacketGen
163
175
  # non-trivial checks should be made.
164
176
  # @return [void]
165
177
  # @example Basic examples
166
- # # Bind Header2 to Header1 when field1 from Header1 has a value of 42
167
- # Header1.bind Header2, field1: 42
168
- # # Bind Header3 to Header1 when field1 from Header1 has a value of 43
169
- # # and field2 has value 43 or 44
170
- # Header1.bind Header3, field1: 43, field2: 43
171
- # Header1.bind Header3, field1: 43, field2: 44
178
+ # # Bind TCP to IP when protocol attribute from IP has a value of 66
179
+ # PacketGen::Header::IP.bind PacketGen::Header::TCP, protocol: 66
180
+ # # Bind UDP to IP when protocol from IP has a value of 177
181
+ # # and tos has value 43 or 44
182
+ # PacketGen::Header::IP .bind PacketGen::Header::UDP, protocol: 177, tos: 43
183
+ # PacketGen::Header::IP .bind PacketGen::Header::UDP, protocol: 177, tos: 44
172
184
  # @example Defining a binding on a field using a lambda.
173
- # # Bind Header4 to Header1 when field1 from Header1 has a value
174
- # # greater or equal to 44. When adding a Header2 to a Header1
185
+ # # Bind DHCP to Eth when ethertype from Eth has a value
186
+ # # greater or equal to 44. When adding a DHCP to a Eth
175
187
  # # with Packet#add, force value to 44.
176
- # Header1.bind Header4, field1: ->(v) { v.nil? ? 44 : v >= 44 }
188
+ # PacketGen::Header::Eth.bind PacketGen::Header::DHCP, ethertype: ->(v) { v.nil? ? 44 : v >= 44 }
177
189
  # @example Defining a binding using procs key
178
- # # Bind Header5 to Header1 when field1 from Header1 has a value of 41
179
- # # and first two bytes of header1's body are null.
180
- # # When adding a Header2 to a Header1 with Packet#add, force value to 44.
181
- # Header1.bind Header5, procs: [->(hdr) { hdr.field1 = 41 }
182
- # ->(hdr) { hdr.field1 == 41 && hdr.body[0..1] == "\x00\x00" }]
190
+ # # Bind IPv6 to IP when protocol from IP has a value of 255
191
+ # # and first two bytes of IP's body are 0x6000.
192
+ # # When adding a IPv6 to a IP with Packet#add, force value to 255.
193
+ # PacketGen::Header::IP.bind PacketGen::Header::IPv6, procs: [->(hdr) { hdr.protocol = 255 },
194
+ # ->(hdr) { hdr.protocol == 255 && hdr.body[0..1] == "\x60\x00" }]
183
195
  # @since 2.7.0
184
196
  def bind(header_klass, args={})
185
197
  bindings = @known_headers[header_klass]
@@ -221,7 +233,7 @@ module PacketGen
221
233
  # @api private
222
234
  # Get +header+ id in {Packet#headers} array
223
235
  # @param [Header] header
224
- # @return [Integer]
236
+ # @return [Integer] header id
225
237
  # @raise [FormatError] +header+ not in a packet
226
238
  def header_id(header)
227
239
  raise FormatError, "header of type #{header.class} not in a packet" if packet.nil?
@@ -247,7 +259,7 @@ module PacketGen
247
259
  end
248
260
 
249
261
  # @api private
250
- # Get link layer header from given header
262
+ # Get link layer ({Eth} or {Dot11}) header from given header
251
263
  # @param [Header] header
252
264
  # @return [Header]
253
265
  # @raise [FormatError] no link layer header in packet
@@ -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.
@@ -12,31 +12,31 @@ module PacketGen
12
12
  # RFC 951}
13
13
  #
14
14
  # A BOOTP header consists of:
15
- # * an operation code field ({#op} of type {BinStruct::Int8Enum}),
16
- # * a hardware address type ({#htype} of type {BinStruct::Int8}),
17
- # * a hardware address length ({#hlen} of type {BinStruct::Int8}),
18
- # * a {#hops} field ({BinStruct::Int8}),
19
- # * a transaction ID ({#xid} of type {BinStruct::Int32}),
20
- # * a {#secs} field (){BinStruct::Int16}),
21
- # * a {#flags} field (){BinStruct::Int16}):
15
+ # * an operation code field ({#op} of type +BinStruct::Int8Enum+),
16
+ # * a hardware address type ({#htype} of type +BinStruct::Int8+),
17
+ # * a hardware address length ({#hlen} of type +BinStruct::Int8+),
18
+ # * a {#hops} field (+BinStruct::Int8+),
19
+ # * a transaction ID ({#xid} of type +BinStruct::Int32+),
20
+ # * a {#secs} field (+BinStruct::Int16+),
21
+ # * a {#flags} field (+BinStruct::Int16+):
22
22
  # * a 1-bit broadcast flag ({#b}),
23
23
  # * a 15-bit Must Be Zero field ({#mbz}),
24
24
  # * a {#ciaddr} field ({IP::Addr}),
25
25
  # * a {#yiaddr} field ({IP::Addr}),
26
26
  # * a {#siaddr} field ({IP::Addr}),
27
27
  # * a {#giaddr} field ({IP::Addr}),
28
- # * a {#chaddr} field (16-byte {BinStruct::String}),
29
- # * a {#sname} field (64-byte {BinStruct::CString}),
30
- # * a {#file} field (128-byte {BinStruct::CString}),
31
- # * and a body ({BinStruct::String}).
28
+ # * a {#chaddr} field (16-byte +BinStruct::String+),
29
+ # * a {#sname} field (64-byte +BinStruct::CString+),
30
+ # * a {#file} field (128-byte +BinStruct::CString+),
31
+ # * and a body (+BinStruct::String+).
32
32
  #
33
- # == Create a BOOTP header
33
+ # @example Create a BOOTP header
34
34
  # # standalone
35
35
  # bootp = PacketGen::Header::BOOTP.new
36
36
  # # in a packet
37
- # pkt = PacketGen.gen('IP').add('BOOTP')
37
+ # pkt = PacketGen.gen('IP').add('UDP').add('BOOTP')
38
38
  # # access to BOOTP header
39
- # pkt.bootp # => PacketGen::Header::BOOTP
39
+ # pkt.bootp.protocol_name # => "BOOTP"
40
40
  # @author Sylvain Daubert
41
41
  # @since 2.2.0
42
42
  class BOOTP < 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.
@@ -58,12 +58,12 @@ module PacketGen
58
58
  }.freeze
59
59
 
60
60
  # @!parse
61
- # # Option class with string value. {#type #type} and {#length #length} are
62
- # # {BinStruct::Int8}.
61
+ # # Option class with string value. +#type+ and +#length+ are
62
+ # # +BinStruct::Int8+.
63
63
  # #
64
- # # See also {IPAddrOption}, {Int8Option}, {Int16Option} and {Int32Option}.
64
+ # # See also specialized {IPAddrOption}, {Int8Option}, {Int16Option} and {Int32Option}.
65
65
  # # @since 2.2.0
66
- # # @since 3.1.0 subclass of {BinStruct::AbstractTLV}
66
+ # # @since 3.1.0 subclass of +BinStruct::AbstractTLV+
67
67
  # class Option < BinStruct::AbstractTLV; end
68
68
  # @private
69
69
  Option = BinStruct::AbstractTLV.create
@@ -71,7 +71,7 @@ module PacketGen
71
71
  # @!parse
72
72
  # # {Option} class with IP address value
73
73
  # # @since 2.2.0
74
- # # @since 3.1.0 subclass of {BinStruct::AbstractTLV}
74
+ # # @since 3.1.0 subclass of +BinStruct::AbstractTLV+
75
75
  # class IPAddrOption < BinStruct::AbstractTLV; end
76
76
  # @private
77
77
  IPAddrOption = BinStruct::AbstractTLV.create(value_class: IP::Addr)
@@ -79,7 +79,7 @@ module PacketGen
79
79
  # @!parse
80
80
  # # {Option} class with int8 value
81
81
  # # @since 2.2.0
82
- # # @since 3.1.0 subclass of {BinStruct::AbstractTLV}
82
+ # # @since 3.1.0 subclass of +BinStruct::AbstractTLV+
83
83
  # class Int8Option < BinStruct::AbstractTLV; end
84
84
  # @private
85
85
  Int8Option = BinStruct::AbstractTLV.create(value_class: BinStruct::Int8)
@@ -87,7 +87,7 @@ module PacketGen
87
87
  # @!parse
88
88
  # # {Option} class with int16 value
89
89
  # # @since 2.2.0
90
- # # @since 3.1.0 subclass of {BinStruct::AbstractTLV}
90
+ # # @since 3.1.0 subclass of {+inStruct::AbstractTLV+
91
91
  # class Int16Option < BinStruct::AbstractTLV; end
92
92
  # @private
93
93
  Int16Option = BinStruct::AbstractTLV.create(value_class: BinStruct::Int16)
@@ -95,7 +95,7 @@ module PacketGen
95
95
  # @!parse
96
96
  # # {Option} class with int32 value
97
97
  # # @since 2.2.0
98
- # # @since 3.1.0 subclass of {BinStruct::AbstractTLV}
98
+ # # @since 3.1.0 subclass of +BinStruct::AbstractTLV+
99
99
  # class Int32Option < BinStruct::AbstractTLV; end
100
100
  # @private
101
101
  Int32Option = BinStruct::AbstractTLV.create(value_class: BinStruct::Int32)
@@ -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.
@@ -9,9 +9,9 @@
9
9
  module PacketGen
10
10
  module Header
11
11
  class DHCP
12
- # Container class for {Option DHCP Options}.
12
+ # Container class for {Option DHCP Options}. Accepted options are listed on {DHCP::DHCP_OPTIONS}.
13
13
  #
14
- # == Add DHCP options to an +Options+ instance
14
+ # @example Add DHCP options to an +Options+ instance
15
15
  # options = PacketGen::Header::DHCP::Options.new
16
16
  # # Add a lease_time option
17
17
  # options << { type: 'lease_time', value: 3600 }
@@ -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.
@@ -12,22 +12,21 @@ module PacketGen
12
12
  # RFC 2131}
13
13
  #
14
14
  # A DHCP header is quite simple. It is composed of:
15
- # * a {#magic} field ({BinStruct::Int32}) to retrieve it in a BOOTP header,
16
- # * a, {#options} field ({Options} type, which is a collection of DHCP
15
+ # * a {#magic} field (+BinStruct::Int32+) to retrieve it in a BOOTP header,
16
+ # * a {#options} field ({Options} type, which is a collection of DHCP
17
17
  # options).
18
18
  #
19
19
  # In PacketGen, a DHCP header is always a secondary header after {BOOTP} one.
20
20
  #
21
- # == Create a DHCP header
21
+ # @example Create a DHCP header
22
22
  # # standalone
23
23
  # dhcp = PacketGen::Header::DHCP.new
24
24
  # # in a packet
25
- # pkt = PacketGen.gen('IP').add('BOOTP').add('DHCP')
25
+ # pkt = PacketGen.gen('IP').add('UDP').add('BOOTP').add('DHCP')
26
26
  # # access to DHCP header
27
- # pkt.dhcp # => PacketGen::Header::DHCP
27
+ # pkt.dhcp.class # => PacketGen::Header::DHCP
28
28
  #
29
- # == Add options
30
- # Options may be added these ways:
29
+ # @example Add options to a DHCP header
31
30
  # dhcp = PacketGen::Header::DHCP.new
32
31
  # # Add a lease_time option
33
32
  # dhcp.options << { type: 'lease_time', value: 3600 }
@@ -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.
@@ -25,7 +25,7 @@ module PacketGen
25
25
  # @return [Integer]
26
26
  define_attr :type, BinStruct::Int16Enum, enum: TYPES
27
27
  # @!attribute body
28
- # @abstract replaced by specific attributes.in subclasses
28
+ # @abstract replaced by specific attributes in subclasses
29
29
  # DUID data.
30
30
  # @return [String]
31
31
  define_attr :body, BinStruct::String
@@ -67,9 +67,7 @@ module PacketGen
67
67
  end
68
68
  end
69
69
 
70
- # rubocop:disable Naming/ClassAndModuleCamelCase
71
-
72
- # DUID Based on Link-layer Address Plus Time
70
+ # DUID Based on Link-layer Address Plus Time
73
71
  # @author Sylvain Daubert
74
72
  class DUID_LLT < DUID
75
73
  remove_attr :body
@@ -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.
@@ -9,10 +9,10 @@
9
9
  module PacketGen
10
10
  module Header
11
11
  class DHCPv6
12
- # A DHCPv6 consists of:
13
- # * a {#type} ({BinStruct::Int16}),
14
- # * a {#length} ({BinStruct::Int16}),
15
- # * and a {#data} ({BinStruct::String}).
12
+ # A DHCPv6 option consists of:
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).
@@ -25,9 +25,10 @@ module PacketGen
25
25
  # @return [Integer]
26
26
  define_attr :type, BinStruct::Int16
27
27
  # @!attribute length
28
- # 16-bit option length
28
+ # 16-bit option length. Length of data part.
29
29
  # @return [Integer]
30
30
  define_attr :length, BinStruct::Int16
31
+ # @!scope class
31
32
  # @!attribute data
32
33
  # variable length option data.
33
34
  # @return [String]
@@ -216,13 +217,6 @@ module PacketGen
216
217
  end
217
218
  end
218
219
 
219
- # List of requested options for {ORO} option.
220
- # Set of {BinStruct::Int16}
221
- # @author Sylvain Daubert
222
- class RequestedOptions < BinStruct::Array
223
- set_of BinStruct::Int16
224
- end
225
-
226
220
  # DHCPv6 Option Request Option
227
221
  # @author Sylvain Daubert
228
222
  class ORO < Option
@@ -230,8 +224,10 @@ module PacketGen
230
224
  remove_attr :data
231
225
 
232
226
  # @!attribute options
233
- # @return [RequestedOptions]
234
- define_attr :options, RequestedOptions, builder: ->(h, t) { t.new(length_from: h[:length]) }
227
+ # @return [BinStruct::ArrayOfInt16]
228
+ # @since 2.5.0
229
+ # @since 4.1.0 Type +BinStruct::ArrayOfInt16+ instead of custom +RequestedOptions+ (deleted)
230
+ define_attr :options, BinStruct::ArrayOfInt16, builder: ->(h, t) { t.new(length_from: h[:length]) }
235
231
 
236
232
  # Get human-readable data
237
233
  # @return [String]
@@ -280,6 +276,9 @@ module PacketGen
280
276
  # @author Sylvain Daubert
281
277
  class RelayMessage < Option
282
278
  update_attr :type, default: 9
279
+ # @!attribute data
280
+ # variable length option data.
281
+ # @return [String]
283
282
  end
284
283
 
285
284
  # DHCPv6 Server Unicast option
@@ -302,8 +301,31 @@ module PacketGen
302
301
 
303
302
  # DHCPv6 Status Code option
304
303
  # @author Sylvain Daubert
305
- class StatusCode < ElapsedTime
304
+ class StatusCode < Option
306
305
  update_attr :type, default: 13
306
+ remove_attr :data
307
+
308
+ # @!attribute status_code
309
+ # 16-bit status code
310
+ # @return [Integer]
311
+ define_attr :status_code, BinStruct::Int16
312
+ # @!attribute status_message
313
+ # UTF-8 encoded text string suitable for display to an end user
314
+ # @return [::String]
315
+ define_attr :status_message, BinStruct::String
316
+
317
+ # @param [Hash] options
318
+ def initialize(options={})
319
+ options[:length] = options[:status_message].to_s.size + 2 if options[:status_message]
320
+ super
321
+ self.length = self.sz - 4 if options[:status_message].nil?
322
+ end
323
+
324
+ # Get human-readable data (status code)
325
+ # @return [String]
326
+ def human_data
327
+ status_code.to_s
328
+ end
307
329
  end
308
330
 
309
331
  # DHCPv6 Rapid Commit option