2

I'm writing a program to find out which network interface is the best to connect to a specified target address.

Right now, I can get the route table via netlink socket APIs, but seems there is no netmask infos in it. I read the manual of rtnetlink, in all rtattr items, there is no netmask infos, just RTA_DST, RTA_SRC, RTA_GATEWAY... defined.

So, how to check out the netmask infos in route table? Just like we can see in route -n outputs.

Thanks a lot.

Kiril Kirov
  • 37,467
  • 22
  • 115
  • 187
Chao Zhang
  • 21
  • 3

1 Answers1

5

The prefix length associated with RTA_DST is in the rtm_dst_len field of the rtmsg, not in an rtattr. (I guess because it's a fixed-size field, unlike RTA_DST, which varies in size depending on the family.)

Dan Winship
  • 51
  • 1
  • 2
  • +1 but I guess there are other fixed length fields like RTA_METRICS etc. There must be another reason for this choice. – JuliandotNut Aug 21 '14 at 23:13