#include <netlink/netlink.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/ctrl.h>
struct nl_handle *sock;
struct nl_msg *msg;
int family;
genl_connect(sock);
CMD_FOO_GET, FOO_VERSION);
static int parse_cb(struct nl_msg *msg, void *arg)
{
struct nlattr *attrs[ATTR_MAX+1];
genlmsg_parse(nlh, 0, attrs, ATTR_MAX, policy);
if (attrs[ATTR_FOO]) {
...
}
return 0;
}
int nla_put_u32(struct nl_msg *n, int attrtype, uint32_t value)
Add a u32 netlink attribute to a netlink message.
uint32_t nla_get_u32(struct nlattr *nla)
Return payload of u32 attribute.
@ NL_CB_VALID
Message is valid.
@ NL_CB_CUSTOM
Customized handler specified by the user.
int genl_ctrl_resolve(struct nl_handle *handle, const char *name)
Resolve generic netlink family name to its identifier.
void * genlmsg_put(struct nl_msg *msg, uint32_t pid, uint32_t seq, int family, int hdrlen, int flags, uint8_t cmd, uint8_t version)
Add generic netlink header to netlink message.
struct nlmsghdr * nlmsg_hdr(struct nl_msg *n)
Return actual netlink message.
void nlmsg_free(struct nl_msg *n)
Free a netlink message.
struct nl_msg * nlmsg_alloc(void)
Allocate a new netlink message with the default maximum payload size.
#define NLM_F_ECHO
Echo this request.
#define NL_AUTO_SEQ
May be used to refer to a sequence number which should be automatically set just before sending the m...
#define NL_AUTO_PID
Will cause the netlink pid to be set to the pid assigned to the netlink handle (socket) just before s...
int nl_send_auto_complete(struct nl_handle *handle, struct nl_msg *msg)
Send netlink message and check & extend header values as needed.
int nl_recvmsgs_default(struct nl_handle *handle)
Receive a set of message from a netlink socket using handlers in nl_handle.
struct nl_handle * nl_handle_alloc(void)
Allocate new netlink socket handle.
int nl_socket_modify_cb(struct nl_handle *handle, enum nl_cb_type type, enum nl_cb_kind kind, nl_recvmsg_msg_cb_t func, void *arg)
Modify the callback handler associated to the socket.