| 1 |
.\" Copyright 1998, Andi Kleen <[email protected]> |
| 2 |
.\" Copyright, the authors of the Linux man-pages project |
| 3 |
.\" |
| 4 |
.\" SPDX-License-Identifier: GPL-1.0-or-later |
| 5 |
.\" |
| 6 |
.TH netlink 3 2026-02-08 "Linux man-pages 6.18" |
| 7 |
.SH NAME |
| 8 |
netlink \- Netlink macros |
| 9 |
.SH LIBRARY |
| 10 |
Standard C library |
| 11 |
.RI ( libc ,\~ \-lc ) |
| 12 |
.SH SYNOPSIS |
| 13 |
.nf |
| 14 |
.B #include <asm/types.h> |
| 15 |
.B #include <linux/netlink.h> |
| 16 |
.P |
| 17 |
.BI "int NLMSG_ALIGN(size_t " size ); |
| 18 |
.BI "int NLMSG_LENGTH(size_t " size ); |
| 19 |
.BI "int NLMSG_SPACE(size_t " size ); |
| 20 |
.BI "void *NLMSG_DATA(struct nlmsghdr *" nlh ); |
| 21 |
.BI "struct nlmsghdr *NLMSG_NEXT(struct nlmsghdr *" nlh ", int " size ); |
| 22 |
.BI "int NLMSG_OK(struct nlmsghdr *" nlh ", int " size ); |
| 23 |
.BI "int NLMSG_PAYLOAD(struct nlmsghdr *" nlh ", int " size ); |
| 24 |
.fi |
| 25 |
.SH DESCRIPTION |
| 26 |
.I <linux/netlink.h> |
| 27 |
defines several standard macros to access or create a netlink datagram. |
| 28 |
They are similar in spirit to the macros defined in |
| 29 |
.BR cmsg (3) |
| 30 |
for auxiliary data. |
| 31 |
The buffer passed to and from a netlink socket should |
| 32 |
be accessed using only these macros. |
| 33 |
.TP |
| 34 |
.BR NLMSG_ALIGN () |
| 35 |
Round the size of a netlink message up to align it properly. |
| 36 |
.TP |
| 37 |
.BR NLMSG_LENGTH () |
| 38 |
Given the payload size, |
| 39 |
.IR size , |
| 40 |
this macro returns the aligned size to store in the |
| 41 |
.I nlmsg_len |
| 42 |
field of the |
| 43 |
.IR nlmsghdr . |
| 44 |
.TP |
| 45 |
.BR NLMSG_SPACE () |
| 46 |
Return the number of bytes that a netlink message with payload of |
| 47 |
.I size |
| 48 |
would occupy. |
| 49 |
.TP |
| 50 |
.BR NLMSG_DATA () |
| 51 |
Return a pointer to the payload associated with the passed |
| 52 |
.IR nlmsghdr . |
| 53 |
.TP |
| 54 |
.\" this is bizarre, maybe the interface should be fixed. |
| 55 |
.BR NLMSG_NEXT () |
| 56 |
Get the next |
| 57 |
.I nlmsghdr |
| 58 |
in a multipart message. |
| 59 |
The caller must check if the current |
| 60 |
.I nlmsghdr |
| 61 |
didn't have the |
| 62 |
.B NLMSG_DONE |
| 63 |
set\[em]this function doesn't return NULL on end. |
| 64 |
The |
| 65 |
.I size |
| 66 |
argument is an lvalue containing the remaining size |
| 67 |
of the message buffer. |
| 68 |
This macro decrements it by the size of the message header. |
| 69 |
.TP |
| 70 |
.BR NLMSG_OK () |
| 71 |
Return true if the netlink message is not truncated and |
| 72 |
is in a form suitable for parsing. |
| 73 |
.TP |
| 74 |
.BR NLMSG_PAYLOAD () |
| 75 |
Return the size of the payload associated with the |
| 76 |
.IR nlmsghdr . |
| 77 |
.SH VERSIONS |
| 78 |
It is often better to use netlink via |
| 79 |
.I libnetlink |
| 80 |
than via the low-level kernel interface. |
| 81 |
.SH STANDARDS |
| 82 |
Linux. |
| 83 |
.SH SEE ALSO |
| 84 |
.BR libnetlink (3), |
| 85 |
.BR netlink (7) |