JuliandotNut
JuliandotNut

Reputation: 1219

Using rtnetlink, reply message type to RTM_GETROUTE message?

I have sent an RTM_GETROUTE message to the kernel using netlink sockets. Now I am listening to kernel for messages.

Kernel sends nlmsghdr structure in reply via netlink sockets. I need to know what is the message type (nlmsg_type) for it? (my code is also listening to rout delete/create events, I want to distinguish).

Is it again RTM_GETROUTE in reply? Any example code or link is appreciated.

For routing, I could only find NEWROUTE, DELROUTE and GETROUTE messages but all 3 seem to have other purposes. (1st when a route is created, 2nd when one is deleted, and third for requesting as I used.)

Here is my code for sending the message.

struct nlmsghdr* hdr;
struct rtmsg* nl_p;

nl_p = (struct rtmsg*) NLMSG_DATA(hdr);
memset(&nl_p, 0, sizeof(nl_p));

hdr->nlmsg_pid = 0;
hdr->nlmsg_seq = ++seq_num;
hdr->nlmsg_type = RTM_GETROUTE;

nl_p->rtm_family = AF_INET;
nl_p->rtm_dst_len = 0;
nl_p->rtm_src_len = 0;
nl_pload->rtm_table = RT_TABLE_MAIN;

rtable_success = send(fd, hdr, hdr->nlmsg_len, 0)

There is an example of parsing received message, but I need to know my required message type (nlmsg_type) to filter others out.

Upvotes: 1

Views: 3081

Answers (1)

Alexander Maximov
Alexander Maximov

Reputation: 97

There is libdnet project at: http://libdnet.sourceforge.net/

You can find answer for your question there in route_get function.

Upvotes: 3

Related Questions