packetgen 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 89bdf542e873de9589a6c7e70b3823ccc306ad02
4
- data.tar.gz: 82fd50fd41475f7471954dde56174853e24dfd1d
3
+ metadata.gz: 45af460b696e393ab1c89b3e27fba605246eafc5
4
+ data.tar.gz: 18f621d8edd0c5c5fee18a97c5ffb9c1d31043c3
5
5
  SHA512:
6
- metadata.gz: b64e2a6f45b6a35c085c819567f9c08ccb2a62502c74861634408b1e1f69fc4c6ac706ad5223f57095fa2f670b2b4d46b920a5f44ecb7fa49381386a7865b736
7
- data.tar.gz: 733c4d48b547aef34bef53c196da7f7d29558286f9791542c316f22e939c2a8c8f75a8b9d372b518b0588723b48c5a84606943b271c41d81d84bd4a985714cb7
6
+ metadata.gz: dfc16c31052743888efb32945d26d16995e975d6affb47c3a52f4fa4338e7906b75548f8d87e14c963ea89d21e08d877e3f9b62cfa723cf35da90b33a42d3cd4
7
+ data.tar.gz: d88d482c4eb651b4175453b29c1e71215935d8ff630598dfcb44c33662b272227bda2aea46f7c219c52cd57c9f5093cf2d03dc668e097c03c58f4a89f725dbf3
@@ -1,3 +1,8 @@
1
+ # This file is part of PacketGen
2
+ # See https://github.com/sdaubert/packetgen for more informations
3
+ # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
4
+ # This program is published under MIT license.
5
+
1
6
  module PacketGen
2
7
 
3
8
  # Capture packets from wire
@@ -1,35 +1,59 @@
1
+ # This file is part of PacketGen
2
+ # See https://github.com/sdaubert/packetgen for more informations
3
+ # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
4
+ # This program is published under MIT license.
5
+
1
6
  module PacketGen
2
7
  module Header
3
8
 
4
- # ARP header class
9
+ # An ARP header consists of:
10
+ # * a hardware type ({#hrd} or {#htype}) field ({Int16}),
11
+ # * a protocol type ({#pro} or {#ptype}) field (+Int16+),
12
+ # * a hardware address length ({#hln} or {#hlen}) field ({Int8}),
13
+ # * a protocol address length ({#pln} or {#plen}) field (+Int8+),
14
+ # * a {#opcode} (or {#op}) field (+Int16+),
15
+ # * a source hardware address ({#sha} or {#src_mac}) field ({Eth::MacAddr}),
16
+ # * a source protocol address ({#spa} or {#src_ip}) field ({IP::Addr}),
17
+ # * a target hardware address ({#tha} or {#dst_mac}) field (+Eth::MacAddr+),
18
+ # * a target protocol address ({#tpa} or {#dst_ip}) field (+IP::Addr+),
19
+ # * and a {#body}.
20
+ #
21
+ # == Create a ARP header
22
+ # # standalone
23
+ # arp = PacketGen::Header::ARP.new
24
+ # # in a packet
25
+ # pkt = PacketGen.gen('Eth').add('ARP')
26
+ # # access to ARP header
27
+ # pkt.arp # => PacketGen::Header::ARP
28
+ #
5
29
  # @author Sylvain Daubert
6
- class ARP < Struct.new(:hw_type, :proto, :hw_len, :proto_len, :opcode,
7
- :src_mac, :src_ip, :dst_mac, :dst_ip, :body)
30
+ class ARP < Struct.new(:hrd, :pro, :hln, :pln, :op,
31
+ :sha, :spa, :tha, :tpa, :body)
8
32
  include StructFu
9
33
  include HeaderMethods
10
34
  extend HeaderClassMethods
11
35
 
12
36
  # @param [Hash] options
13
- # @option options [Integer] :hw_type network protocol type (default: 1)
14
- # @option options [Integer] :proto internet protocol type (default: 0x800)
15
- # @option options [Integer] :hw_len length of hardware addresses (default: 6)
16
- # @option options [Integer] :proto_len length of internet addresses (default: 4)
17
- # @option options [Integer] :opcode operation performing by sender (default: 1).
37
+ # @option options [Integer] :hrd network protocol type (default: 1)
38
+ # @option options [Integer] :pro internet protocol type (default: 0x800)
39
+ # @option options [Integer] :hln length of hardware addresses (default: 6)
40
+ # @option options [Integer] :pln length of internet addresses (default: 4)
41
+ # @option options [Integer] :op operation performing by sender (default: 1).
18
42
  # known values are +request+ (1) and +reply+ (2)
