netlink(3)
๐ netlink โ Netlink macros ๐
okay bestie, settle in, because we're talking about netlink(3) โ the manual page for the little macro family that handles your netlink datagrams ๐ no cap, these are the ones you actually need.
๐ LIBRARY
Standard C library โ that's libc, link with -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 ๐ธ
k so <linux/netlink.h> defines a whole little squad of standard macros for accessing or creating a netlink datagram โจ. They're similar in spirit to the macros defined over in cmsg(3) for auxiliary data โ same energy, different body of work.
real talk: the buffer you pass to and from a netlink socket should be accessed using only these macros. Like, only. Do not freestyle it ๐ญ
Here's the whole cast, one by one:
NLMSG_ALIGN()โ rounds the size of a netlink message up so it's properly aligned. glow-up but for byte boundaries ๐NLMSG_LENGTH()โ hand it a payload size, size, and it returns the aligned size that you store in thenlmsg_lenfield of thenlmsghdr. it's giving "do the math for me" โจNLMSG_SPACE()โ returns the number of bytes a netlink message with a payload of size would take up. headcount but for bytes ๐NLMSG_DATA()โ returns a pointer to the payload that's associated with thenlmsghdryou passed in. here's your data bestie ๐NLMSG_NEXT()โ gets the nextnlmsghdrin a multipart message. โ ๏ธ big one: the caller must check whether the currentnlmsghdrdidn't haveNLMSG_DONEset โ this function does not returnNULLon the end. so don't be out here waiting for aNULLthat never comes, you'll be stuck forever ๐. The size argument is an lvalue holding the remaining size of the message buffer, and this macro decrements it by the size of the message header. it keeps the receipt and updates the total, periodt.NLMSG_OK()โ returns true if the netlink message is not truncated and is in a form suitable for parsing. vibe check for your message ๐ฆNLMSG_PAYLOAD()โ returns the size of the payload associated with thenlmsghdr. how much payload, exactly? this one knows ๐
๐ง VERSIONS ๐ง
ngl bestie, it's often better to use netlink via libnetlink than via the low-level kernel interface. just saying ๐
โญ STANDARDS โญ
Linux. that's it, that's the standard ๐
๐ซถ SEE ALSO ๐ซถ
okay that's the whole page, ur welcome ๐
this was brought to you by Linux man-pages 6.20, dated 2026-02-08, and it's the netlink(3) page, mwah, go slay your netlink buffers bestie โจ๐๐
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: GPL-1.0-or-later
- Copyright 1998, Andi Kleen <andi@firstfloor.org>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms