Subject: route(8) doesn't always exit(1) on an error
To: None <tech-net@netbsd.org>
From: Tad Hunt <tad@entrisphere.com>
List: tech-net
Date: 11/15/2001 13:00:22
I want to use the route(8) (or an equivalent command) invoked from
a program that adds and removes static routes. I had been intending
to look at the route(8) exit(2) value from the my program to
determine if the route was successfully added or not. However, it
seems as though short of getting the arguments wrong and exiting
with a usage error, route(8) always exits 0 (via a return 0 in
main())
Is there a workaround for this behavior so I can invoke add and
remove static routes from my program? I would prefer *not* doing
a popen(3), and reading the route(8) output.
Thanks,
-Tad
For example, I add a route through gw 192.168.168.4:
# route add -net 192.168.1.0 192.168.168.4
add net 192.168.1.0: gateway 192.168.168.4
Then I try to add the same destination via different (192.168.168.5) gw:
# if route add -net 192.168.1.0 192.168.168.5 ; then
> echo route add ok
> else
> echo route add failed
> fi
writing to routing socket: File exists
add net 192.168.1.0: gateway 192.168.168.5: Bad file descriptor
route add ok
The shell script thinks route added the route successfully, but further
examination of the routing table shows that not to be true:
# route show
Routing tables
Internet:
Destination Gateway Flags
default 192.168.168.3 UG
192.168.1.0 192.168.168.4 UG
192.168.168.0 link#1 U
192.168.168.3 link#1 UH
192.168.168.4 0:b0:d0:b0:1:fa UH
192.168.168.5 link#1 UH
192.168.168.18 0:b0:d0:ab:1a:30 UH
192.168.168.142 0:19:22:33:48:63 UH
#