19
- # @option options [String] :src_mac sender hardware address
20
- # @option options [String] :src_ip sender internet address
21
- # @option options [String] :dst_mac target hardware address
22
- # @option options [String] :dst_ip targetr internet address
43
+ # @option options [String] :sha sender hardware address
44
+ # @option options [String] :spa sender internet address
45
+ # @option options [String] :tha target hardware address
46
+ # @option options [String] :tpa targetr internet address
23
47
  def initialize(options={})
24
- super Int16.new(options[:hw_type] || 1),
25
- Int16.new(options[:proto] || 0x800),
26
- Int8.new(options[:hw_len] || 6),
27
- Int8.new(options[:proto_len] || 4),
28
- Int16.new(options[:opcode] || 1),
29
- Eth::MacAddr.new.parse(options[:src_mac]),
30
- IP::Addr.new.parse(options[:src_ip]),
31
- Eth::MacAddr.new.parse(options[:dst_mac]),
32
- IP::Addr.new.parse(options[:dst_ip]),
48
+ super Int16.new(options[:hrd] || options[:htype] || 1),
49
+ Int16.new(options[:pro] || options[:ptype] || 0x800),
50
+ Int8.new(options[:hln] || options[:hlen] || 6),
51
+ Int8.new(options[:pln] || options[:plen] || 4),
52
+ Int16.new(options[:op] || options[:opcode] || 1),
53
+ Eth::MacAddr.new.from_human(options[:sha] || options[:src_mac]),
54
+ IP::Addr.new.from_human(options[:spa] || options[:src_ip]),
55
+ Eth::MacAddr.new.from_human(options[:tha] || options[:dst_mac]),
56
+ IP::Addr.new.from_human(options[:tpa] || options[:dst_ip]),
33
57
  StructFu::String.new.read(options[:body])
34
58
  end
35
59
 
@@ -39,110 +63,128 @@ module PacketGen
39
63
  def read(str)
40
64
  force_binary str
41
65
  raise ParseError, 'string too short for ARP' if str.size < self.sz
42
- self[:hw_type].read str[0, 2]
43
- self[:proto].read str[2, 2]
44
- self[:hw_len].read str[4, 1]
45
- self[:proto_len].read str[5, 1]
46
- self[:opcode].read str[6, 2]
47
- self[:src_mac].read str[8, 6]
48
- self[:src_ip].read str[14, 4]
49
- self[:dst_mac].read str[18, 6]
50
- self[:dst_ip].read str[24, 4]
66
+ self[:hrd].read str[0, 2]
67
+ self[:pro].read str[2, 2]
68
+ self[:hln].read str[4, 1]
69
+ self[:pln].read str[5, 1]
70
+ self[:op].read str[6, 2]
71
+ self[:sha].read str[8, 6]
72
+ self[:spa].read str[14, 4]
73
+ self[:tha].read str[18, 6]
74
+ self[:tpa].read str[24, 4]
51
75
  self[:body].read str[28..-1]
52
76
  end
53
77
 
54
- # @!attribute [rw] hw_type
78
+ # @!attribute [rw] hrd
55
79
  # @return [Integer]
56
- def hw_type
57
- self[:hw_type].to_i
80
+ def hrd
81
+ self[:hrd].to_i
58
82
  end
83
+ alias :htype :hrd
59
84
 
60
- def hw_type=(i)
61
- self[:hw_type].read i
85
+ def hrd=(i)
86
+ self[:hrd].read i
62
87
  end
88
+ alias :htype= :hrd=
63
89
 
64
- # @!attribute [rw] proto
90
+ # @!attribute [rw] pro
65
91
  # @return [Integer]
66
- def proto
67
- self[:proto].to_i
92
+ def pro
93
+ self[:pro].to_i
68
94
  end
95
+ alias :ptype :pro
69
96
 
70
- def proto=(i)
71
- self[:proto].read i
97
+ def pro=(i)
98
+ self[:pro].read i
72
99
  end
100
+ alias :ptype= :pro=
73
101
 
74
- # @!attribute [rw] hw_len
102
+ # @!attribute [rw] hln
75
103
  # @return [Integer]
76
- def hw_len
77
- self[:hw_len].to_i
104
+ def hln
105
+ self[:hln].to_i
78
106
  end
