Skip to content

Instantly share code, notes, and snippets.

@supermartian
Created March 12, 2013 07:27
Show Gist options
  • Select an option

  • Save supermartian/5140929 to your computer and use it in GitHub Desktop.

Select an option

Save supermartian/5140929 to your computer and use it in GitHub Desktop.
Netlink programming demo.
@igaw

igaw commented Jun 22, 2021

Copy link
Copy Markdown

This demo code does not use padding between header and message. It 'works', because the compiler does
the padding for struct nl_req_s.

@jshen28

jshen28 commented May 21, 2022

Copy link
Copy Markdown

This demo code does not use padding between header and message. It 'works', because the compiler does the padding for struct nl_req_s.

@igaw Hello, could you provide the correct way to pad nl_req_s? thank you

@igaw

igaw commented May 23, 2022

Copy link
Copy Markdown

The raw RTNL interface is tricky. I would recomand to use libmnl & co. If you want/have to use the Kernel API check the examples in the man pages. Basically you want a buffer and use 'the position macros' (e.g. NLMSG_DATA) to place the write/read head. These macros get the alignment and padding right.

https://man7.org/linux/man-pages/man7/netlink.7.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment