RET=""
case $1 in
- dev) RET=`route -n | \
- awk 'BEGIN {m = 2^32}
- /^0.0.0.0\b/{if ($5 < m) {r = $8; m = $5}}
- END {print r}'`
- addr) RET=`route -n | \
- awk 'BEGIN {m = 2^32}
- /^0.0.0.0\b/{if ($5 < m) {r = $2; m = $5}}
- END {print r}'`
- *) echo "cp_get_ifdefault: Argument required (dev or addr)" >&2 ;;
+ dev)
+ RET=`route -n | awk 'BEGIN {m = 2^32}
+ /^0\.0\.0\.0[ \t]/ {if ($5 < m) {r = $8; m = $5}}
+ END {print r}'`
+ ;;
+ addr)
+ RET=`route -n | awk 'BEGIN {m = 2^32}
+ /^0\.0\.0\.0[ \t]/ {if ($5 < m) {r = $2; m = $5}}
+ END {print r}'`
+ ;;
+ *)
+ echo "cp_get_ifdefault: Argument required (dev or addr)" >&2
+ ;;
esac
[ -z "$RET" -a "$1" ] && echo "cp_get_ifdefault: No default route" >&2