src/examples/simple_router/interface.rb in trema-0.4.5 vs src/examples/simple_router/interface.rb in trema-0.4.6
- old
+ new
@@ -15,83 +15,74 @@
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
+require 'arp-table'
+require 'routing-table'
-require "arp-table"
-require "routing-table"
+require 'pio'
-
class Interface
attr_reader :hwaddr
attr_reader :ipaddr
attr_reader :masklen
attr_reader :port
-
def initialize options
- @port = options[ :port ]
- @hwaddr = Mac.new( options[ :hwaddr ] )
- @ipaddr = IPAddr.new( options[ :ipaddr ] )
- @masklen = options[ :masklen ]
+ @port = options[:port]
+ @hwaddr = Pio::Mac.new(options[:hwaddr])
+ @ipaddr = Pio::IPv4Address.new(options[:ipaddr])
+ @masklen = options[:masklen]
end
-
def has? mac
mac == hwaddr
end
end
-
class Interfaces
def initialize interfaces = []
@list = []
- interfaces.each do | each |
- @list << Interface.new( each )
+ interfaces.each do |each|
+ @list << Interface.new(each)
end
end
-
def find_by_port port
- @list.find do | each |
+ @list.find do |each|
each.port == port
end
end
-
def find_by_ipaddr ipaddr
- @list.find do | each |
- each.ipaddr == ipaddr
+ @list.find do |each|
+ each.ipaddr.to_i == ipaddr.to_i
end
end
-
def find_by_prefix ipaddr
- @list.find do | each |
+ @list.find do |each|
masklen = each.masklen
- each.ipaddr.mask( masklen ) == ipaddr.mask( masklen )
+ each.ipaddr.mask(masklen).to_s == ipaddr.mask(masklen).to_s
end
end
-
def find_by_port_and_ipaddr port, ipaddr
- @list.find do | each |
- each.port == port and each.ipaddr == ipaddr
+ @list.find do |each|
+ each.port == port and each.ipaddr.to_i == ipaddr.to_i
end
end
-
def ours? port, macda
- return true if macda.broadcast?
+ true if macda.broadcast?
- interface = find_by_port( port )
- if not interface.nil? and interface.has?( macda )
- return true
+ interface = find_by_port(port)
+ if not interface.nil? and interface.has?(macda)
+ true
end
end
end
-
### Local variables:
### mode: Ruby
### coding: utf-8
### indent-tabs-mode: nil