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

int nla_parse ( struct nlattr tb[],
int  maxtype,
struct nlattr head,
int  len,
struct nla_policy policy 

Parse a stream of attributes into a tb buffer

  • tb destination array with maxtype+1 elements
  • maxtype maximum attribute type to be expected
  • head head of attribute stream
  • len length of attribute stream
  • policy validation policy
Parses a stream of attributes and stores a pointer to each attribute in the tb array accessable via the attribute type. Attributes with a type exceeding maxtype will be silently ignored for backwards compatibility reasons. policy may be set to NULL if no validation is required.

0 on success or a negative error code.

Definition at line 255 of file attr.c.

References nla_for_each_attr, and nlattr::nla_type.

Referenced by nla_parse_nested(), and nlmsg_parse().

      struct nlattr *nla;
      int rem, err;

      memset(tb, 0, sizeof(struct nlattr *) * (maxtype + 1));

      nla_for_each_attr(nla, head, len, rem) {
            uint16_t type = nla->nla_type;

            if (type == 0) {
                  fprintf(stderr, "Illegal nla->nla_type == 0\n");

            if (type <= maxtype) {
                  if (policy) {
                        err = validate_nla(nla, maxtype, policy);
                        if (err < 0)
                              goto errout;

                  tb[type] = nla;

      if (rem > 0)
            fprintf(stderr, "netlink: %d bytes leftover after parsing "
                   "attributes.\n", rem);

      err = 0;
      return err;

Generated by  Doxygen 1.6.0   Back to index