- uint32_t seqnum = 0;
-
- // expect ack
- for (; NLMSG_OK (ack_nh, len); ack_nh = NLMSG_NEXT (ack_nh, len))
- {
- if (ack_nh->nlmsg_type == NLMSG_DONE)
- return msg_count != 0 || seqnum != nlseqnum;
- // 1 => lost an ack
-
- if (ack_nh->nlmsg_type == NLMSG_ERROR)
- {
- struct nlmsgerr *errmsg = NLMSG_DATA(ack_nh);
- if (errmsg->error)
- return errmsg->error; // got an error back
- else
- {
- // ack received
- --msg_count;
- if (errmsg->msg.nlmsg_seq > seqnum);
- seqnum = errmsg->msg.nlmsg_seq;
- // if this is a single message, return now
- if (!(ack_nh->nlmsg_flags & NLM_F_MULTI))
- return msg_count != 0 || seqnum != nlseqnum;
- }
- }
- else
- // unknown message
- LOG(3, 0, 0, "Got an unknown netlink message: type %d\n", ack_nh->nlmsg_type);
- }
-
- return 1; // malformed message?!
+ int len = RTA_LENGTH(alen);
+ struct rtattr *rta;
+
+ rta = (struct rtattr *)(((void *)nh) + NLMSG_ALIGN(nh->nlmsg_len));
+ rta->rta_type = type;
+ rta->rta_len = len;
+ memcpy(RTA_DATA(rta), data, alen);
+ nh->nlmsg_len = NLMSG_ALIGN(nh->nlmsg_len) + RTA_ALIGN(len);