2 #include <netinet/in.h>
11 #include <libmnl/libmnl.h>
12 #include <linux/if_link.h>
13 #include <linux/rtnetlink.h>
15 int main(
int argc,
char *argv[])
18 char buf[MNL_SOCKET_BUFFER_SIZE*4];
21 uint32_t prefix, seq, portid;
24 nlh = mnl_nlmsg_put_header(buf);
25 nlh->nlmsg_type = RTM_NEWROUTE;
26 nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK;
27 nlh->nlmsg_seq = seq = time(NULL);
28 nlh->nlmsg_len +=
sizeof(buf) -
sizeof(
struct nlmsghdr);
30 nl = mnl_socket_open(NETLINK_FIB_LOOKUP);
32 perror(
"mnl_socket_open");
36 if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) {
37 perror(
"mnl_socket_bind");
40 portid = mnl_socket_get_portid(nl);
43 if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) {
44 perror(
"mnl_socket_send");
48 ret = mnl_socket_recvfrom(nl, buf,
sizeof(buf));
50 perror(
"mnl_socket_recvfrom");
54 ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);