Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. int main(void) {
  2. struct nl_sock *sock;
  3. struct nl_cache *cache;
  4.  
  5. if (!(sock = nl_socket_alloc())) {
  6. perror("nl_socket_alloc");
  7. return -1;
  8. }
  9.  
  10. if (nl_connect(sock, NETLINK_ROUTE) < 0) {
  11. perror("nl_connect");
  12. nl_socket_free( sock );
  13. return -1;
  14. }
  15.  
  16. if (rtnl_link_alloc_cache(sock, AF_UNSPEC, &cache) < 0) {
  17. perror("rtnl_link_alloc_cache");
  18. nl_socket_free( sock );
  19. nl_close( sock );
  20. return -1;
  21. }
  22. {
  23. int ifindex, rc, flags;
  24. struct rtnl_link *link = NULL;
  25.  
  26. if (!(ifindex = rtnl_link_name2i(cache, "eno1.10"))) {
  27. perror("rtnl_link_name2i");
  28. return -1;
  29. }
  30. printf("ind: %dn", ifindex);
  31.  
  32. if (!(link = rtnl_link_get(cache, ifindex))) {
  33. perror("rtnl_link_get");
  34. return -1;
  35. }
  36.  
  37. if (rtnl_link_is_vlan(link)) {
  38. puts("It's VLAN link");
  39.  
  40. /* alas it's not about the 'real' device */
  41. printf("master: %dn", rtnl_link_get_master(link));
  42. } else
  43. puts("It's 'real' link");
  44. }
  45.  
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement