Class: Netfilter::InterfaceTable
- Inherits:
-
Object
- Object
- Netfilter::InterfaceTable
- Defined in:
- lib/nfnetlink.rb
Overview
Class representing the table of interfaces.
Constant Summary collapse
- IFNAMSIZ =
16
- IFFLAGS =
{ (1 << 0) => :UP, (1 << 1) => :BROADCAST, (1 << 2) => :DEBUG, (1 << 3) => :LOOPBACK, (1 << 4) => :POINTTOPOINT, (1 << 5) => :NOTRAILERS, (1 << 6) => :RUNNING, (1 << 7) => :NOARP, (1 << 8) => :PROMISC, (1 << 9) => :ALLMULTI, (1 << 10) => :MASTER, (1 << 11) => :SLAVE, (1 << 12) => :MULTICAST, (1 << 13) => :PORTSEL, (1 << 14) => :AUTOMEDIA, (1 << 15) => :DYNAMIC, (1 << 16) => :LOWER_UP, (1 << 17) => :DORMANT, (1 << 18) => :ECHO, }
Instance Method Summary collapse
-
#[](index) ⇒ Object
Gets an interface by index.
-
#each ⇒ Object
Enumerator for the list of interfaces.
-
#initialize ⇒ InterfaceTable
constructor
A new instance of InterfaceTable.
Constructor Details
#initialize ⇒ InterfaceTable
Returns a new instance of InterfaceTable.
89 90 91 92 93 94 95 96 |
# File 'lib/nfnetlink.rb', line 89 def initialize @lock = Mutex.new @nlif_handle = Netlink.nlif_open raise NetlinkError, "nlif_open has failed" if @nlif_handle.null? query_table ObjectSpace.define_finalizer(self, proc { Netlink.nlif_close(@nlif_handle) }) end |
Instance Method Details
#[](index) ⇒ Object
Gets an interface by index. Return value is a Hash with attributes :name and :flags. Returns nil if interface does not exist.
103 104 105 106 107 108 |
# File 'lib/nfnetlink.rb', line 103 def [](index) @lock.synchronize { update_table get_iface(index) } end |
#each ⇒ Object
Enumerator for the list of interfaces.
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/nfnetlink.rb', line 113 def each @lock.synchronize { update_table for index in 1..65535 iface = get_iface(index) next if iface.nil? yield(iface) end } end |