Class: Arpoon::Route

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/arpoon/route.rb

Defined Under Namespace

Classes: Entry

Constant Summary collapse

Flags =
Bitmap.new(
  up:      0x0001,
  gateway: 0x0002,

  host:         0x0004,
  reinstate:    0x0008,
  dynamic:      0x0010,
  modified:     0x0020,
  mtu:          0x0040,
  window:       0x0080,
  irtt:         0x0100,
  reject:       0x0200,
  static:       0x0400,
  xresolve:     0x0800,
  no_forward:   0x1000,
  throw:        0x2000,
  no_pmt_udisc: 0x4000,

  default:     0x00010000,
  all_on_link: 0x00020000,
  addrconf:    0x00040000,

  linkrt:      0x00100000,
  no_next_hop: 0x00200000,

  cache:  0x01000000,
  flow:   0x02000000,
  policy: 0x0400000
)

Instance Method Summary collapse

Constructor Details

#initializeRoute

Returns a new instance of Route.



96
97
98
99
100
101
102
103
104
# File 'lib/arpoon/route.rb', line 96

def initialize
  @entries = []

  File.open('/proc/net/route', 'r').each_line {|line|
    next if line.start_with? 'Iface'

    @entries << Entry.new(*line.split(/\s+/))
  }
end

Instance Method Details

#each(device = nil) ⇒ Object



106
107
108
109
110
111
112
113
114
# File 'lib/arpoon/route.rb', line 106

def each (device = nil)
  return enum_for :each, device unless block_given?

  @entries.each {|entry|
    yield entry if !device || device.to_s == entry.device
  }

  self
end

#gateway_for(device) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/arpoon/route.rb', line 116

def gateway_for (device)
  each(device) {|entry|
    return entry.gateway if entry.gateway?
  }

  nil
end