#!/bin/sh

if [ $# -gt 0 ]; then
	echo "This command is provided for display compatablity only."
	echo "Please use the \"ip\" command for all other functionality."
	exit 1
fi

warn_compat() {
	cat >&2 <<EOF

*WARNING* This command is deprecated.
Please use "ip route" instead.

EOF
}
warn_compat

echo "Kernel IP routing table"
echo -e "Destination\tGateway\t\tGenmask\t\tFlags\tMetric\tRef\tUse\tIface"
ip route | while read a b c d e f g 
do
	destination=$a
	if [ $destination == "default" ]; then 
		destination="$destination\t"
		gw=$c
		flags="UG"
	elif [ "$b" = "via" ]
	then
		gw=$c
		flags="UG"
	else
		gw="*\t"
		flags="U"
	fi

	if [ $(echo $a | grep "/" ) ]; then
		destination=$(echo $a | sed 's,/.*,,')
		msk=$(echo $a | sed 's,^.*/,,')
		case $msk in
		"8")  msk="255.0.0.0";;
		"9")  msk="255.128.0.0";;
		"16") msk="255.255.0.0";;
		"17") msk="255.255.128.0";;
		"18") msk="255.255.192.0";;
		"19") msk="255.255.224.0";;
		"20") msk="255.255.240.0";;
		"21") msk="255.255.248.0";;
		"22") msk="255.255.252.0";;
		"23") msk="255.255.254.0";;
		"24") msk="255.255.255.0";;
		*) msk="\t";;
		esac
	else
		msk="\t"
	fi

	
	metric=0
	ref=0
	use=0

	[ $b == "dev" ] && dev=$c
	[ $c == "dev" ] && dev=$d
	[ $d == "dev" ] && dev=$e


	echo -e "$destination\t$gw\t$msk\t$flags\t$metric\t$ref\t$use\t$dev"

done

warn_compat
