Get default route

Thomas Graf tgraf at
Wed Oct 13 08:02:39 EDT 2010

On Wed, Jun 16, 2010 at 04:52:06PM +0300, alexfilth186 at wrote:
> I am writing app with libnl (Ubuntu 10.04, libnl 1.1.5).
> I need to get default route from route table. 
> There is my code:

>     //rtnl_route_set_dst(route, src_addr); // <--- this line
>     nl_cache_foreach_filter(route_cache, (struct nl_object *)route, hword, NULL);
> If line rtnl_route_set_dst(route, src_addr); commented, callback function hword called one time and obtained data was default gateway.
> When I uncommented this line - no matches found.  
> There is part of route table:
> Destination Gateway Genmask Flags Metric Ref Use Iface
>         UG    0      0        0 eth0
> Is there another way to get default route?

The default route is identified by a address length of zero. Creating
a zero length nl_addr as filter for dst should work.

More information about the libnl mailing list