netlink(3)

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 the nlmsg_len field of the nlmsghdr. 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 the nlmsghdr you passed in. here's your data bestie ๐ŸŽ€
  • NLMSG_NEXT() โ€” gets the next nlmsghdr in a multipart message. โš ๏ธ big one: the caller must check whether the current nlmsghdr didn't have NLMSG_DONE set โ€” this function does not return NULL on the end. so don't be out here waiting for a NULL that 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 the nlmsghdr. 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
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms