Class: EthernetAdapter

Inherits:
NetworkAdapter show all
Defined in:
lib/ifconfig/common/interface_types.rb,
lib/ifconfig/bsd/interface_types.rb,
lib/ifconfig/linux/interface_types.rb,
lib/ifconfig/sunos/interface_types.rb

Overview

each platform defines it’s own set_mac function to get the mac address

Instance Attribute Summary collapse

Attributes inherited from NetworkAdapter

#flags, #mtu, #name, #rx, #status, #tx

Instance Method Summary collapse

Methods inherited from NetworkAdapter

#add_network, #addr_types, #addresses, #addrs_with_type, #array_to_hash_elem, #has_addr?, #ifacetype, #parse_activity, #parse_flags, #parse_ifconfig, #up?

Constructor Details

#initialize(name, ifconfigtxt) ⇒ EthernetAdapter

Returns a new instance of EthernetAdapter.



106
107
108
109
# File 'lib/ifconfig/common/interface_types.rb', line 106

def initialize(name,ifconfigtxt)
  super(name,ifconfigtxt)
  @mac = set_mac
end

Instance Attribute Details

#interruptObject (readonly)

Returns the value of attribute interrupt.



111
112
113
# File 'lib/ifconfig/common/interface_types.rb', line 111

def interrupt
  @interrupt
end

#macObject (readonly)

Returns the value of attribute mac.



111
112
113
# File 'lib/ifconfig/common/interface_types.rb', line 111

def mac
  @mac
end

#rxbytesObject (readonly)

Returns the value of attribute rxbytes.



111
112
113
# File 'lib/ifconfig/common/interface_types.rb', line 111

def rxbytes
  @rxbytes
end

#rxpacketsObject (readonly)

Returns the value of attribute rxpackets.



111
112
113
# File 'lib/ifconfig/common/interface_types.rb', line 111

def rxpackets
  @rxpackets
end

#txbytesObject (readonly)

Returns the value of attribute txbytes.



111
112
113
# File 'lib/ifconfig/common/interface_types.rb', line 111

def txbytes
  @txbytes
end

#txpacketsObject (readonly)

Returns the value of attribute txpackets.



111
112
113
# File 'lib/ifconfig/common/interface_types.rb', line 111

def txpackets
  @txpackets
end

Instance Method Details

#set_macObject



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ifconfig/bsd/interface_types.rb', line 58

def set_mac
  begin
    match=@ifconfig.match(/\s+ether\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5})/im)
    return match[1] unless match.nil?
    # Openbsd
    match = @ifconfig.match(/\s+address\:\s+([a-f\d]{1,2}(?:\:[a-f\d]{1,2}){5})/im)
    return match[1] unless match.nil?
  rescue NoMethodError
    puts "Couldn't Parse MAC Address for: "+@name
  end
end

#to_sObject



114
115
116
# File 'lib/ifconfig/common/interface_types.rb', line 114

def to_s
  super + "\n MAC: #{@mac}"
end