Class: PacketFu::EthNic

Inherits:
Struct
  • Object
show all
Defined in:
lib/packetfu/protos/eth/header.rb

Overview

EthNic is the Network Interface Controler portion of a MAC address, used in EthHeader.

Header Definition

Integer:n1
Integer:n2
Integer:n3

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Struct

#force_binary

Constructor Details

#initialize(args = {}) ⇒ EthNic

EthNic does not enjoy StructFu typing.



78
79
80
81
# File 'lib/packetfu/protos/eth/header.rb', line 78

def initialize(args={})
  args.each_pair {|k,v| args[k] = 0 unless v}
  super(args[:n0], args[:n1], args[:n2])
end

Instance Attribute Details

#n0Object

Returns the value of attribute n0

Returns:

  • (Object)

    the current value of n0



75
76
77
# File 'lib/packetfu/protos/eth/header.rb', line 75

def n0
  @n0
end

#n1Object

Returns the value of attribute n1

Returns:

  • (Object)

    the current value of n1



75
76
77
# File 'lib/packetfu/protos/eth/header.rb', line 75

def n1
  @n1
end

#n2Object

Returns the value of attribute n2

Returns:

  • (Object)

    the current value of n2



75
76
77
# File 'lib/packetfu/protos/eth/header.rb', line 75

def n2
  @n2
end

Instance Method Details

#read(str) ⇒ Object

Reads a string to populate the object.



89
90
91
92
93
94
# File 'lib/packetfu/protos/eth/header.rb', line 89

def read(str)
  force_binary(str)
  return self if str.nil?
  self[:n0], self[:n1], self[:n2] = str[0,3].unpack("C3")
  self
end

#to_sObject

Returns the object in string form.



84
85
86
# File 'lib/packetfu/protos/eth/header.rb', line 84

def to_s
  [n0,n1,n2].map {|x| x.to_i}.pack("C3")
end