batch: introduce mnl_nlmsg_batch_reset_buffer for mmap
PATCH 8/9 batch: introduce mnl_nlmsg_batch_reset_buffer for mmap
Signed-off-by Ken-ichirou MATSUZAWA <[email protected]>
--- include/libmnl/libmnl.h | 1 + src/libmnl.map | 1 + src/nlmsg.c | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+)
include/libmnl/libmnl.h +1 -0
@@ -74,6 +74,7 @@ extern void mnl_nlmsg_batch_reset(struct mnl_nlmsg_batch *b);extern void *mnl_nlmsg_batch_head (struct mnl_nlmsg_batch *b);extern void *mnl_nlmsg_batch_current (struct mnl_nlmsg_batch *b);extern bool mnl_nlmsg_batch_is_empty (struct mnl_nlmsg_batch *b); +extern void mnl_nlmsg_batch_reset_buffer (struct mnl_nlmsg_batch *b,void *buf,size_t limit);/* * Netlink attributes API
src/libmnl.map +1 -0
@@ -85,4 +85,5 @@ LIBMNL_1.2 { mnl_ring_build_frame; mnl_ring_parse_frame2; mnl_ring_parse_frame; + mnl_nlmsg_batch_reset_buffer; } LIBMNL_1.1;
src/nlmsg.c +20 -0
@@ -569,5 +569,25 @@ bool mnl_nlmsg_batch_is_empty(struct mnl_nlmsg_batch *b)EXPORT_SYMBOL (mnl_nlmsg_batch_is_empty);/** +* mnl_nlmsg_batch_reset_buffer - reset to the new buffer +*/ +void mnl_nlmsg_batch_reset_buffer (struct mnl_nlmsg_batch *b,void *buf,size_t limit) +{ +if (b->overflow) { +struct nlmsghdr *nlh = b->cur; +memcpy (buf, b->cur, nlh->nlmsg_len); + b->buflen = nlh->nlmsg_len; + b->cur = buf + b->buflen; + b->overflow = false; + }else { + b->buflen =0 ; + b->cur = buf; + } + b->buf = buf; + b->limit = limit; +} +EXPORT_SYMBOL (mnl_nlmsg_batch_reset_buffer); + +/** * @} */
Signature · 1 line
1.8.4.rc3