test-genl.c 937 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "../src/utils.h"
  2. int main(int argc, char *argv[])
  3. {
  4. struct nl_handle *h;
  5. struct nl_msg *msg;
  6. void *hdr;
  7. if (nltool_init(argc, argv) < 0)
  8. return -1;
  9. h = nltool_alloc_handle();
  10. if (!h) {
  11. nl_perror("nl_handle_alloc");
  12. return -1;
  13. }
  14. if (genl_connect(h) < 0) {
  15. nl_perror("genl_connect");
  16. return -1;
  17. }
  18. msg = nlmsg_alloc();
  19. if (msg == NULL) {
  20. nl_perror("nlmsg_alloc");
  21. return -1;
  22. }
  23. hdr = genlmsg_put(msg, NL_AUTO_PID, NL_AUTO_SEQ, GENL_ID_CTRL,
  24. 0, 0, CTRL_CMD_GETFAMILY, 1);
  25. if (hdr == NULL) {
  26. nl_perror("genlmsg_put");
  27. return -1;
  28. }
  29. if (nla_put_u32(msg, CTRL_ATTR_FAMILY_ID, GENL_ID_CTRL) < 0) {
  30. nl_perror("nla_put_u32(CTRL_ATTR_FAMILY_ID)");
  31. return -1;
  32. }
  33. if (nl_send_auto_complete(h, msg) < 0) {
  34. nl_perror("nl_send_auto_complete");
  35. return -1;
  36. }
  37. if (nl_recvmsgs_default(h) < 0) {
  38. nl_perror("nl_recvmsgs_def");
  39. return -1;
  40. }
  41. nlmsg_free(msg);
  42. nl_close(h);
  43. return 0;
  44. }