Skip to content

Instantly share code, notes, and snippets.

@supermartian
Created March 12, 2013 07:27
Show Gist options
  • Save supermartian/5140929 to your computer and use it in GitHub Desktop.
Save supermartian/5140929 to your computer and use it in GitHub Desktop.
Netlink programming demo.
@sachinites
Copy link

dont you have to write any kernel module for this.
Secondly, i tried executing it, and rtnl_print_link() is never called, so no output.

@igaw
Copy link

igaw commented Jun 22, 2021

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
Copy link

jshen28 commented May 21, 2022

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
Copy link

igaw commented May 23, 2022

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