2011-05-02 22:52:47 +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-02 22:52:47 +01:00
|
|
|
|
2011-05-06 09:49:47 +01:00
|
|
|
ip = Linux::Netlink::Route::Socket.new
|
2011-05-02 22:52:47 +01:00
|
|
|
puts "\n*** Before adding address"
|
2011-05-03 19:13:37 +01:00
|
|
|
ip.addr.list(:index=>"lo", :family=>Socket::AF_INET) { |x| puts x.address }
|
2011-05-02 22:52:47 +01:00
|
|
|
|
2011-05-03 12:41:10 +01:00
|
|
|
puts "\n*** After adding address"
|
2011-05-02 22:52:47 +01:00
|
|
|
begin
|
2011-05-03 19:13:37 +01:00
|
|
|
ip.addr.add(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
2011-05-02 22:52:47 +01:00
|
|
|
rescue Errno::EEXIST
|
2011-05-03 12:41:10 +01:00
|
|
|
puts "Already exists"
|
2011-05-02 22:52:47 +01:00
|
|
|
end
|
2011-05-03 19:13:37 +01:00
|
|
|
ip.addr.list(:index=>"lo", :family=>Socket::AF_INET) { |x| puts x.address }
|
2011-05-02 22:52:47 +01:00
|
|
|
|
|
|
|
puts "\n*** After deleting address"
|
2011-05-03 19:13:37 +01:00
|
|
|
ip.addr.delete(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
|
|
|
ip.addr.list(:index=>"lo", :family=>Socket::AF_INET) { |x| puts x.address }
|
2011-05-02 22:52:47 +01:00
|
|
|
|