packetgen 3.3.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -21
  3. data/lib/packetgen/capture.rb +2 -2
  4. data/lib/packetgen/config.rb +0 -1
  5. data/lib/packetgen/deprecation.rb +7 -7
  6. data/lib/packetgen/header/arp.rb +13 -13
  7. data/lib/packetgen/header/asn1_base.rb +1 -1
  8. data/lib/packetgen/header/base.rb +17 -18
  9. data/lib/packetgen/header/bootp.rb +32 -34
  10. data/lib/packetgen/header/dhcp/option.rb +19 -19
  11. data/lib/packetgen/header/dhcp/options.rb +1 -1
  12. data/lib/packetgen/header/dhcp.rb +3 -3
  13. data/lib/packetgen/header/dhcpv6/duid.rb +16 -16
  14. data/lib/packetgen/header/dhcpv6/option.rb +53 -53
  15. data/lib/packetgen/header/dhcpv6/options.rb +1 -1
  16. data/lib/packetgen/header/dhcpv6/relay.rb +5 -5
  17. data/lib/packetgen/header/dhcpv6.rb +6 -6
  18. data/lib/packetgen/header/dns/name.rb +14 -10
  19. data/lib/packetgen/header/dns/opt.rb +2 -2
  20. data/lib/packetgen/header/dns/option.rb +11 -11
  21. data/lib/packetgen/header/dns/qdsection.rb +1 -1
  22. data/lib/packetgen/header/dns/question.rb +6 -8
  23. data/lib/packetgen/header/dns/rr.rb +56 -43
  24. data/lib/packetgen/header/dns/rrsection.rb +4 -4
  25. data/lib/packetgen/header/dns.rb +27 -30
  26. data/lib/packetgen/header/dot11/control.rb +11 -11
  27. data/lib/packetgen/header/dot11/data.rb +20 -20
  28. data/lib/packetgen/header/dot11/element.rb +4 -4
  29. data/lib/packetgen/header/dot11/management.rb +8 -8
  30. data/lib/packetgen/header/dot11/sub_mngt.rb +39 -53
  31. data/lib/packetgen/header/dot11.rb +88 -93
  32. data/lib/packetgen/header/dot1q.rb +10 -12
  33. data/lib/packetgen/header/dot1x.rb +9 -9
  34. data/lib/packetgen/header/eap/fast.rb +4 -4
  35. data/lib/packetgen/header/eap/md5.rb +6 -6
  36. data/lib/packetgen/header/eap/tls.rb +13 -15
  37. data/lib/packetgen/header/eap/ttls.rb +13 -15
  38. data/lib/packetgen/header/eap.rb +22 -22
  39. data/lib/packetgen/header/eth.rb +18 -18
  40. data/lib/packetgen/header/gre.rb +8 -10
  41. data/lib/packetgen/header/http/headers.rb +2 -2
  42. data/lib/packetgen/header/http/request.rb +17 -16
  43. data/lib/packetgen/header/http/response.rb +18 -17
  44. data/lib/packetgen/header/http/verbs.rb +1 -3
  45. data/lib/packetgen/header/icmp.rb +8 -8
  46. data/lib/packetgen/header/icmpv6.rb +3 -3
  47. data/lib/packetgen/header/igmp.rb +8 -8
  48. data/lib/packetgen/header/igmpv3/group_record.rb +12 -12
  49. data/lib/packetgen/header/igmpv3/mq.rb +16 -18
  50. data/lib/packetgen/header/igmpv3/mr.rb +4 -4
  51. data/lib/packetgen/header/igmpv3.rb +7 -7
  52. data/lib/packetgen/header/ip/addr.rb +13 -13
  53. data/lib/packetgen/header/ip/option.rb +31 -33
  54. data/lib/packetgen/header/ip/options.rb +1 -1
  55. data/lib/packetgen/header/ip.rb +37 -72
  56. data/lib/packetgen/header/ipv6/addr.rb +14 -14
  57. data/lib/packetgen/header/ipv6/extension.rb +8 -8
  58. data/lib/packetgen/header/ipv6/hop_by_hop.rb +9 -9
  59. data/lib/packetgen/header/ipv6.rb +20 -22
  60. data/lib/packetgen/header/llc.rb +17 -17
  61. data/lib/packetgen/header/mdns.rb +1 -1
  62. data/lib/packetgen/header/mld.rb +6 -6
  63. data/lib/packetgen/header/mldv2/mcast_address_record.rb +11 -11
  64. data/lib/packetgen/header/mldv2/mlq.rb +21 -23
  65. data/lib/packetgen/header/mldv2/mlr.rb +8 -8
  66. data/lib/packetgen/header/ospfv2/db_description.rb +11 -12
  67. data/lib/packetgen/header/ospfv2/hello.rb +11 -11
  68. data/lib/packetgen/header/ospfv2/ls_ack.rb +1 -1
  69. data/lib/packetgen/header/ospfv2/ls_request.rb +9 -9
  70. data/lib/packetgen/header/ospfv2/ls_update.rb +3 -3
  71. data/lib/packetgen/header/ospfv2/lsa.rb +54 -58
  72. data/lib/packetgen/header/ospfv2/lsa_header.rb +9 -9
  73. data/lib/packetgen/header/ospfv2.rb +27 -29
  74. data/lib/packetgen/header/ospfv3/db_description.rb +13 -14
  75. data/lib/packetgen/header/ospfv3/hello.rb +12 -12
  76. data/lib/packetgen/header/ospfv3/ipv6_prefix.rb +17 -19
  77. data/lib/packetgen/header/ospfv3/ls_ack.rb +2 -2
  78. data/lib/packetgen/header/ospfv3/ls_request.rb +9 -9
  79. data/lib/packetgen/header/ospfv3/ls_update.rb +4 -4
  80. data/lib/packetgen/header/ospfv3/lsa.rb +48 -51
  81. data/lib/packetgen/header/ospfv3/lsa_header.rb +9 -9
  82. data/lib/packetgen/header/ospfv3.rb +25 -27
  83. data/lib/packetgen/header/sctp/chunk.rb +44 -41
  84. data/lib/packetgen/header/sctp/error.rb +52 -52
  85. data/lib/packetgen/header/sctp/parameter.rb +38 -38
  86. data/lib/packetgen/header/sctp.rb +5 -5
  87. data/lib/packetgen/header/snmp.rb +2 -2
  88. data/lib/packetgen/header/tcp/option.rb +45 -39
  89. data/lib/packetgen/header/tcp/options.rb +2 -2
  90. data/lib/packetgen/header/tcp.rb +55 -44
  91. data/lib/packetgen/header/tftp.rb +16 -16
  92. data/lib/packetgen/header/udp.rb +8 -8
  93. data/lib/packetgen/header.rb +9 -10
  94. data/lib/packetgen/headerable.rb +13 -3
  95. data/lib/packetgen/inspect.rb +2 -2
  96. data/lib/packetgen/packet.rb +54 -37
  97. data/lib/packetgen/pcap.rb +15 -4
  98. data/lib/packetgen/pcapng/block.rb +18 -17
  99. data/lib/packetgen/pcapng/epb.rb +13 -15
  100. data/lib/packetgen/pcapng/file.rb +3 -97
  101. data/lib/packetgen/pcapng/idb.rb +9 -11
  102. data/lib/packetgen/pcapng/shb.rb +13 -15
  103. data/lib/packetgen/pcapng/spb.rb +8 -10
  104. data/lib/packetgen/pcapng/unknown_block.rb +6 -17
  105. data/lib/packetgen/pcapng.rb +4 -4
  106. data/lib/packetgen/pcaprub_wrapper.rb +17 -1
  107. data/lib/packetgen/proto.rb +1 -1
  108. data/lib/packetgen/unknown_packet.rb +2 -2
  109. data/lib/packetgen/utils/arp_spoofer.rb +18 -19
  110. data/lib/packetgen/utils.rb +2 -2
  111. data/lib/packetgen/version.rb +1 -1
  112. data/lib/packetgen.rb +4 -3
  113. metadata +34 -29
  114. data/lib/packetgen/types/abstract_tlv.rb +0 -278
  115. data/lib/packetgen/types/array.rb +0 -287
  116. data/lib/packetgen/types/cstring.rb +0 -109
  117. data/lib/packetgen/types/enum.rb +0 -171
  118. data/lib/packetgen/types/fieldable.rb +0 -66
  119. data/lib/packetgen/types/fields.rb +0 -622
  120. data/lib/packetgen/types/int.rb +0 -473
  121. data/lib/packetgen/types/int_string.rb +0 -102
  122. data/lib/packetgen/types/length_from.rb +0 -54
  123. data/lib/packetgen/types/oui.rb +0 -52
  124. data/lib/packetgen/types/string.rb +0 -97
  125. data/lib/packetgen/types/tlv.rb +0 -161
  126. data/lib/packetgen/types.rb +0 -26
