Restructure so messages and code specific to NETLINK_ROUTE are in one file

This commit is contained in:
Brian Candler
2011-04-30 22:39:25 +01:00
parent 3d4be4cd58
commit 8f453c5dc9
6 changed files with 391 additions and 346 deletions

16
examples/route_hi.rb Normal file
View File

@@ -0,0 +1,16 @@
LIBDIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift LIBDIR
require 'pp'
require 'netlink/route'
# Example of use of high-level API for NETLINK_ROUTE socket.
# The data is memoized - that is, it's downloaded from the kernel once
# and then manipulated internally.
nl = Netlink::RTSocket.new
pp nl.link["eth0"]
pp nl.addrs["eth0"]
# Find the route with the shortest prefix len (probably default route)
pp nl.routes[Socket::AF_INET].min_by { |route| route.dst_len }

16
examples/route_lo.rb Normal file
View File

@@ -0,0 +1,16 @@
LIBDIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift LIBDIR
require 'pp'
require 'netlink/route'
# Example of use of low-level API for NETLINK_ROUTE socket.
# Each of these method calls performs a netlink protocol exchange.
nl = Netlink::RTSocket.new
puts "*** links ***"
pp nl.read_links
puts "*** addrs ***"
pp nl.read_addrs(:family => Socket::AF_INET)
puts "*** routes ***"
pp nl.read_routes(:family => Socket::AF_INET)