2011-05-03 15:59:07 +01:00
|
|
|
LIBDIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
|
|
$LOAD_PATH.unshift LIBDIR
|
|
|
|
|
2011-05-06 09:49:47 +01:00
|
|
|
require 'linux/netlink/route'
|
2011-05-03 15:59:07 +01:00
|
|
|
|
2011-05-06 09:49:47 +01:00
|
|
|
ip = Linux::Netlink::Route::Socket.new
|
2011-05-03 15:59:07 +01:00
|
|
|
puts "\n*** Before adding route"
|
2011-05-06 09:49:47 +01:00
|
|
|
ip.route.list(:family=>Socket::AF_INET, :table=>Linux::RT_TABLE_MAIN) { |x| p x }
|
2011-05-03 15:59:07 +01:00
|
|
|
|
|
|
|
puts "\n*** After adding route"
|
|
|
|
begin
|
2011-05-03 19:13:37 +01:00
|
|
|
ip.route.add(:oif=>"lo", :dst=>"1.2.3.4", :dst_len=>32, :gateway=>"127.0.0.1")
|
2011-05-03 15:59:07 +01:00
|
|
|
rescue Errno::EEXIST
|
|
|
|
puts "Already exists"
|
|
|
|
end
|
2011-05-06 09:49:47 +01:00
|
|
|
ip.route.list(:family=>Socket::AF_INET, :table=>Linux::RT_TABLE_MAIN) { |x| p x }
|
2011-05-03 15:59:07 +01:00
|
|
|
|
|
|
|
puts "\n*** After deleting route"
|
2011-05-03 19:13:37 +01:00
|
|
|
ip.route.delete(:oif=>"lo", :dst=>"1.2.3.4", :dst_len=>32, :gateway=>"127.0.0.1")
|
2011-05-06 09:49:47 +01:00
|
|
|
ip.route.list(:family=>Socket::AF_INET, :table=>Linux::RT_TABLE_MAIN) { |x| p x }
|
2011-05-03 15:59:07 +01:00
|
|
|
|