: run this script through /bin/sh
agent= community= dest= flags=
-*) echo "$A: unknown flag" 1>&2
*) if [ "x$dest" = "x" ]; then
elif [ "x$community" = "x" ]; then
community="-v COMMUNITY=$A"
elif [ "x$agent" = "x" ]; then
echo "usage: s-traceroute [switches] destination [community [agent]]" 1>&2
if [ "x$dest" = "x" ]; then
echo "no destination specified" 1>&2
exec gawk $flags $agent $community $dest '
printf "from %s to %s:\n", AGENT, DEST;
net = dest[1] "." dest[2];
net = dest[1] "." dest[2] "." dest[3];
for (i in ipRouteMask, net) {
if ((type = ipRouteType) == INVALID)
split(ipRouteMask, mask, ".");
mask = bit_and(dest[1],mask[1]) "." \
bit_and(dest[2],mask[2]) "." \
bit_and(dest[3],mask[3]) "." \
bit_and(dest[4],mask[4]);
if (mask == ipRouteDest) {
if ((hop = ipRouteNextHop[addr = DEST]) \
&& (type = ipRouteType[addr]) == INVALID)
&& (hop = ipRouteNextHop[addr = net]) \
&& (type = ipRouteType[addr]) == INVALID)
if (!hop && (hop = ipRouteNextHop[addr = "0.0.0.0"])) {
if ((type = ipRouteType[addr]) == INVALID)
printf " via %-15s metric %2d%s\n",
hop, ipRouteMetric1[addr],
dr ? " (default route)" : "";
printf "\nno path to %s from %s\n%s\n",
printf "\tdirect route.\n";
printf "\nrouting loop!\n";