1
0

unl.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef __UNL_H
  2. #define __UNL_H
  3. #include <netlink/netlink.h>
  4. #include <netlink/genl/genl.h>
  5. #include <netlink/genl/family.h>
  6. #include <stdbool.h>
  7. struct unl {
  8. struct nl_sock *sock;
  9. struct nl_cache *cache;
  10. struct genl_family *family;
  11. char *family_name;
  12. int hdrlen;
  13. bool loop_done;
  14. };
  15. int unl_genl_init(struct unl *unl, const char *family);
  16. int unl_rtnl_init(struct unl *unl);
  17. void unl_free(struct unl *unl);
  18. typedef int (*unl_cb)(struct nl_msg *, void *);
  19. struct nl_msg *unl_genl_msg(struct unl *unl, int cmd, bool dump);
  20. struct nl_msg *unl_rtnl_msg(struct unl *unl, int cmd, bool dump);
  21. int unl_request(struct unl *unl, struct nl_msg *msg, unl_cb handler, void *arg);
  22. int unl_request_single(struct unl *unl, struct nl_msg *msg, struct nl_msg **dest);
  23. void unl_loop(struct unl *unl, unl_cb handler, void *arg);
  24. /* compat */
  25. #define unl_genl_request unl_request
  26. #define unl_genl_request_single unl_request_single
  27. #define unl_genl_loop unl_loop
  28. int unl_genl_multicast_id(struct unl *unl, const char *name);
  29. int unl_genl_subscribe(struct unl *unl, const char *name);
  30. int unl_genl_unsubscribe(struct unl *unl, const char *name);
  31. int unl_nl80211_phy_lookup(const char *name);
  32. int unl_nl80211_wdev_to_phy(struct unl *unl, int wdev);
  33. struct nl_msg *unl_nl80211_phy_msg(struct unl *unl, int phy, int cmd, bool dump);
  34. struct nl_msg *unl_nl80211_vif_msg(struct unl *unl, int dev, int cmd, bool dump);
  35. static inline void unl_loop_done(struct unl *unl)
  36. {
  37. unl->loop_done = true;
  38. }
  39. static inline struct nlattr *unl_find_attr(struct unl *unl, struct nl_msg *msg, int attr)
  40. {
  41. return nlmsg_find_attr(nlmsg_hdr(msg), unl->hdrlen, attr);
  42. }
  43. #endif