1#!/bin/sh
2#$Id$
3
4#
5# Script created by: Stephen R. van den Berg <srb@cuci.nl>, 1999/04/18
6# Donated to the public domain.
7#
8# This script transforms the output of "ip" into more readable text.
9# "ip" is the Linux-advanced-routing configuration tool part of the
10# iproute package.
11#
12
13test "X-h" = "X$1" && echo "Usage: $0 [tablenr [raw ip args...]]" && exit 64
14
15test -z "$*" && set 0
16
17ip route list table "$@" |
18 while read network rest
19 do set xx $rest
20    shift
21    proto=""
22    via=""
23    dev=""
24    scope=""
25    src=""
26    table=""
27    case $network in
28       broadcast|local|unreachable) via=$network
29          network=$1
30          shift
31          ;;
32    esac
33    while test $# != 0
34    do
35       key=$1
36       val=$2
37       eval "$key=$val"
38       shift 2
39    done
40    echo "$network	$via	$src	$proto	$scope	$dev	$table"
41 done | awk -F '	' '
42BEGIN {
43   format="%15s%-3s %15s %15s %8s %8s%7s %s\n";
44   printf(format,"target","","gateway","source","proto","scope","dev","tbl");
45 }
46 { network=$1;
47   mask="";
48   if(match(network,"/"))
49    { mask=" "substr(network,RSTART+1);
50      network=substr(network,0,RSTART);
51    }
52   via=$2;
53   src=$3;
54   proto=$4;
55   scope=$5;
56   dev=$6;
57   table=$7;
58   printf(format,network,mask,via,src,proto,scope,dev,table);
59 }
60'
61