Class: PacketFu::NDPHeader
- Inherits:
-
Struct
- Object
- Struct
- PacketFu::NDPHeader
- Includes:
- StructFu
- Defined in:
- lib/bettercap/monkey/packetfu/utils.rb
Constant Summary collapse
- PROTOCOL_NUMBER =
58
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#ndp_code ⇒ Object
Getter for the code.
-
#ndp_lla ⇒ Object
Getter for the link local address.
-
#ndp_opt_len ⇒ Object
Getter for the options length.
-
#ndp_opt_type ⇒ Object
Getter for the options type field.
-
#ndp_reserved ⇒ Object
Getter for the reserved.
-
#ndp_sum ⇒ Object
Getter for the checksum.
-
#ndp_tgt ⇒ Object
Getter for the target address.
-
#ndp_type ⇒ Object
Getter for the type.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ NDPHeader
constructor
A new instance of NDPHeader.
-
#ndp_lladdr ⇒ Object
(also: #ndp_lla_readable)
Gets the link local address in a more readable way.
-
#ndp_lladdr=(mac) ⇒ Object
Sets the link local address in a more readable way.
-
#ndp_set_flags=(bits) ⇒ Object
Set flag bits (First three are flag bits, the rest are reserved).
- #ndp_sum_readable ⇒ Object
-
#ndp_taddr ⇒ Object
(also: #ndp_tgt_readable)
Get target address in a more readable form.
-
#ndp_taddr=(str) ⇒ Object
Set the target address in a more readable form.
-
#read(str) ⇒ Object
Reads a string to populate the object.
-
#to_s ⇒ Object
Returns the object in string form.
Constructor Details
#initialize(args = {}) ⇒ NDPHeader
Returns a new instance of NDPHeader.
218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 218 def initialize(args={}) super( Int8.new(args[:ndp_type]), Int8.new(args[:ndp_code]), Int16.new(args[:ndp_sum]), Int32.new(args[:ndp_reserved]), AddrIpv6.new.read(args[:ndp_tgt] || ("\x00" * 16)), Int8.new(args[:ndp_opt_type]), Int8.new(args[:ndp_opt_len]), EthMac.new.read(args[:ndp_lla]) ) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
211 212 213 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 211 def body @body end |
#ndp_code ⇒ Object
Getter for the code.
258 259 260 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 258 def ndp_code @ndp_code end |
#ndp_lla ⇒ Object
Getter for the link local address.
283 284 285 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 283 def ndp_lla @ndp_lla end |
#ndp_opt_len ⇒ Object
Getter for the options length.
279 280 281 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 279 def ndp_opt_len @ndp_opt_len end |
#ndp_opt_type ⇒ Object
Getter for the options type field.
275 276 277 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 275 def ndp_opt_type @ndp_opt_type end |
#ndp_reserved ⇒ Object
Getter for the reserved.
267 268 269 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 267 def ndp_reserved @ndp_reserved end |
#ndp_sum ⇒ Object
Getter for the checksum.
263 264 265 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 263 def ndp_sum @ndp_sum end |
#ndp_tgt ⇒ Object
Getter for the target address.
271 272 273 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 271 def ndp_tgt @ndp_tgt end |
#ndp_type ⇒ Object
Getter for the type.
254 255 256 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 254 def ndp_type @ndp_type end |
Instance Method Details
#ndp_lladdr ⇒ Object Also known as: ndp_lla_readable
Gets the link local address in a more readable way.
303 304 305 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 303 def ndp_lladdr EthHeader.str2mac(self[:ndp_lla].to_s) end |
#ndp_lladdr=(mac) ⇒ Object
Sets the link local address in a more readable way.
296 297 298 299 300 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 296 def ndp_lladdr=(mac) mac = EthHeader.mac2str(mac) self[:ndp_lla].read mac self[:ndp_lla] end |
#ndp_set_flags=(bits) ⇒ Object
Set flag bits (First three are flag bits, the rest are reserved).
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 312 def ndp_set_flags=(bits) case bits when "000" self.ndp_reserved = 0x00000000 when "001" self.ndp_reserved = 0x20000000 when "010" self.ndp_reserved = 0x40000000 when "011" self.ndp_reserved = 0x60000000 when "100" self.ndp_reserved = 0x80000000 when "101" self.ndp_reserved = 0xa0000000 when "110" self.ndp_reserved = 0xc0000000 when "111" self.ndp_reserved = 0xe0000000 end end |
#ndp_sum_readable ⇒ Object
307 308 309 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 307 def ndp_sum_readable "0x%04x" % ndp_sum end |
#ndp_taddr ⇒ Object Also known as: ndp_tgt_readable
Get target address in a more readable form.
286 287 288 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 286 def ndp_taddr self[:ndp_tgt].to_x end |
#ndp_taddr=(str) ⇒ Object
Set the target address in a more readable form.
291 292 293 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 291 def ndp_taddr=(str) self[:ndp_tgt].read_x(str) end |
#read(str) ⇒ Object
Reads a string to populate the object.
237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 237 def read(str) force_binary(str) return self if str.nil? self[:ndp_type].read(str[0,1]) self[:ndp_code].read(str[1,1]) self[:ndp_sum].read(str[2,2]) self[:ndp_reserved].read(str[4,4]) self[:ndp_tgt].read(str[8,16]) self[:ndp_opt_type].read(str[24,1]) self[:ndp_opt_len].read(str[25,1]) self[:ndp_lla].read(str[26,2]) self end |
#to_s ⇒ Object
Returns the object in string form.
232 233 234 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 232 def to_s self.to_a.map {|x| x.to_s}.join end |