Basic interface address manipulation
This commit is contained in:
20
examples/add_addr.rb
Normal file
20
examples/add_addr.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
LIBDIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
||||
$LOAD_PATH.unshift LIBDIR
|
||||
|
||||
require 'netlink/route'
|
||||
|
||||
nl = Netlink::Route::Socket.new
|
||||
puts "\n*** Before adding address"
|
||||
nl.addrs["lo"][Socket::AF_INET].each { |x| puts x.address }
|
||||
|
||||
begin
|
||||
nl.add_addr(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
||||
rescue Errno::EEXIST
|
||||
end
|
||||
puts "\n*** After adding address"
|
||||
nl.addrs["lo"][Socket::AF_INET].each { |x| puts x.address }
|
||||
|
||||
nl.delete_addr(:index=>"lo", :local=>"1.2.3.4", :prefixlen=>32)
|
||||
puts "\n*** After deleting address"
|
||||
nl.addrs["lo"][Socket::AF_INET].each { |x| puts x.address }
|
||||
|
Reference in New Issue
Block a user