zer0stimulus
zer0stimulus

Reputation: 23606

API for querying routing table entry to reach specified destination

Does an API exist to retrieve which routing table entry the OS will use to send a packet to a specified destination (IP address)? This API must be able to traverse relationships between multiple routing tables (specified by ip rules).

Upvotes: 4

Views: 321

Answers (2)

Some programmer dude
Some programmer dude

Reputation: 409176

There is no guarantee that a route is static. If, for example, you ping a host halfway across the world, one ping may travel one route, and the next ping may travel a completely different route. Even if you do like traceroute (start with a TTL of 0 and increasing by one for each answer), there is no guarantee that the route will not change from one packet to the next.

The reason is simply that you can not know what happens with the communication between two routers anywhere from you to your destination. A router may answer one time, but a second later may have a power outage, or the cable may be cut, or any other reason a network can be disabled (my favorite is cleaners pulling plugs because they need the outlet for their vacuum.)

Upvotes: 1

Sushant Sharma
Sushant Sharma

Reputation: 447

A general purpose OS will always forward the packets to the router to which it is connected. However, if the OS is a router-OS (e.g., IOS, JunOS, etc) it is going to perform a lookup in the routing table (among other things) to determine the next hop. Packets usually originate from an end-host, and then go via a series of routers, finally ending up at the other end-point.

I think you are looking for something like traceroute, that can tell you the route that the packet is going to take.

Upvotes: 0

Related Questions