Advertisement
troglobit

Adding a neighbour with libnl

May 21st, 2015
517
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. /* Allocate an empty neighbour handle to be filled out with the attributes
  2.  * of the new neighbour. */
  3. struct rtnl_neigh *neigh = rtnl_neigh_alloc();
  4.  
  5. /* Fill out the attributes of the new neighbour */
  6. rtnl_neigh_set_ifindex(neigh, ifindex);
  7. rtnl_neigh_set_dst(neigh, dst_addr);
  8. rtnl_neigh_set_state(neigh, rtnl_neigh_str2state("permanent"));
  9.  
  10. /* Build the netlink message and send it to the kernel, the operation will
  11.  * block until the operation has been completed. Alternatively the required
  12.  * netlink message can be built using rtnl_neigh_build_add_request()
  13.  * to be sent out using nl_send_auto_complete(). */
  14. rtnl_neigh_add(sk, neigh, NLM_F_CREATE);
  15.  
  16. /* Free the memory */
  17. rtnl_neigh_put(neigh);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement