Files
netlinkrb/examples/add_addr.rb

22 lines
689 B
Ruby
Raw Normal View History

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"
ip.addr.list(:index=>"lo", :family=>Socket::AF_INET) { |x| puts x.address }
2011-05-02 22:52:47 +01:00
puts "\n*** After adding address"
2011-05-02 22:52:47 +01:00
begin
ip.addr.add(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
2011-05-02 22:52:47 +01:00
rescue Errno::EEXIST
puts "Already exists"
2011-05-02 22:52:47 +01:00
end
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"
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