Logo Search packages:      
Sourcecode: libnl2 version File versions  Download package

struct nlattr* nla_reserve ( struct nl_msg *  msg,
int  attrtype,
int  attrlen 
) [read]

Reserve space for a attribute.

  • msg Netlink Message.
  • attrtype Attribute Type.
  • attrlen Length of payload.
Reserves room for a attribute in the specified netlink message and fills in the attribute header (type, length). Returns NULL if there is unsuficient space for the attribute.

Any padding between payload and the start of the next attribute is zeroed out.

Pointer to start of attribute or NULL on failure.

Definition at line 798 of file attr.c.

References nla_attr_size(), nla_padlen(), nla_total_size(), and nlmsg_data().

Referenced by nla_put().

      struct nlattr *nla;
      int tlen;
      tlen = NLMSG_ALIGN(msg->nm_nlh->nlmsg_len) + nla_total_size(attrlen);

      if ((tlen + msg->nm_nlh->nlmsg_len) > msg->nm_size)
            return NULL;

      nla = (struct nlattr *) nlmsg_tail(msg->nm_nlh);
      nla->nla_type = attrtype;
      nla->nla_len = nla_attr_size(attrlen);

      memset((unsigned char *) nla + nla->nla_len, 0, nla_padlen(attrlen));
      msg->nm_nlh->nlmsg_len = tlen;

      NL_DBG(2, "msg %p: Reserved %d bytes at offset +%td for attr %d "
              "nlmsg_len=%d\n", msg, attrlen,
              (void *) nla - nlmsg_data(msg->nm_nlh),
              attrtype, msg->nm_nlh->nlmsg_len);

      return nla;

Generated by  Doxygen 1.6.0   Back to index