packetgen 3.3.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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
@@ -12,15 +12,15 @@ module PacketGen
12
12
  # {https://tools.ietf.org/html/rfc3748 RFC 3748}
13
13
  #
14
14
  # A EAP header has:
15
- # * a {#code} field ({Types::Int8Enum}),
16
- # * a {#id} field ({Types::Int8}),
17
- # * a {#length} field ({Types::Int16}).
15
+ # * a {#code} field ({BinStruct::Int8Enum}),
16
+ # * a {#id} field ({BinStruct::Int8}),
17
+ # * a {#length} field ({BinStruct::Int16}).
18
18
  # Request (code 1) and Response (code 2) packets also have:
19
- # * a {#type} field (+Types::Int8Enum+).
19
+ # * a {#type} field (+BinStruct::Int8Enum+).
20
20
  # And Expanded Types (type 254) packets also have:
21
- # * a {#vendor_id} field ({Types::Int24}),
22
- # * a {#vendor_type} field ({Types::Int32}).
23
- # Finally, all packets have a {#body} ({Types::String}).
21
+ # * a {#vendor_id} field ({BinStruct::Int24}),
22
+ # * a {#vendor_type} field ({BinStruct::Int32}).
23
+ # Finally, all packets have a {#body} ({BinStruct::String}).
24
24
  #
25
25
  # == Create EAP headers
26
26
  # An EAP header may be created this way:
@@ -82,41 +82,41 @@ module PacketGen
82
82
 
83
83
  # @!attribute code
84
84
  # @return [Integer] 8-bit EAP code
85
- define_field :code, Types::Int8Enum, enum: CODES
85
+ define_attr :code, BinStruct::Int8Enum, enum: CODES
86
86
 
87
87
  # @!attribute id
88
88
  # @return [Integer] 8-bit identifier
89
- define_field :id, Types::Int8
89
+ define_attr :id, BinStruct::Int8
90
90
 
91
91
  # @!attribute length
92
92
  # @return [Integer] 16-bit length of EAP packet
93
- define_field :length, Types::Int16, default: 4
93
+ define_attr :length, BinStruct::Int16, default: 4
94
94
 
95
95
  # @!attribute type
96
96
  # This field is present only for Request or Response packets,
97
97
  # with type different from Expanded Types (254).
98
98
  # @return [Integer] 8-bit request or response type
99
- define_field :type, Types::Int8Enum,
100
- enum: TYPES,
101
- optional: ->(eap) { eap.type? }
99
+ define_attr :type, BinStruct::Int8Enum,
100
+ enum: TYPES,
101
+ optional: lambda(&:type?)
102
102
 
103
103
  # @!attribute vendor_id
104
104
  # This field is present only for Request or Response packets,
105
105
  # with type equal to +Expanded Types+ (254).
106
106
  # @return [Integer] 24-bit vendor ID
107
- define_field :vendor_id, Types::Int24,
108
- optional: ->(eap) { eap.type? && (eap.type == 254) }
107
+ define_attr :vendor_id, BinStruct::Int24,
108
+ optional: ->(eap) { eap.type? && (eap.type == 254) }
109
109
 
110
110
  # @!attribute vendor_type
111
111
  # This field is present only for Request or Response packets,
112
112
  # with type equal to +Expanded Types+ (254).
113
113
  # @return [Integer] 32-bit vendor type
114
- define_field :vendor_type, Types::Int32,
115
- optional: ->(eap) { eap.type? && (eap.type == 254) }
114
+ define_attr :vendor_type, BinStruct::Int32,
115
+ optional: ->(eap) { eap.type? && (eap.type == 254) }
116
116
 
117
117
  # @!attribute body
118
- # @return [Types::String, Header::Base]
119
- define_field :body, Types::String
118
+ # @return [BinStruct::String, Header::Base]
119
+ define_attr :body, BinStruct::String
120
120
 
121
121
  # @return [EAP]
122
122
  def initialize(options={})
@@ -132,7 +132,7 @@ module PacketGen
132
132
  # @return [Dot11] may return a subclass object if a more specific class
133
133
  # may be determined
134
134
  def read(str)
135
- super(str)
135
+ super
136
136
  return self unless self.instance_of?(EAP)
137
137
  return self unless type?
138
138
 
@@ -201,7 +201,7 @@ module PacketGen
201
201
  # Calculate length field from content
202
202
  # @return [Integer]
203
203
  def calc_length
204
- Base.calculate_and_set_length self
204
+ Base.calculate_and_set_length(self)
205
205
  end
206
206
 
207
207
  # Say is this EAP header has {#type} field
@@ -217,7 +217,7 @@ module PacketGen
217
217
  # @param [Packet] packet
218
218
  # @return [void]
219
219
  def added_to_packet(packet)
220
- return if packet.respond_to? :eap
220
+ return if packet.respond_to?(:eap)
221
221
 
222
222
  packet.instance_eval("def eap(arg=nil); header(#{self.class}, arg); end") # def eap(arg=nil); header(EAP, arg); end
223
223
  end
@@ -11,8 +11,8 @@ module PacketGen
11
11
  # An Ethernet header consists of:
12
12
  # * a destination MAC address ({MacAddr}),
13
13
  # * a source MAC address (MacAddr),
14
- # * a {#ethertype} ({Types::Int16}),
15
- # * and a body (a {Types::String} or another Header class).
14
+ # * a {#ethertype} ({BinStruct::Int16}),
15
+ # * and a body (a {BinStruct::String} or another Header class).
16
16
  #
17
17
  # == Create a Ethernet header
18
18
  # # standalone
@@ -33,27 +33,27 @@ module PacketGen
33
33
  class Eth < Base
34
34
  # Ethernet MAC address, as a group of 6 bytes
35
35
  # @author Sylvain Daubert
36
- class MacAddr < Types::Fields
37
- include Types::Fieldable
36
+ class MacAddr < BinStruct::Struct
37
+ include BinStruct::Structable
38
38
 
39
39
  # @!attribute a0
40
40
  # @return [Integer] first byte from MacAddr
41
- define_field :a0, Types::Int8
41
+ define_attr :a0, BinStruct::Int8
42
42
  # @!attribute a1
43
43
  # @return [Integer] second byte from MacAddr
44
- define_field :a1, Types::Int8
44
+ define_attr :a1, BinStruct::Int8
45
45
  # @!attribute a2
46
46
  # @return [Integer] third byte from MacAddr
47
- define_field :a2, Types::Int8
47
+ define_attr :a2, BinStruct::Int8
48
48
  # @!attribute a3
49
49
  # @return [Integer] fourth byte from MacAddr
50
- define_field :a3, Types::Int8
50
+ define_attr :a3, BinStruct::Int8
51
51
  # @!attribute a4
52
52
  # @return [Integer] fifth byte from MacAddr
53
- define_field :a4, Types::Int8
53
+ define_attr :a4, BinStruct::Int8
54
54
  # @!attribute a5
55
55
  # @return [Integer] sixth byte from MacAddr
56
- define_field :a5, Types::Int8
56
+ define_attr :a5, BinStruct::Int8
57
57
 
58
58
  # Read a human-readable string to populate +MacAddr+
59
59
  # @param [String] str
@@ -65,7 +65,7 @@ module PacketGen
65
65
  raise ArgumentError, 'not a MAC address' unless bytes.size == 6
66
66
 
67
67
  6.times do |i|
68
- self[:"a#{i}"].read(bytes[i].to_i(16))
68
+ self[:"a#{i}"].from_human(bytes[i].to_i(16))
69
69
  end
70
70
  self
71
71
  end
@@ -73,27 +73,27 @@ module PacketGen
73
73
  # +MacAddr+ in human readable form (colon format)
74
74
  # @return [String]
75
75
  def to_human
76
- fields.map { |m| '%02x' % self[m] }.join(':')
76
+ attributes.map { |m| '%02x' % self[m] }.join(':')
77
77
  end
78
78
 
79
79
  def ==(other)
80
80
  other.is_a?(self.class) &&
81
- fields.all? { |attr| self[attr].value == other[attr].value }
81
+ attributes.all? { |attr| self[attr].value == other[attr].value }
82
82
  end
83
83
  end
84
84
 
85
85
  # @!attribute dst
86
86
  # @return [MacAddr] Destination MAC address
87
- define_field :dst, MacAddr, default: '00:00:00:00:00:00'
87
+ define_attr :dst, MacAddr, default: '00:00:00:00:00:00'
88
88
  # @!attribute src
89
89
  # @return [MacAddr] Source MAC address
90
- define_field :src, MacAddr, default: '00:00:00:00:00:00'
90
+ define_attr :src, MacAddr, default: '00:00:00:00:00:00'
91
91
  # @!attribute ethertype
