route-cache.pl [Re: 2.0.30/31-2 bug: ICMP redirect...]

Ulrik Dickow (ukd@kampsax.dk)
Fri, 20 Jun 1997 22:11:44 +0200


#! /usr/bin/perl -w
# Author: Ulrik Dickow <ukd@kampsax.dk>, Feb & June 1997.
# Print the Linux kernel routing cache in a somewhat readable format,
# skipping blank lines and the direct host routes.
# This script will hopefully be obsoleted by the next release of net-tools
# (after net-tools-1.32-alpha).
#
use strict;

my $cache = "/proc/net/rt_cache";
my @fields;

open(CACHE, $cache) or die "Can't open $cache: $!";

while (<CACHE>) {
@fields = split;
next if $fields[1] eq $fields[2]; # Destination = Gateway
# Quick & dirty hack: just translate anything looking like a 32 bit hex
# number into dotted decimal notation (reverse byte order).
s/\b[0-9A-F]{8}\b/
sprintf "%d.%d.%d.%d", reverse unpack "C4", pack "H8", $& /eg;
# Only print the first 9 columns (up to & including MTU):
/(\S+\s+){8}\S+/ and print $& . "\n";
}