Class: PacketGen::Config
- Inherits:
-
Object
- Object
- PacketGen::Config
- Defined in:
- lib/packetgen/config.rb
Overview
Config class to provide config object to pgconsole
Instance Attribute Summary collapse
-
#hwaddr ⇒ String
readonly
MAC address of default interface.
-
#iface ⇒ String
readonly
Default network interface.
-
#ip6addr ⇒ String
readonly
IPv6 address of default interface.
-
#ipaddr ⇒ String
readonly
IP address of default interface.
Instance Method Summary collapse
-
#initialize(iface = nil) ⇒ Config
constructor
Create a configuration object.
Constructor Details
#initialize(iface = nil) ⇒ Config
Create a configuration object. If iface is not set, attempt to find it automatically or default to the first available loopback interface.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/packetgen/config.rb', line 28 def initialize(iface=nil) if iface.nil? begin iface = Pcap.lookupdev rescue PCAPRUB::BindingError iface = NetworkInterface.interfaces.select { |iface| iface =~ /lo/ }.first end end @iface = iface addresses = NetworkInterface.addresses(iface) @hwaddr = case RbConfig::CONFIG['target_os'] when /darwin/ addresses[Socket::AF_LINK][0]['addr'] if addresses[Socket::AF_LINK] else addresses[Socket::AF_PACKET][0]['addr'] if addresses[Socket::AF_PACKET] end @ipaddr = addresses[Socket::AF_INET][0]['addr'] if addresses[Socket::AF_INET] @ip6addr = addresses[Socket::AF_INET6][0]['addr'] if addresses[Socket::AF_INET6] end |
Instance Attribute Details
#hwaddr ⇒ String (readonly)
MAC address of default interface
16 17 18 |
# File 'lib/packetgen/config.rb', line 16 def hwaddr @hwaddr end |
#iface ⇒ String (readonly)
Default network interface
13 14 15 |
# File 'lib/packetgen/config.rb', line 13 def iface @iface end |
#ip6addr ⇒ String (readonly)
IPv6 address of default interface
22 23 24 |
# File 'lib/packetgen/config.rb', line 22 def ip6addr @ip6addr end |
#ipaddr ⇒ String (readonly)
IP address of default interface
19 20 21 |
# File 'lib/packetgen/config.rb', line 19 def ipaddr @ipaddr end |