@@ -1,97 +0,0 @@
1
- # coding: utf-8
2
- # frozen_string_literal: true
3
-
4
- # This file is part of PacketGen
5
- # See https://github.com/lemontree55/packetgen for more informations
6
- # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
7
- # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
8
- # This program is published under MIT license.
9
-
10
- require 'forwardable'
11
-
12
- module PacketGen
13
- module Types
14
- # This class mimics regular String, but it is {Fieldable}.
15
- # @author Sylvain Daubert
16
- # @since 3.1.6 no more a subclass or regular String
17
- class String
18
- extend Forwardable
19
- include Fieldable
20
- include LengthFrom
21
-
22
- def_delegators :@string, :[], :to_s, :length, :size, :inspect, :==,
23
- :unpack, :force_encoding, :encoding, :index, :empty?,
24
- :encode, :slice, :slice!, :[]=
25
-
26
- # @return [::String]
27
- attr_reader :string
28
- # @return [Integer]
29
- attr_reader :static_length
30
-
31
- # @param [Hash] options
32
- # @option options [Types::Int,Proc] :length_from object or proc from which
33
- # takes length when reading
34
- # @option options [Integer] :static_length set a static length for this string
35
- def initialize(options={})
36
- register_internal_string(+'')
37
- initialize_length_from(options)
38
- @static_length = options[:static_length]
39
- end
40
-
41
- def initialize_copy(_orig)
42
- @string = @string.dup
43
- end
44
-
45
- # @param [::String] str
46
- # @return [String] self
47
- def read(str)
48
- s = read_with_length_from(str)
49
- register_internal_string s
50
- self
51
- end
52
-
53
- alias old_sz_to_read sz_to_read
54
- private :old_sz_to_read
55
-
56
- # Size to read.
57
- # Computed from static_length or length_from, if defined.
58
- # @return [Integer]
59
- # @since 3.1.6
60
- def sz_to_read
61
- return static_length if static_length?
62
-
63
- old_sz_to_read
64
- end
65
-
66
- # Say if a static length is defined
67
- # @return [Boolean]
68
- # @since 3.1.6
69
- def static_length?
70
- !static_length.nil?
71
- end
72
-
73
- def format_inspect
74
- inspect
75
- end
76
-
77
- # Append the given string to String
78
- # @param [#to_s] str
79
- # @return [self]
80
- def <<(str)
81
- @string << str.to_s
82
- self
83
- end
84
-
85
- alias sz length
86
- alias to_human to_s
87
- alias from_human read
88
-
89
- private
90
-
91
- def register_internal_string(str)
92
- @string = str
93
- PacketGen.force_binary(@string)
94
- end
95
- end
96
- end
97
- end
@@ -1,161 +0,0 @@
1
- # coding: utf-8
2
- # frozen_string_literal: true
3
-
4
- # This file is part of PacketGen
5
- # See https://github.com/lemontree55/packetgen for more informations
6
- # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
7
- # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
8
- # This program is published under MIT license.
9
-
10
- module PacketGen
11
- module Types
12
- # Class to handle Type-Length-Value attributes
13
- #
14
- # TLV fields handles three subfields:
15
- # * a tag/type field (defaults: {Int8} type),
16
- # * a length field (defaults: {Int8} type),
17
- # * a value field (defaults: {String} type).
18
- #
19
- # {#initialize} supports options to change tag and length type. By example, to
20
- # declare a TLV using {Int16}:
21
- # define_field :tlv, PacketGen::Types::TLV, builder: ->(obj) { PacketGen::Types::TLV.new(t: PacketGen::Types::Int16, l: PacketGen::Types::Int16) }
22
- #
23
- # == Subclasses
24
- # A subclass may defined a constant hash TYPES. This hash defines human readable
25
- # types versus their integer values. Hash keys are integer values, and hash values
26
- # are types as strings.
27
- #
28
- # If TYPES is defined, a subclass may:
29
- # * print human readable type using {#human_type},
30
- # * set type as String with {#type=}.
31
- # @author Sylvain Daubert
32
- # @deprecated Use {AbstractTLV} instead.
33
- # @since 3.1.0 deprecated
34
- class TLV < Fields
35
- include Fieldable
36
-
37
- # @!attribute type
38
- # @return [Integer]
39
- define_field :type, Int8
40
- # @!attribute length
41
- # @return [Integer]
42
- define_field :length, Int8
43
- # @!attribute value
44
- # @return [String]
45
- define_field :value, String
46
-
47
- # @param [Hash] options
48
- # @option options [Integer] :type
49
- # @option options [Integer] :length
50
- # @option options [String] :value
51
- # @option options [Class] :t {Int} subclass for +:type+ attribute.
52
- # Default: {Int8}.
53
- # @option options [Class] :l {Int} subclass for +:length+ attribute.
54
- # Default: {Int8}.
55
- # @option options [Class] :v {String} subclass for +:value+ attribute.
56
- # Default: {Types::String}.
57
- def initialize(options={})
58
- Deprecation.deprecated_class(self.class, AbstractTLV)
59
- super
60
- initialize_types(options)
61
- initialize_values(options)
62
- end
63
-
64
- # Populate object from a binary string
65
- # @param [String] str
66
- # @return [Fields] self
67
- def read(str)
68
- idx = 0
69
- self[:type].read str[idx, self[:type].sz]
70
- idx += self[:type].sz
71
- self[:length].read str[idx, self[:length].sz]
72
- idx += self[:length].sz
73
- self[:value].read str[idx, self.length]
74
- self
75
- end
76
-
77
- # @private
78
- alias old_type= type=
79
-
80
- undef type=, value=, value
81
-
82
- # Set type
83
- # @param [::String,Integer] val
84
- # @return [Integer]
85
- # @raise [TypeError] class does not define TYPES
86
- # @raise [ArgumentError] unknown string type
87
- def type=(val)
88
- case val
89
- when Integer
90
- self.old_type = val
91
- else
92
- raise TypeError, 'need an Integer' unless human_types?
93
-
94
- new_val = self.class::TYPES.key(val.to_s)
95
- raise ArgumentError, "unknown #{val} type" if new_val.nil?
96
-
97
- self.old_type = new_val
98
- end
99
- end
100
-
101
- # Set +value+. May set +length+ if value is a {Types::String}.
102
- # @param [::String,Integer] val
103
- # @return [::String,Integer]
104
- def value=(val)
105
- self[:value].from_human val
106
- self.length = self[:value].sz
107
- val
108
- end
109
-
110
- # Get +value+
111
- # @return [Object] depend on +value+ type
112
- def value
113
- self[:value].to_human
114
- end
115
-
116
- # Return human readable type, if TYPES is defined
117
- # @return [String]
118
- def human_type
119
- if human_types?
120
- htype = self.class::TYPES[type]
121
- htype = type if htype.nil?
122
- htype.to_s
123
- else
124
- type.to_s
125
- end
126
- end
127
-
128
- # @return [String]
129
- def to_human
130
- name = self.class.to_s.gsub(/.*::/, '')
131
- @typestr ||= if human_types?
132
- types = self.class::TYPES.values
133
- "%-#{types.max_by(&:length).size}s"
134
- else
135
- '%s'
136
- end
137
- lenstr = "%-#{(2**self[:length].nbits - 1).to_s.size}u"
138
- "#{name} type:#{@typestr} length:#{lenstr} value:#{value.inspect}" % [human_type,
139
- length]
140
- end
141
-
142
- private
143
-
144
- def human_types?
145
- self.class.const_defined? :TYPES
146
- end
147
-
148
- def initialize_types(options)
149
- self[:type] = options[:t].new(self.type) if options[:t]
150
- self[:length] = options[:l].new(self.length) if options[:l]
151
- self[:value] = options[:v].new if options[:v]
152
- end
153
-
154
- def initialize_values(options)
155
- self.type = options[:type] if options[:type]
156
- self.value = options[:value] if options[:value]
157
- self.length = options[:length] if options[:length]
158
- end
159
- end
160
- end
161
- end
@@ -1,26 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # This file is part of PacketGen
4
- # See https://github.com/lemontree55/packetgen for more informations
5
- # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
6
- # Copyright (C) 2024 LemonTree55 <lenontree@proton.me>
7
- # This program is published under MIT license.
8
-
9
- module PacketGen
10
- # Module to group all type definitions
11
- module Types
12
- end
13
- end
14
-
15
- require_relative 'types/length_from'
16
- require_relative 'types/fieldable'
17
- require_relative 'types/int'
18
- require_relative 'types/enum'
19
- require_relative 'types/string'
20
- require_relative 'types/int_string'
21
- require_relative 'types/cstring'
22
- require_relative 'types/fields'
23
- require_relative 'types/array'
24
- require_relative 'types/oui'
25
- require_relative 'types/abstract_tlv'
26
- require_relative 'types/tlv'