I'm trying to send an abstract data using libnl and generic netlink, when I run the following code:
struct nl_msg *msg;
struct nl_data *abstract;
int err = -1;
if ((msg = nlmsg_alloc()) == NULL)
return err;
if ((genlmsg_put(msg, ctrl->pid, NL_AUTO_SEQ, ctrl->genl_family,
0, NLM_F_REQUEST, CREATE_STATE, KLUA_VERSION) == NULL))
return err;
if ((err = nla_put_string(msg, STATE_NAME, cmd->name)))
return err;
if ((err = nl_send_auto(ctrl->sock, msg)) < 0)
return err;
nlmsg_free(msg);
The kernel receives the message well. But if I change this code for this:
struct nl_msg *msg;
struct nl_data *abstract;
int err = -1;
if ((msg = nlmsg_alloc()) == NULL)
return err;
if ((abstract = nl_data_alloc(cmd, sizeof(struct klua_nl_state))) == NULL)
return err;
if ((genlmsg_put(msg, ctrl->pid, NL_AUTO_SEQ, ctrl->genl_family,
0, NLM_F_REQUEST, CREATE_STATE, KLUA_VERSION) == NULL))
return err;
nla_put_data(msg, TEST_ATTR, abstract);
if ((err = nl_send_auto(ctrl->sock, msg)) < 0)
return err;
nlmsg_free(msg);
By the way, my TEST_ATTR
is defined as:
[TEST_ATTR] = {.type = NLA_UNSPEC}
Why the kernel isn't receiving my message if I'm changing just the payload of the message? How do I do to send abstract data through generic netlink and libnl?