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,171 +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
- # @abstract Base enum class to handle binary integers with limited
13
- # authorized values
14
- # An {Enum} type is used to handle an {Int} field with limited
15
- # and named values.
16
- #
17
- # == Simple example
18
- # enum = Int8Enum.new('low' => 0, 'medium' => 1, 'high' => 2})
19
- # In this example, +enum+ is a 8-bit field which may take one
20
- # among three values: +low+, +medium+ or +high+:
21
- # enum.value = 'high'
22
- # enum.value # => 2
23
- # enum.value = 1
24
- # enum.value # => 1
25
- # enum.to_human # => "medium"
26
- # Setting an unknown value will raise an exception:
27
- # enum.value = 4 # => raise!
28
- # enum.value = 'unknown' # => raise!
29
- # But {#read} will not raise when reading an outbound value. This
30
- # to enable decoding (or forging) of bad packets.
31
- # @since 2.1.3
32
- # @author Sylvain Daubert
33
- class Enum < Int
34
- # @return [Hash]
35
- attr_reader :enum
36
-
37
- # @param [Hash] enum enumerated values. Default value is taken from
38
- # first element unless given.
39
- # @param [:little,:big,nil] endian
40
- # @param [Integer,nil] width
41
- # @param [Integer,nil] default default value
42
- def initialize(enum, endian=nil, width=nil, default=nil)
43
- default ||= enum[enum.keys.first]
44
- super(nil, endian, width, default)
45
- @enum = enum
46
- end
47
-
48
- # Setter for value attribute
49
- # @param [#to_i, String,nil] value value as an Integer or as a String
50
- # from enumration
51
- # @return [Integer]
52
- # @raise [ArgumentError] String value is unknown
53
- def value=(value)
54
- ival = case value
55
- when NilClass
56
- nil
57
- when ::String
58
- raise ArgumentError, "#{value.inspect} not in enumeration" unless @enum.key? value
59
-
60
- @enum[value]
61
- else
62
- value.to_i
63
- end
64
- @value = ival
65
- end
66
-
67
- # To handle human API: set value from a String
68
- alias from_human value=
69
-
70
- # Get human readable value (enum name)
71
- # @return [String]
72
- def to_human
73
- @enum.key(to_i) || "<unknown:#{@value}>"
74
- end
75
-
76
- def format_inspect
77
- format_str % [to_human, to_i]
78
- end
79
- end
80
-
81
- # Enumeration on one byte. See {Enum}.
82
- # @author Sylvain Daubert
83
- # @since 2.1.3
84
- class Int8Enum < Enum
85
- # @param [Integer] default
86
- # @param [Hash] enum
87
- def initialize(enum, default=nil)
88
- super(enum, nil, 1, default)
89
- @packstr = { nil => 'C' }
90
- end
91
- end
92
-
93
- # Enumeration on 2-byte integer. See {Enum}.
94
- # @author Sylvain Daubert
95
- # @since 2.1.3
96
- class Int16Enum < Enum
97
- # @param [Hash] enum
98
- # @param [:big, :little] endian
99
- # @param [Integer,nil] default default value
100
- def initialize(enum, endian=:big, default=nil)
101
- super(enum, endian, 2, default)
102
- @packstr = { big: 'n', little: 'v' }
103
- end
104
- end
105
-
106
- # Enumeration on big endian 2-byte integer. See {Enum}.
107
- # @author Sylvain Daubert
108
- # @since 2.1.3
109
- class Int16beEnum < Int16Enum
110
- undef endian=
111
-
112
- # @param [Hash] enum
113
- # @param [Integer,nil] default default value
114
- def initialize(enum, default=nil)
115
- super(enum, :big, default)
116
- end
117
- end
118
-
119
- # Enumeration on big endian 2-byte integer. See {Enum}.
120
- # @author Sylvain Daubert
121
- # @since 2.1.3
122
- class Int16leEnum < Int16Enum
123
- undef endian=
124
-
125
- # @param [Hash] enum
126
- # @param [Integer,nil] default default value
127
- def initialize(enum, default=nil)
128
- super(enum, :little, default)
129
- end
130
- end
131
-
132
- # Enumeration on 4-byte integer. See {Enum}.
133
- # @author Sylvain Daubert
134
- # @since 2.1.3
135
- class Int32Enum < Enum
136
- # @param [Hash] enum
137
- # @param [:big, :little] endian
138
- # @param [Integer,nil] default default value
139
- def initialize(enum, endian=:big, default=nil)
140
- super(enum, endian, 4, default)
141
- @packstr = { big: 'N', little: 'V' }
142
- end
143
- end
144
-
145
- # Enumeration on big endian 4-byte integer. See {Enum}.
146
- # @author Sylvain Daubert
147
- # @since 2.1.3
148
- class Int32beEnum < Int32Enum
149
- undef endian=
150
-
151
- # @param [Hash] enum
152
- # @param [Integer,nil] default default value
153
- def initialize(enum, default=nil)
154
- super(enum, :big, default)
155
- end
156
- end
157
-
158
- # Enumeration on big endian 4-byte integer. See {Enum}.
159
- # @author Sylvain Daubert
160
- # @since 2.1.3
161
- class Int32leEnum < Int32Enum
162
- undef endian=
163
-
164
- # @param [Hash] enum
165
- # @param [Integer,nil] default default value
166
- def initialize(enum, default=nil)
167
- super(enum, :little, default)
168
- end
169
- end
170
- end
171
- end
@@ -1,66 +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 Types
11
- # Mixin to define minimal API for a class to be embbeded as a field in
12
- # {Fields} type.
13
- #
14
- # == Optional methods
15
- # These methods may, optionally, be defined by fieldable types:
16
- # * +from_human+ to load data from a human-readable string.
17
- # @author Sylvain Daubert
18
- # @since 3.1.6
19
- module Fieldable
20
- # Get type name
21
- # @return [String]
22
- def type_name
23
- self.class.to_s.split('::').last
24
- end
25
-
26
- # rubocop:disable Lint/UselessMethodDefinition
27
- # These methods are defined for documentation.
28
-
29
- # Populate object from a binary string
30
- # @param [String] str
31
- # @return [Fields] self
32
- # @abstract subclass should overload it.
33
- def read(str)
34
- super
35
- end
36
-
37
- # Return object as a binary string
38
- # @return [String]
39
- # @abstract subclass should overload it.
40
- def to_s
41
- super
42
- end
43
-
44
- # Size of object as binary string
45
- # @return [Integer]
46
- def sz
47
- to_s.size
48
- end
49
-
50
- # Return a human-readbale string
51
- # @return [String]
52
- # @abstract subclass should overload it.
53
- def to_human
54
- super
55
- end
56
-
57
- # rubocop:enable Lint/UselessMethodDefinition
58
-
59
- # Format object when inspecting a {Fields} object
60
- # @return [String]
61
- def format_inspect
62
- to_human
63
- end
64
- end
65
- end
66
- end