libmnl  1.0.4
Data Structures | Functions
Netlink message batch helpers
Collaboration diagram for Netlink message batch helpers:

Data Structures

struct  mnl_nlmsg_batch


struct mnl_nlmsg_batchmnl_nlmsg_batch_start (void *buf, size_t limit)
void mnl_nlmsg_batch_stop (struct mnl_nlmsg_batch *b)
bool mnl_nlmsg_batch_next (struct mnl_nlmsg_batch *b)
void mnl_nlmsg_batch_reset (struct mnl_nlmsg_batch *b)
size_t mnl_nlmsg_batch_size (struct mnl_nlmsg_batch *b)
void * mnl_nlmsg_batch_head (struct mnl_nlmsg_batch *b)
void * mnl_nlmsg_batch_current (struct mnl_nlmsg_batch *b)
bool mnl_nlmsg_batch_is_empty (struct mnl_nlmsg_batch *b)

Detailed Description

This library provides helpers to batch several messages into one single datagram. These helpers do not perform strict memory boundary checkings.

The following figure represents a Netlink message batch:

|<-----------— MNL_SOCKET_BUFFER_SIZE ----------—>| |<-----------------— batch ---------------—>| | |--------—|--------—|--------—|--------—|--------—| |<- nlmsg ->|<- nlmsg ->|<- nlmsg ->|<- nlmsg ->|<- nlmsg ->| |--------—|--------—|--------—|--------—|--------—| ^ ^ | | message N message N+1

To start the batch, you have to call mnl_nlmsg_batch_start() and you can use mnl_nlmsg_batch_stop() to release it.

You have to invoke mnl_nlmsg_batch_next() to get room for a new message in the batch. If this function returns NULL, it means that the last message that was added (message N+1 in the figure above) does not fit the batch. Thus, you have to send the batch (which includes until message N) and, then, you have to call mnl_nlmsg_batch_reset() to re-initialize the batch (this moves message N+1 to the head of the buffer). For that reason, the buffer that you have to use to store the batch must be double of MNL_SOCKET_BUFFER_SIZE to ensure that the last message (message N+1) that did not fit into the batch is written inside valid memory boundaries.