107
+ alias :hlen :hln
79
108
 
80
- def hw_len=(i)
81
- self[:hw_len].read i
109
+ def hln=(i)
110
+ self[:hln].read i
82
111
  end
112
+ alias :hlen= :hln=
83
113
 
84
- # @!attribute [rw] proto_len
114
+ # @!attribute [rw] pln
85
115
  # @return [Integer]
86
- def proto_len
87
- self[:proto_len].to_i
116
+ def pln
117
+ self[:pln].to_i
88
118
  end
119
+ alias :plen :pln
89
120
 
90
- def proto_len=(i)
91
- self[:proto_len].read i
121
+ def pln=(i)
122
+ self[:pln].read i
92
123
  end
124
+ alias :plen= :pln=
93
125
 
94
- # @!attribute [rw] opcode
126
+ # @!attribute [rw] op
95
127
  # @return [Integer]
96
- def opcode
97
- self[:opcode].to_i
128
+ def op
129
+ self[:op].to_i
98
130
  end
131
+ alias :opcode :op
99
132
 
100
- def opcode=(i)
101
- self[:opcode].read i
133
+ def op=(i)
134
+ self[:op].read i
102
135
  end
136
+ alias :opcode= :op=
103
137
 
104
- # @!attribute [rw] src_mac
138
+ # @!attribute [rw] sha
105
139
  # @return [String]
106
- def src_mac
107
- self[:src_mac].to_x
140
+ def sha
141
+ self[:sha].to_human
108
142
  end
143
+ alias :src_mac :sha
109
144
 
110
- def src_mac=(addr)
111
- self[:src_mac].parse addr
145
+ def sha=(addr)
146
+ self[:sha].from_human addr
112
147
  end
148
+ alias :src_mac= :sha=
113
149
 
114
- # @!attribute [rw] src_ip
150
+ # @!attribute [rw] spa
115
151
  # @return [String]
116
- def src_ip
117
- self[:src_ip].to_x
152
+ def spa
153
+ self[:spa].to_human
118
154
  end
155
+ alias :src_ip :spa
119
156
 
120
- def src_ip=(addr)
121
- self[:src_ip].parse addr
157
+ def spa=(addr)
158
+ self[:spa].from_human addr
122
159
  end
160
+ alias :src_ip= :spa=
123
161
 
124
- # @!attribute [rw] dst_mac
162
+ # @!attribute [rw] tha
125
163
  # @return [String]
126
- def dst_mac
127
- self[:dst_mac].to_x
164
+ def tha
165
+ self[:tha].to_human
128
166
  end
167
+ alias :dst_mac :tha
129
168
 
130
- def dst_mac=(addr)
131
- self[:dst_mac].parse addr
169
+ def tha=(addr)
170
+ self[:tha].from_human addr
132
171
  end
172
+ alias :dst_mac= :tha=
133
173
 
134
- # @!attribute [rw] dst_ip
174
+ # @!attribute [rw] tpa
135
175
  # @return [String]
136
- def dst_ip
137
- self[:dst_ip].to_x
176
+ def tpa
177
+ self[:tpa].to_human
138
178
  end
179
+ alias :dst_ip :tpa
139
180
 
140
- def dst_ip=(addr)
141
- self[:dst_ip].parse addr
181
+ def tpa=(addr)
182
+ self[:tpa].from_human addr
142
183
  end
184
+ alias :dst_ip= :tpa=
143
185
  end
144
186
 
145
- Eth.bind_header ARP, proto: 0x806
187
+ Eth.bind_header ARP, ethertype: 0x806
146
188
  end
147
189
  end
148
190
 
@@ -1,9 +1,34 @@
1
+ # This file is part of PacketGen
2
+ # See https://github.com/sdaubert/packetgen for more informations
3
+ # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
4
+ # This program is published under MIT license.
5
+
1
6
  module PacketGen
2
7
  module Header
3
8
 
4
- # Ethernet header class
9
+ # An Ethernet header consists of:
10
+ # * a destination MAC address ({MacAddr}),
11
+ # * a source MAC address (MacAddr),
12
+ # * a {#ethertype} ({Int16}),
13
+ # * and a body (a {String} or another Header class).
14
+ #
15
+ # == Create a Ethernet header
16
+ # # standalone
17
+ # eth = PacketGen::Header::Eth.new
18
+ # # in a packet
19
+ # pkt = PacketGen.gen('Eth')
20
+ # # access to Ethernet header
21
+ # pkt.eth # => PacketGen::Header::Eth
22
+ #
23
+ # == Ethernet attributes
24
+ # eth.dst = "00:01:02:03:04:05'
25
+ # eth.src # => "00:01:01:01:01:01"
26
+ # eth[:src] # => PacketGen::Header::Eth::MacAddr
27
+ # eth.ethertype # => 16-bit Integer
28
+ # eth.body = "This is a body"
29
+ #
5
30
  # @author Sylvain Daubert
6
- class Eth < Struct.new(:dst, :src, :proto, :body)
31
+ class Eth < Struct.new(:dst, :src, :ethertype, :body)
7
32
  include StructFu
8
33
  include HeaderMethods
9
34
  extend HeaderClassMethods
@@ -30,10 +55,10 @@ module PacketGen
30
55
 
31
56
  end
32
57
 
33
- # Parse a string to populate MacAddr
58
+ # Read a human-readable string to populate +MacAddr+
34
59
  # @param [String] str
35
60
  # @return [self]
36
- def parse(str)
61
+ def from_human(str)
37
62
  return self if str.nil?
38
63
  bytes = str.split(/:/)
39
64
  unless bytes.size == 6
@@ -48,7 +73,7 @@ module PacketGen
48
73
  self
49
74
  end
50
75
 
51
- # Read a MacAddr from a string
76
+ # Read a +MacAddr+ from a binary string
52
77
  # @param [String] str binary string
53
78
  # @return [self]
54
79
  def read(str)
@@ -65,9 +90,9 @@ module PacketGen
65
90
  "def #{sym}=(v); self[:#{sym}].read v; end"
66
91
  end
67
92
 
68
- # Addr in human readable form (dotted format)
93
+ # +MacAddr+ in human readable form (colon format)
69
94
  # @return [String]
70
- def to_x
95
+ def to_human
71
96
  members.map { |m| "#{'%02x' % self[m]}" }.join(':')
72
97
  end
73
98
  end
@@ -82,11 +107,11 @@ module PacketGen
82
107
  # @param [Hash] options
83
108
  # @option options [String] :dst MAC destination address
84
109
  # @option options [String] :src MAC source address
85
- # @option options [Integer] :proto
110
+ # @option options [Integer] :ethertype
86
111
  def initialize(options={})
87
- super MacAddr.new.parse(options[:dst] || '00:00:00:00:00:00'),
88
- MacAddr.new.parse(options[:src] || '00:00:00:00:00:00'),
89
- Int16.new(options[:proto] || 0),
112
+ super MacAddr.new.from_human(options[:dst] || '00:00:00:00:00:00'),
113
+ MacAddr.new.from_human(options[:src] || '00:00:00:00:00:00'),
114
+ Int16.new(options[:ethertype] || 0),
90
115
  StructFu::String.new.read(options[:body])
91
116
  end
92
117
 
@@ -99,7 +124,7 @@ module PacketGen
99
124
  force_binary str
100
125
  self[:dst].read str[0, 6]
101
126
  self[:src].read str[6, 6]
102
- self[:proto].read str[12, 2]
127
+ self[:ethertype].read str[12, 2]
103
128
  self[:body].read str[14..-1]
104
129
  self
105
130
  end
@@ -107,40 +132,40 @@ module PacketGen
107
132
  # Get MAC destination address
108
133
  # @return [String]
109
134
  def dst
110
- self[:dst].to_x
135
+ self[:dst].to_human
111
136
  end
112
137
 
113
138
  # Set MAC destination address
114
139
  # @param [String] addr
115
140
  # @return [String]
116
141
  def dst=(addr)
117
- self[:dst].parse addr
142
+ self[:dst].from_human addr
118
143
  end
119
144
 
120
145
  # Get MAC source address
121
146
  # @return [String]
122
147
  def src
123
- self[:src].to_x
148
+ self[:src].to_human
124
149
  end
125
150
 
126
151
  # Set MAC source address
127
152
  # @param [String] addr
128
153
  # @return [String]
129
154
  def src=(addr)
130
- self[:src].parse addr
155
+ self[:src].from_human addr
131
156
  end
132
157
 
133
- # Get protocol field
158
+ # Get ethertype field
134
159
  # @return [Integer]
135
- def proto
136
- self[:proto].to_i
160
+ def ethertype
161
+ self[:ethertype].to_i
137
162
  end
138
163
 
