Class: HashiCorp::VagrantVMwareDesktop::Helper::RoutingTable
- Inherits:
-
Object
- Object
- HashiCorp::VagrantVMwareDesktop::Helper::RoutingTable
- Defined in:
- lib/vagrant-vmware-desktop/helper/routing_table.rb
Overview
This class reads the TCP/IP routing table for the current host. On Mac OS X and Linux machines, ‘netstat` is used. Windows is not currently implemented, but similar applications are installed by default.
Instance Method Summary collapse
-
#device_for_route(ip) ⇒ Object
This will return the device that the given IP would be routed to, or ‘nil` if it would just route to the default route.
-
#initialize ⇒ RoutingTable
constructor
A new instance of RoutingTable.
Constructor Details
#initialize ⇒ RoutingTable
Returns a new instance of RoutingTable.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vagrant-vmware-desktop/helper/routing_table.rb', line 20 def initialize if Vagrant::Util::Platform.darwin? @table = read_table_darwin elsif Vagrant::Util::Platform.linux? @table = read_table_linux elsif Vagrant::Util::Platform.windows? @table = read_table_windows else raise Errors::RoutingTableUnsupportedOS end end |
Instance Method Details
#device_for_route(ip) ⇒ Object
This will return the device that the given IP would be routed to, or ‘nil` if it would just route to the default route.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vagrant-vmware-desktop/helper/routing_table.rb', line 36 def device_for_route(ip) return @table[ip] if @table.has_key?(ip) smallest = nil smallest_size = nil @table.each do |destination, interface| if destination.include?(IPAddr.new(ip)) # Ruby 2.0 adds a "size" operator to Range, which we should # use when we switch to it. ip_range = destination.to_range ip_size = ip_range.max.to_i - ip_range.min.to_i if smallest_size.nil? || ip_size < smallest_size smallest = interface smallest_size = ip_size end end end smallest end |