osdl.org!shemminger | aba5acd | 2004-04-15 20:56:59 +0000 | [diff] [blame] | 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 | |
| 13 | test "X-h" = "X$1" && echo "Usage: $0 [tablenr [raw ip args...]]" && exit 64 |
| 14 | |
| 15 | test -z "$*" && set 0 |
| 16 | |
| 17 | ip 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 ' ' ' |
| 42 | BEGIN { |
| 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 | ' |