how do you use libnl nl_sock?
Question
#include <netlink/socket.h>
#include <netlink/netlink.h>
struct nl_sock *sock;
sock = nl_socket_alloc();
The above code always fails to compile with the following error: /home/micah/Documents/C++/Socket_fun/Socket_fun/src/main.cpp|5|error: ‘sock’ does not name a type
I got this from the libnl example, and as it doesn't work, I am wondering, what is the correct way to do this?
Solution
That code has to be in a function, you can't just start calling functions outside the context of a function:
int main()
{
struct nl_sock *sock;
sock = nl_socket_alloc();
}
Also, what are you compiling with? I would recommend compiling it as C, not C++.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow