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

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

Create attribute index based on a stream of attributes.

  • tb Index array to be filled (maxtype+1 elements).
  • maxtype Maximum attribute type expected and accepted.
  • head Head of attribute stream.
  • len Length of attribute stream.
  • policy Attribute validation policy.
Iterates over the stream of attributes and stores a pointer to each attribute in the index array using the attribute type as index to the array. Attribute with a type greater than the maximum type specified will be silently ignored in order to maintain backwards compatibility. If policy is not NULL, the attribute will be validated using the specified policy.

See also:
0 on success or a negative error code.

Definition at line 583 of file attr.c.

References nla_for_each_attr, and 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) {
            int type = nla_type(nla);

            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