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_mask, #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.



117
118
119
120
# File 'lib/ifconfig/common/interface_types.rb', line 117

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

Instance Attribute Details

#interruptObject (readonly)

Returns the value of attribute interrupt.



122
123
124
# File 'lib/ifconfig/common/interface_types.rb', line 122

def interrupt
  @interrupt
end

#macObject (readonly)

Returns the value of attribute mac.



122
123
124
# File 'lib/ifconfig/common/interface_types.rb', line 122

def mac
  @mac
end

#rxbytesObject (readonly)

Returns the value of attribute rxbytes.



122
123
124
# File 'lib/ifconfig/common/interface_types.rb', line 122

def rxbytes
  @rxbytes
end

#rxpacketsObject (readonly)

Returns the value of attribute rxpackets.



122
123
124
# File 'lib/ifconfig/common/interface_types.rb', line 122

def rxpackets
  @rxpackets
end

#txbytesObject (readonly)

Returns the value of attribute txbytes.



122
123
124
# File 'lib/ifconfig/common/interface_types.rb', line 122

def txbytes
  @txbytes
end

#txpacketsObject (readonly)

Returns the value of attribute txpackets.



122
123
124
# File 'lib/ifconfig/common/interface_types.rb', line 122

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



125
126
127
# File 'lib/ifconfig/common/interface_types.rb', line 125

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