139
- # Set protocol field
140
- # @param [Integer] proto
164
+ # Set ethertype field
165
+ # @param [Integer] type
141
166
  # @return [Integer]
142
- def proto=(proto)
143
- self[:proto].value = proto
167
+ def ethertype=(type)
168
+ self[:ethertype].value = type
144
169
  end
145
170
 
146
171
  # send Eth packet on wire.
@@ -1,3 +1,8 @@
1
+ # This file is part of PacketGen
2
+ # See https://github.com/sdaubert/packetgen for more informations
3
+ # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
4
+ # This program is published under MIT license.
5
+
1
6
  module PacketGen
2
7
  module Header
3
8
 
@@ -22,7 +27,76 @@ module PacketGen
22
27
  def known_headers
23
28
  @known_headers ||= {}
24
29
  end
25
- end
26
30
 
31
+ # Define a bitfield on given attribute
32
+ # class MyHeader < Struct.new(:flags)
33
+ #
34
+ # def initialize(options={})
35
+ # super Int16.new(options[:flags])
36
+ # end
37
+ #
38
+ # # define a bit field on :flag attribute:
39
+ # # flag1, flag2 and flag3 are 1-bit fields
40
+ # # type and stype are 3-bit fields. reserved is a 6-bit field
41
+ # define_bit_fields_on :flags, :flag1, :flag2, :flag3, :type, 3, :stype, 3, :reserved: 6
42
+ # end
43
+ # A bitfield of size 1 bit defines 2 methods:
44
+ # * +#field?+ which returns a Boolean,
45
+ # * +#field=+ which takes and returns a Boolean.
46
+ # A bitfield of more bits defines 2 methods:
47
+ # * +#field+ which returns an Integer,
48
+ # * +#field=+ which takes and returns an Integer.
49
+ # @param [Symbol] attr attribute name (attribute should a {StructFu::Int}
50
+ # subclass)
51
+ # @param [Array] args list of bitfield names. Name may be followed
52
+ # by bitfield size. If no size is given, 1 bit is assumed.
53
+ # @return [void]
54
+ def define_bit_fields_on(attr, *args)
55
+ total_size = self.new[attr].width * 8
56
+ idx = total_size - 1
57
+
58
+ field = args.shift
59
+ while field
60
+ next unless field.is_a? Symbol
61
+ size = if args.first.is_a? Integer
62
+ args.shift
63
+ else
64
+ 1
65
+ end
66
+ unless field == :_
67
+ shift = idx - (size - 1)
68
+ field_mask = (2**size - 1) << shift
69
+ clear_mask = (2**total_size - 1) & (~field_mask & (2**total_size - 1))
70
+
71
+ if size == 1
72
+ class_eval <<-EOM
73
+ def #{field}?
74
+ val = (self[:#{attr}].to_i & #{field_mask}) >> #{shift}
75
+ val != 0
76
+ end
77
+ def #{field}=(v)
78
+ val = v ? 1 : 0
79
+ self[:#{attr}].value = self[:#{attr}].to_i & #{clear_mask}
80
+ self[:#{attr}].value |= val << #{shift}
81
+ end
82
+ EOM
83
+ else
84
+ class_eval <<-EOM
85
+ def #{field}
86
+ (self[:#{attr}].to_i & #{field_mask}) >> #{shift}
87
+ end
88
+ def #{field}=(v)
89
+ self[:#{attr}].value = self[:#{attr}].to_i & #{clear_mask}
90
+ self[:#{attr}].value |= (v & #{2**size - 1}) << #{shift}
91
+ end
92
+ EOM
93
+ end
94
+ end
95
+
96
+ idx -= size
97
+ field = args.shift
98
+ end
99
+ end
100
+ end
27
101
  end
28
102
  end
@@ -1,3 +1,8 @@
1
+ # This file is part of PacketGen
2
+ # See https://github.com/sdaubert/packetgen for more informations
3
+ # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
4
+ # This program is published under MIT license.
5
+
1
6
  module PacketGen
2
7
  module Header
3
8
 
@@ -46,6 +51,17 @@ module PacketGen
46
51
  raise FormatError, 'no IP or IPv6 header in packet' if iph.nil?
47
52
  iph
48
53
  end
54
+
55
+ # Common inspect method for headers
56
+ # @return [String]
57
+ def inspect
58
+ str = Inspect.dashed_line(self.class, 2)
59
+ to_h.each do |attr, value|
60
+ next if attr == :body
61
+ str << Inspect.inspect_attribute(attr, value, 2)
62
+ end
63
+ str
64
+ end
49
65
  end
50
66
  end
51
67
  end
@@ -1,9 +1,32 @@
1
+ # This file is part of PacketGen
2
+ # See https://github.com/sdaubert/packetgen for more informations
3
+ # Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
4
+ # This program is published under MIT license.
5
+
1
6
  module PacketGen
2
7
  module Header
3
8
 
4
- # ICMP header class
9
+ # A ICMP header consists of:
10
+ # * a {#type} field ({Int8} type),
11
+ # * a {#code} field ({Int8} type),
12
+ # * a {#checksum} field ({Int16} type),
13
+ # * and a {#body}.
14
+ #
15
+ # == Create a ICMP header
16
+ # # standalone
17
+ # icmp = PacketGen::Header::ICMP.new
18
+ # # in a packet
19
+ # pkt = PacketGen.gen('IP').add('ICMP')
20
+ # # access to ICMP header
21
+ # pkt.icmp # => PacketGen::Header::ICMP
22
+ #
23
+ # == ICMP attributes
24
+ # icmp.code = 0
25
+ # icmp.type = 200
26
+ # icmp.checksum = 0x248a
27
+ # icmp.body.read 'this is a body'
5
28
  # @author Sylvain Daubert
6
- class ICMP < Struct.new(:type, :code, :sum, :body)
29
+ class ICMP < Struct.new(:type, :code, :checksum, :body)
7
30
  include StructFu
8
31
  include HeaderMethods
9
32
  extend HeaderClassMethods
@@ -14,12 +37,12 @@ module PacketGen
14
37
  # @param [Hash] options
15
38
  # @option options [Integer] :type
16
39
  # @option options [Integer] :code
17
- # @option options [Integer] :sum
40
+ # @option options [Integer] :checksum
18
41
  # @option options [String] :body
19
42
  def initialize(options={})
20
43
  super Int8.new(options[:type]),
21
44
  Int8.new(options[:code]),
22
- Int16.new(options[:sum]),
45
+ Int16.new(options[:checksum]),
23
46
  StructFu::String.new.read(options[:body])
24
47
  end
25
48
 
@@ -28,17 +51,17 @@ module PacketGen
28
51
  # @return [self]
29
52
  def read(str)
30
53
  return self if str.nil?
31
- raise ParseError, 'string too short for Eth' if str.size < self.sz
54
+ raise ParseError, 'string too short for ICMP' if str.size < self.sz
32
55
  force_binary str
33
56
  self[:type].read str[0, 1]
34
57
  self[:code].read str[1, 1]
35
- self[:sum].read str[2, 2]
58
+ self[:checksum].read str[2, 2]
36
59
  self[:body].read str[4..-1]
37
60
  end
38
61
 
39
- # Compute checksum and set +sum+ field
62
+ # Compute checksum and set +checksum+ field
40
63
  # @return [Integer]
41
- def calc_sum
64
+ def calc_checksum
42
65
  sum = (type << 8) | code
43
66
 
44
67
  payload = body.to_s
@@ -49,7 +72,7 @@ module PacketGen
49
72
  sum = (sum & 0xffff) + (sum >> 16)
50
73
  end
51
74
  sum = ~sum & 0xffff
52
- self[:sum].value = (sum == 0) ? 0xffff : sum
75
+ self[:checksum].value = (sum == 0) ? 0xffff : sum
53
76
  end
54
77
 
55
78
  # Getter for type attribute
@@ -78,20 +101,20 @@ module PacketGen
78
101
  self[:code].value = code
79
102
  end
80
103
 
81
- # Getter for sum attribute
104
+ # Getter for checksum attribute
82
105
  # @return [Integer]
83
- def sum
84
- self[:sum].to_i
106
+ def checksum
107
+ self[:checksum].to_i
85
108
  end
86
109
 
87
- # Setter for sum attribute
110
+ # Setter for checksum attribute
88
111
  # @param [Integer] sum
89
112
  # @return [Integer]
90
- def sum=(sum)
91
- self[:sum].value = sum
113
+ def checksum=(sum)
114
+ self[:checksum].value = sum
92
115
  end
93
116
  end
94
117
 
95
- IP.bind_header ICMP, proto: ICMP::IP_PROTOCOL
118
+ IP.bind_header ICMP, protocol: ICMP::IP_PROTOCOL
96
119
  end
97
120
  end