92
92
  # @return [Integer] 16-bit integer to determine payload type
93
- define_field :ethertype, Types::Int16, default: 0
93
+ define_attr :ethertype, BinStruct::Int16, default: 0
94
94
  # @!attribute body
95
- # @return [Types::String,Header::Base]
96
- define_field :body, Types::String
95
+ # @return [BinStruct::String,Header::Base]
96
+ define_attr :body, BinStruct::String
97
97
 
98
98
  # send Eth packet on wire.
99
99
  # @param [String] iface interface name
@@ -26,8 +26,6 @@ module PacketGen
26
26
  # IP protocol number for GRE
27
27
  IP_PROTOCOL = 47
28
28
 
29
- define_field :u16, Types::Int16
30
-
31
29
  # @!attribute c
32
30
  # @return [Boolean]
33
31
  # @!attribute k
@@ -38,26 +36,26 @@ module PacketGen
38
36
  # @return [Integer]
39
37
  # @!attribute ver
40
38
  # @return [Integer]
41
- define_bit_fields_on :u16, :c, :r, :k, :s, :reserved0, 9, :ver, 3
39
+ define_bit_attr :u16, c: 1, r: 1, k: 1, s: 1, reserved0: 9, ver: 3
42
40
 
43
41
  # @!attribute protocol_type
44
42
  # @return [Integer]
45
- define_field :protocol_type, Types::Int16
43
+ define_attr :protocol_type, BinStruct::Int16
46
44
  # @!attribute checksum
47
45
  # @return [Integer]
48
- define_field :checksum, Types::Int16, default: 0, optional: ->(gre) { gre.c? }
46
+ define_attr :checksum, BinStruct::Int16, default: 0, optional: lambda(&:c?)
49
47
  # @!attribute reserved1
50
48
  # @return [Integer]
51
- define_field :reserved1, Types::Int16, default: 0, optional: ->(gre) { gre.c? }
49
+ define_attr :reserved1, BinStruct::Int16, default: 0, optional: lambda(&:c?)
52
50
  # @!attribute key
53
51
  # @return [Integer]
54
- define_field :key, Types::Int32, optional: ->(gre) { gre.k? }
52
+ define_attr :key, BinStruct::Int32, optional: lambda(&:k?)
55
53
  # @!attribute sequence_number
56
54
  # @return [Integer]
57
- define_field :sequence_number, Types::Int32, optional: ->(gre) { gre.s? }
55
+ define_attr :sequence_number, BinStruct::Int32, optional: lambda(&:s?)
58
56
  # @!attribute body
59
- # @return [Types::String,Header::Base]
60
- define_field :body, Types::String
57
+ # @return [BinStruct::String,Header::Base]
58
+ define_attr :body, BinStruct::String
61
59
 
62
60
  alias seqnum sequence_number
63
61
  alias seqnum= sequence_number=
@@ -13,7 +13,7 @@ module PacketGen
13
13
  # @abstract Base class for HTTP headers.
14
14
  # @author Kent 'picat' Gruber
15
15
  class Headers
16
- include Types::Fieldable
16
+ include BinStruct::Structable
17
17
 
18
18
  # Underlying Headers data (or nil).
19
19
  # @return [Hash, nil]
@@ -76,7 +76,7 @@ module PacketGen
76
76
  end
77
77
 
78
78
  # Read human-readable data to populate header data.
79
- # @param [String, Hash] data
79
+ # @param [Hash] data
80
80
  # @return [self]
81
81
  def from_human(data)
82
82
  read(data)
@@ -10,9 +10,9 @@ module PacketGen
10
10
  module Header
11
11
  module HTTP
12
12
  # An HTTP/1.1 Request packet consists of:
13
- # * the http verb ({Types::String}).
14
- # * the path ({Types::String}).
15
- # * the version ({Types::String}).
13
+ # * the http verb ({BinStruct::String}).
14
+ # * the path ({BinStruct::String}).
15
+ # * the version ({BinStruct::String}).
16
16
  # * associated http headers ({HTTP::Headers}).
17
17
  #
18
18
  # == Create a HTTP Request header
@@ -35,25 +35,26 @@ module PacketGen
35
35
  #
36
36
  # @author Kent 'picat' Gruber
37
37
  # @author Sylvain Daubert
38
+ # @author LemonTree55
38
39
  # @since 3.1.0 Rename +#method+ into {#verb} to not mask +Object#method+.
39
40
  class Request < Base
40
41
  # @!attribute verb
41
- # @return [Types::String]
42
+ # @return [BinStruct::String]
42
43
  # @since 3.1.0
43
- define_field :verb, Types::String
44
+ define_attr :verb, BinStruct::String
44
45
  # @!attribute path
45
- # @return [Types::String]
46
- define_field :path, Types::String
46
+ # @return [BinStruct::String]
47
+ define_attr :path, BinStruct::String
47
48
  # @!attribute version
48
- # @return [Types::String]
49
- define_field :version, Types::String, default: 'HTTP/1.1'
49
+ # @return [BinStruct::String]
50
+ define_attr :version, BinStruct::String, default: 'HTTP/1.1'
50
51
  # @!attribute headers
51
52
  # associated http/1.1 headers
52
53
  # @return [HTTP::Headers]
53
- define_field :headers, HTTP::Headers
54
+ define_attr :headers, HTTP::Headers
54
55
  # @!attribute body
55
- # @return [Types::String]
56
- define_field :body, Types::String
56
+ # @return [BinStruct::String]
57
+ define_attr :body, BinStruct::String
57
58
 
58
59
  # @param [Hash] options
59
60
  # @option options [String] :verb
@@ -61,7 +62,7 @@ module PacketGen
61
62
  # @option options [String] :version
62
63
  # @option options [Hash] :headers
63
64
  def initialize(options={})
64
- super(options)
65
+ super
65
66
  self.headers ||= options[:headers]
66
67
  end
67
68
 
@@ -70,9 +71,9 @@ module PacketGen
70
71
  def read(str)
71
72
  lines = lines(str)
72
73
  first_line_words = lines.shift.split
73
- self[:verb].read first_line_words[0]
74
- self[:path].read first_line_words[1]
75
- self[:version].read first_line_words[2]
74
+ self[:verb].read(first_line_words[0])
75
+ self[:path].read(first_line_words[1])
76
+ self[:version].read(first_line_words[2])
76
77
 
77
78
  # requests can sometimes have a payload
78
79
  headers, data = headers_and_payload_from_lines(lines)
@@ -10,11 +10,11 @@ module PacketGen
10
10
  module Header
11
11
  module HTTP
12
12
  # An HTTP/1.1 Response packet consists of:
13
- # * the version ({Types::String}).
14
- # * the status code ({Types::String}).
15
- # * the status message ({Types::String}).
13
+ # * the version ({BinStruct::String}).
14
+ # * the status code ({BinStruct::String}).
15
+ # * the status message ({BinStruct::String}).
16
16
  # * associated http headers ({HTTP::Headers}).
17
- # * the actual http payload body ({Types::String}).
17
+ # * the actual http payload body ({BinStruct::String}).
18
18
  #
19
19
  # == Create a HTTP Response header
20
20
  # # standalone
@@ -36,23 +36,24 @@ module PacketGen
36
36
  # http_resp.headers = { "Host": "tcpdump.org" } # even a hash
37
37
  #
38
38
  # @author Kent 'picat' Gruber
39
+ # @author LemonTree55
39
40
  class Response < Base
40
41
  # @!attribute version
41
- # @return [Types::String]
42
- define_field :version, Types::String, default: 'HTTP/1.1'
42
+ # @return [BinStruct::String]
43
+ define_attr :version, BinStruct::String, default: 'HTTP/1.1'
43
44
  # @!attribute status_code
44
- # @return [Types::String]
45
- define_field :status_code, Types::String
45
+ # @return [BinStruct::String]
46
+ define_attr :status_code, BinStruct::String
46
47
  # @!attribute status_mesg
47
- # @return [Types::String]
48
- define_field :status_mesg, Types::String
48
+ # @return [BinStruct::String]
49
+ define_attr :status_mesg, BinStruct::String
49
50
  # @!attribute headers
50
51
  # associated http/1.1 headers
51
- # @return [Types::String]
52
- define_field :headers, HTTP::Headers
52
+ # @return [BinStruct::String]
53
+ define_attr :headers, HTTP::Headers
53
54
  # @!attribute body
54
55
  # @return [HTTP::PHeaders]
55
- define_field :body, Types::String
56
+ define_attr :body, BinStruct::String
56
57
 
57
58
  # @param [Hash] options
58
59
  # @option options [String] :version
@@ -61,7 +62,7 @@ module PacketGen
61
62
  # @option options [String] :body
62
63
  # @option options [Hash] :headers
63
64
  def initialize(options={})
64
- super(options)
65
+ super
65
66
  self.headers ||= options[:headers]
66
67
  end
67
68
 
@@ -125,9 +126,9 @@ module PacketGen
125
126
  first_line = headers.shift.split
126
127
  return if first_line.size < 3
127
128
 
128
- self[:version].read first_line[0]
129
- self[:status_code].read first_line[1]
130
- self[:status_mesg].read first_line[2..].join(' ')
129
+ self[:version].read(first_line[0])
130
+ self[:status_code].read(first_line[1])
131
+ self[:status_mesg].read(first_line[2..].join(' '))
131
132
  end
132
133
 
133
134
  def raise_on_bad_version_status
@@ -9,10 +9,8 @@
9
9
  module PacketGen
10
10
  module Header
11
11
  # @since 2.2.0
12
+ # @author Kent 'picat' Gruber
12
13
  module HTTP
13
- # @abstract Collection of useful HTTP verbs.
14
- # @author Kent 'picat' Gruber
15
-
16
14
  # Valid HTTP Verbs
17
15
  VERBS = %w[GET HEAD POST PUT DELETE CONNECT OPTIONS TRACE PATCH].freeze
18
16
 
@@ -15,9 +15,9 @@ module PacketGen
15
15
  # | Type | Code | Checksum |
16
16
  # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17
17
  # A ICMP header consists of:
18
- # * a {#type} field ({Types::Int8} type),
19
- # * a {#code} field ({Types::Int8} type),
20
- # * a {#checksum} field ({Types::Int16} type),
18
+ # * a {#type} field ({BinStruct::Int8} type),
19
+ # * a {#code} field ({BinStruct::Int8} type),
20
+ # * a {#checksum} field ({BinStruct::Int16} type),
21
21
  # * and a {#body}.
22
22
  #
23
23
  # == Create a ICMP header
@@ -41,18 +41,18 @@ module PacketGen
41
41
  # @!attribute type
42
42
  # 8-bit ICMP type
43
43
  # @return [Integer]
44
- define_field :type, Types::Int8
44
+ define_attr :type, BinStruct::Int8
45
45
  # @!attribute code
46
46
  # 8-bit ICMP code
47
47
  # @return [Integer]
48
- define_field :code, Types::Int8
48
+ define_attr :code, BinStruct::Int8
49
49
  # @!attribute checksum
50
50
  # 16-bit ICMP checksum
51
51
  # @return [Integer]
52
- define_field :checksum, Types::Int16
52
+ define_attr :checksum, BinStruct::Int16
53
53
  # @!attribute body
54
- # @return [Types::String,Header::Base]
55
- define_field :body, Types::String
54
+ # @return [BinStruct::String,Header::Base]
55
+ define_attr :body, BinStruct::String
56
56
 
57
57
  # Compute checksum and set +checksum+ field
58
58
  # @return [Integer]
@@ -15,9 +15,9 @@ module PacketGen
15
15
  # | Type | Code | Checksum |
16
16
  # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
17
17
  # A ICMPv6 header consists of:
18
- # * a +type+ field ({Types::Int8} type),
19
- # * a +code+ field ({Types::Int8} type),
20
- # * a +checksum+ field ({Types::Int16} type),
18
+ # * a +type+ field ({BinStruct::Int8} type),
19
+ # * a +code+ field ({BinStruct::Int8} type),
20
+ # * a +checksum+ field ({BinStruct::Int16} type),
21
21
  # * and a +body+.
22
22
  #
23
23
  # == Create a ICMPv6 header
@@ -20,9 +20,9 @@ module PacketGen
20
20
  # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
21
21
  #
22
22
  # A IGMP header consists of:
23
- # * a {#type} field ({Types::Int8Enum} type),
24
- # * a {#max_resp_time} field ({Types::Int8} type),
25
- # * a {#checksum} field ({Types::Int16} type),
23
+ # * a {#type} field ({BinStruct::Int8Enum} type),
24
+ # * a {#max_resp_time} field ({BinStruct::Int8} type),
25
+ # * a {#checksum} field ({BinStruct::Int16} type),
26
26
  # * a {#group_addr} field ({Header::IP::Addr} type),
27
27
  # * and a {#body} (unused for IGMPv2).
28
28
  #
@@ -56,22 +56,22 @@ module PacketGen
56
56
  # @!attribute type
57
57
  # 8-bit IGMP Type
58
58
  # @return [Integer]
59
- define_field :type, Types::Int8Enum, enum: TYPES
59
+ define_attr :type, BinStruct::Int8Enum, enum: TYPES
60
60
  # @!attribute max_resp_time
61
61
  # 8-bit IGMP Max Response Time
62
62
  # @return [Integer]
63
- define_field :max_resp_time, Types::Int8
63
+ define_attr :max_resp_time, BinStruct::Int8
64
64
  # @!attribute checksum
65
65
  # 16-bit IGMP Checksum
66
66
  # @return [Integer]
67
- define_field :checksum, Types::Int16
67
+ define_attr :checksum, BinStruct::Int16
68
68
  # @!attribute group_addr
69
69
  # IP Group address
70
70
  # @return [IP::Addr]
71
- define_field :group_addr, IP::Addr, default: '0.0.0.0'
71
+ define_attr :group_addr, IP::Addr, default: '0.0.0.0'
72
72
  # @!attribute body
73
73
  # @return [String,Base]
74
- define_field :body, Types::String
74
+ define_attr :body, BinStruct::String
75
75
 
76
76
  # @api private
77
77
  # @note This method is used internally by PacketGen and should not be
@@ -11,7 +11,7 @@ module PacketGen
11
11
  class IGMPv3
12
12
  # Class to handle IGMPv3 Group Records.
13
13
  #
14
- # A Group Record is a block of fields containing information
14
+ # A Group Record is a block of attributes.containing information
15
15
  # pertaining to the sender's membership in a single multicast group on
16
16
  # the interface from which the Report is sent.
17
17
  #
@@ -40,8 +40,8 @@ module PacketGen
40
40
  # | |
41
41
  # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42
42
  # @author Sylvain Daubert
43
- class GroupRecord < Types::Fields
44
- include Types::Fieldable
43
+ class GroupRecord < BinStruct::Struct
44
+ include BinStruct::Structable
45
45
 
46
46
  # Known record types
