---
name: "netlink"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/netlink"
---

# netlink(3)

Netlink macros

## NAME

netlink - Netlink macros

## LIBRARY

Standard C library (*libc*, *-lc*)

## SYNOPSIS

```
#include <asm/types.h>
#include <linux/netlink.h>
```

**int NLMSG\_ALIGN(size\_t** *size***);** **int NLMSG\_LENGTH(size\_t** *size***);** **int NLMSG\_SPACE(size\_t** *size***);** **void \*NLMSG\_DATA(struct nlmsghdr \****nlh***);** **struct nlmsghdr \*NLMSG\_NEXT(struct nlmsghdr \****nlh***, int** *size***);** **int NLMSG\_OK(struct nlmsghdr \****nlh***, int** *size***);** **int NLMSG\_PAYLOAD(struct nlmsghdr \****nlh***, int** *size***);**

## DESCRIPTION

*\<linux/netlink.h\>* defines several standard macros to access or create a netlink datagram. They are similar in spirit to the macros defined in [**cmsg**(3)](/cmsg/3.md) for auxiliary data. The buffer passed to and from a netlink socket should be accessed using only these macros.

- **NLMSG\_ALIGN**()

  Round the size of a netlink message up to align it properly.

- **NLMSG\_LENGTH**()

  Given the payload size, *size*, this macro returns the aligned size to store in the *nlmsg\_len* field of the *nlmsghdr*.

- **NLMSG\_SPACE**()

  Return the number of bytes that a netlink message with payload of *size* would occupy.

- **NLMSG\_DATA**()

  Return a pointer to the payload associated with the passed *nlmsghdr*.

- **NLMSG\_NEXT**()

  Get the next *nlmsghdr* in a multipart message. The caller must check if the current *nlmsghdr* didn't have the **NLMSG\_DONE** set—this function doesn't return NULL on end. The *size* argument is an lvalue containing the remaining size of the message buffer. This macro decrements it by the size of the message header.

- **NLMSG\_OK**()

  Return true if the netlink message is not truncated and is in a form suitable for parsing.

- **NLMSG\_PAYLOAD**()

  Return the size of the payload associated with the *nlmsghdr*.

## VERSIONS

It is often better to use netlink via *libnetlink* than via the low-level kernel interface.

## STANDARDS

Linux.

## SEE ALSO

[**libnetlink**(3)](/libnetlink/3.md), [**netlink**(7)](/netlink/7.md)
