batch(3)
π batch(3) β Library Functions Manual π
okay bestie, sit down, hydrate, because we're about to talk about Netlink message batch helpers and honestly? it's giving "small API, big brain". this is batch(3) from the libmnl crew, and it's way less scary than it sounds. let's go π«Ά
β¨ NAME β¨
batch β Netlink message batch helpers π
πΈ SYNOPSIS πΈ
Functions
struct mnl_nlmsg_batch * mnl_nlmsg_batch_start (void *buf, size_t limit)β bestie starts the batch πvoid mnl_nlmsg_batch_stop (struct mnl_nlmsg_batch *b)β and this one lets it go πbool mnl_nlmsg_batch_next (struct mnl_nlmsg_batch *b)β make room for the next message β¨void mnl_nlmsg_batch_reset (struct mnl_nlmsg_batch *b)β reset and reuse, iconic β»οΈsize_t mnl_nlmsg_batch_size (struct mnl_nlmsg_batch *b)β how big is it rn πvoid * mnl_nlmsg_batch_head (struct mnl_nlmsg_batch *b)β the head of the batch πvoid * mnl_nlmsg_batch_current (struct mnl_nlmsg_batch *b)β where we're at rn πbool mnl_nlmsg_batch_is_empty (struct mnl_nlmsg_batch *b)β vibe check: is it empty? π
π¦ Detailed Description π¦
so this library gives you helpers to batch several messages into one single datagram. slay. but real talk: these helpers do not perform strict memory boundary checkings. no cap, they trust you. π
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. periodt. π
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. so like, 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. yes bestie, double. write it down. π
π Function Documentation π
π
void * mnl_nlmsg_batch_current (struct mnl_nlmsg_batch * b)
mnl_nlmsg_batch_current - returns current position in the batch
Parameters
bβ pointer to batch
this function returns a pointer to the current position in the buffer that is used to store the batch. it's literally the "you are here" dot on the map π
Definition at line 539 of file nlmsg.c.
π void * mnl_nlmsg_batch_head (struct mnl_nlmsg_batch * b)
mnl_nlmsg_batch_head - get head of this batch
Parameters
bβ pointer to batch
this function returns a pointer to the head of the batch, which is the beginning of the buffer that is used. the origin. the main character of the buffer π
Definition at line 527 of file nlmsg.c.
π bool mnl_nlmsg_batch_is_empty (struct mnl_nlmsg_batch * b)
mnl_nlmsg_batch_is_empty - check if there is any message in the batch
Parameters
bβ pointer to batch
this function returns true if the batch is empty. that's it. that's the whole function. simple queen π
Definition at line 550 of file nlmsg.c.
β¨ bool mnl_nlmsg_batch_next (struct mnl_nlmsg_batch * b)
mnl_nlmsg_batch_next - get room for the next message in the batch
Parameters
bβ pointer to batch
this function returns false if the last message did not fit into the batch. otherwise, it prepares the batch to provide room for the new Netlink message in the batch and returns true. π₯
not me warning you: you have to put at least one message in the batch before calling this function, otherwise your application is likely to crash. bestie. PLEASE. π
Definition at line 474 of file nlmsg.c.
β»οΈ void mnl_nlmsg_batch_reset (struct mnl_nlmsg_batch * b)
mnl_nlmsg_batch_reset - reset the batch
Parameters
bβ pointer to batch
this function allows you to reset a batch, so you can reuse it to create a new one. reuse era π this function moves the last message which does not fit the batch to the head of the buffer, if any. cute and efficient, we love her π«Ά
Definition at line 495 of file nlmsg.c.
π size_t mnl_nlmsg_batch_size (struct mnl_nlmsg_batch * b)
mnl_nlmsg_batch_size - get current size of the batch
Parameters
bβ pointer to batch
this function returns the current size of the batch. numbers, bestie. we love a measurable vibe π
Definition at line 515 of file nlmsg.c.
π struct mnl_nlmsg_batch * mnl_nlmsg_batch_start (void * buf, size_t limit)
mnl_nlmsg_batch_start - initialize a batch
Parameters
bufβ pointer to the buffer that will store this batchlimitβ maximum size of the batch (should beMNL_SOCKET_BUFFER_SIZE).
the buffer that you pass must be double of MNL_SOCKET_BUFFER_SIZE. the limit must be half of the buffer size, otherwise expect funny memory corruptions 8-). π "funny" she says. it is NOT funny. do the math or perish.
you can allocate the buffer that you use to store the batch in the stack or the heap, no restrictions in this regard. stack girlies and heap girlies, both welcome π this function returns NULL on error.
Definition at line 434 of file nlmsg.c.
π void mnl_nlmsg_batch_stop (struct mnl_nlmsg_batch * b)
mnl_nlmsg_batch_stop - release a batch
Parameters
bβ pointer to batch
this function releases the batch allocated by mnl_nlmsg_batch_start(). closure. healing. moving on π¦β¨
Definition at line 458 of file nlmsg.c.
π Author π
Generated automatically by Doxygen for libmnl from the source code. (she wrote herself, we stan an independent queen π
)
that's the whole page bestie, you ate it up π this was libmnl Version 1.0.5, and yeah, you just read batch(3) β go forth and batch responsibly, and remember: double the buffer, half the limit, or the memory corruptions will come for you ππ
π¦ where this page comes from
- debian trixie: libmnl-doc 1.0.5-3 Β· LGPL-2.1-only
- ubuntu noble: libmnl-doc 1.0.5-2build1 Β· LGPL-2.1-only
- ubuntu questing: libmnl-doc 1.0.5-3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms