Getting egress interface by destination IP in VxWorks 5.x
- At February 17, 2011
- By Eran Duchan
- In VxWorks
0
Here’s a small code snippet that may be useful to the 20 or so VxWorks programmers left on the planet. I thought this would be much easier than it turned out to be, but after gathering code examples from here and there in the VxWorks source tree, I was able to query the routing table as to which interface is used for a certain egress IP address.
VxWorks 5.x doesn’t really have a “user” and “kernel” space, so you’re kind of inclined to directly access the routing table (like how routeShow does it) should you need routing information. Looking at the code for rtalloc, rtalloc1 and ipRouteGet shows that this is a recipe for pain. Since a lot of BSD code found its way into the VxWorks networking stack, you can use standard route sockets to get routing information from your application, without worrying about tripping over locks and such.
In the attached example, I have a routine to get the egress interface by destination IP address. I only look at the interface information in the response, but this should serve as a good example as to how to get more information from the routing table.
You can download the code here.