47
47
  RECORD_TYPES = {
@@ -56,29 +56,29 @@ module PacketGen
56
56
  # @!attribute type
57
57
  # 8-bit record type
58
58
  # @return [Integer]
59
- define_field :type, Types::Int8Enum, enum: RECORD_TYPES
59
+ define_attr :type, BinStruct::Int8Enum, enum: RECORD_TYPES
60
60
  # @!attribute aux_data_len
61
61
  # 8-bit length of of the Auxiliary Data field ({#aux_data}), in unit of
62
62
  # 32-bit words
63
63
  # @return [Integer]
64
- define_field :aux_data_len, Types::Int8, default: 0
64
+ define_attr :aux_data_len, BinStruct::Int8, default: 0
65
65
  # @!attribute number_of_sources
66
66
  # 16-bit Number of source addresses in {#source_addr}
67
67
  # @return [Integer]
68
- define_field :number_of_sources, Types::Int16, default: 0
68
+ define_attr :number_of_sources, BinStruct::Int16, default: 0
69
69
  # @!attribute multicast_addr
70
70
  # IP multicast address to which this Group Record pertains
71
71
  # @return [IP::Addr]
72
- define_field :multicast_addr, IP::Addr, default: '0.0.0.0'
72
+ define_attr :multicast_addr, IP::Addr, default: '0.0.0.0'
73
73
  # @!attribute source_addr
74
74
  # Array of source addresses
75
75
  # @return [IP::ArrayOfAddr]
76
- define_field :source_addr, IP::ArrayOfAddr,
77
- builder: ->(h, t) { t.new(counter: h[:number_of_sources]) }
76
+ define_attr :source_addr, IP::ArrayOfAddr,
77
+ builder: ->(h, t) { t.new(counter: h[:number_of_sources]) }
78
78
  # @!attribute aux_data
79
79
  # @return [String]
80
- define_field :aux_data, Types::String,
81
- builder: ->(h, t) { t.new(length_from: -> { h[:aux_data_len].to_i * 4 }) }
80
+ define_attr :aux_data, BinStruct::String,
81
+ builder: ->(h, t) { t.new(length_from: -> { h[:aux_data_len].to_i * 4 }) }
82
82
 
83
83
  def human_type
84
84
  self[:type].to_human
@@ -91,7 +91,7 @@ module PacketGen
91
91
 
92
92
  # Class to handle series of {GroupRecord}.
93
93
  # @author Sylvain Daubert
94
- class GroupRecords < Types::Array
94
+ class GroupRecords < BinStruct::Array
95
95
  set_of GroupRecord
96
96
 
97
97
  # Separator used in {#to_human}.
@@ -31,7 +31,7 @@ module PacketGen
31
31
  # | Source Address [N] |
32
32
  # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33
33
  #
34
- # Fields are:
34
+ # Struct are:
35
35
  # * 32-bit {#group_addr} field ({Header::IP::Addr} type),
36
36
  # * 4-bit {#resv}, a reserved field,
37
37
  # * 1-bit {#flag_s} (Suppress Router-Side Processing),
@@ -44,36 +44,34 @@ module PacketGen
44
44
  # @!attribute group_addr
45
45
  # IP Group address
46
46
  # @return [IP::Addr]
47
- define_field :group_addr, IP::Addr, default: '0.0.0.0'
47
+ define_attr :group_addr, IP::Addr, default: '0.0.0.0'
48
48
  # @!attribute u8
49
49
  # First 8-bit field, composed of {#resv}, {#flag_s} and {#qrv}
50
50
  # @return [Integer]
51
- define_field :u8, Types::Int8
51
+ # @!attribute resv
52
+ # 4-bit reserved field in
53
+ # @return [Integer]
54
+ # @!attribute flag_s
55
+ # 1-bit S flag (Suppress Router-Side Processing)
56
+ # @return [Integer]
57
+ # @!attribute qrv
58
+ # 3-bit Querier's Robustness Variable
59
+ # @return [Integer]
60
+ define_bit_attr :u8, resv: 4, flag_s: 1, qrv: 3
52
61
  # @!attribute qqic
53
62
  # 8-bit QQIC
54
63
  # @return [Integer,Float]
55
- define_field :qqic, Types::Int8
64
+ define_attr :qqic, BinStruct::Int8
56
65
  # @!attribute number_of_sources
57
66
  # 16-bit Number of Sources in {#source_addr}
58
67
  # @return [Integer]
59
- define_field :number_of_sources, Types::Int16
68
+ define_attr :number_of_sources, BinStruct::Int16
60
69
 
61
70
  # @!attribute source_addr
62
71
  # Array of IP source addresses
63
72
  # @return [IP::ArrayOfAddr]
64
- define_field :source_addr, IP::ArrayOfAddr,
65
- builder: ->(h, t) { t.new(counter: h[:number_of_sources]) }
66
-
67
- # @!attribute resv
68
- # 4-bit reserved field in
69
- # @return [Integer]
70
- # @!attribute flag_s
71
- # 1-bit S flag (Suppress Router-Side Processing)
72
- # @return [Boolean]
73
- # @!attribute qrv
74
- # 3-bit Querier's Robustness Variable
75
- # @return [Integer]
76
- define_bit_fields_on :u8, :resv, 4, :flag_s, :qrv, 3
73
+ define_attr :source_addr, IP::ArrayOfAddr,
74
+ builder: ->(h, t) { t.new(counter: h[:number_of_sources]) }
77
75
 
78
76
  undef qqic, qqic=
79
77
 
@@ -49,17 +49,17 @@ module PacketGen
49
49
  # @!attribute reserved
50
50
  # 16-bit reserved field
51
51
  # @return [Integer]
52
- define_field :reserved, Types::Int16, default: 0
52
+ define_attr :reserved, BinStruct::Int16, default: 0
53
53
  # @!attribute number_of_gr
54
54
  # 16-bit Number of group records in {#group_records}
55
55
  # @return [Integer]
56
- define_field :number_of_gr, Types::Int16, default: 0
56
+ define_attr :number_of_gr, BinStruct::Int16, default: 0
57
57
 
58
58
  # @!attribute group_records
59
59
  # Array of group records
60
60
  # @return [GroupRecords]
61
- define_field :group_records, GroupRecords,
62
- builder: ->(h, t) { t.new(counter: h[:number_of_gr]) }
61
+ define_attr :group_records, GroupRecords,
62
+ builder: ->(h, t) { t.new(counter: h[:number_of_gr]) }
63
63
  end
64
64
  end
65
65