---
name: "mnl_nlmsg_batch_current"
section: "3"
platform: "linux"
package: "libmnl-doc"
version: "1.0.5-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/mnl_nlmsg_batch_current"
---

# mnl\_nlmsg\_batch\_current(3)

Netlink message batch helpers

## NAME

batch - Netlink message batch helpers

## SYNOPSIS

### Functions

struct mnl\_nlmsg\_batch \* **mnl\_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.

## 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.

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.

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.

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.

You have to put at least one message in the batch before calling this function, otherwise your application is likely to crash.

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. This function moves the last message which does not fit the batch to the head of the buffer, if any.

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.

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 batch \
 *limit* maximum size of the batch (should be MNL\_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-).

You can allocate the buffer that you use to store the batch in the stack or the heap, no restrictions in this regard. 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()**.

Definition at line **458** of file **nlmsg.c**.

## Author

Generated automatically by Doxygen for libmnl from the source code.
