I am trying to develop a module to communicate between Kernel and Userspace application. I tried the answer provided in https://stackoverflow.com/a/25071310/4190159
The issue is I have the following code:
#include <net/sock.h>
#include <net/netlink.h>
#include <linux/skbuff.h>
#include <string.h>
#define MY_GROUP 1
struct sock* socket;
struct sk_buff* socket_buff;
static void nl_receive_callback (struct sk_buff *skb)
{
nlmsg_free(skb);
}
static void kernel_send_nl_msg(void)
{
struct nlmsghdr *nlsk_mh;
char* msg = "hello kernel";
socket = netlink_kernel_create(&init_net, NETLINK_USERSOCK, 1, nl_receive_callback, NULL, THIS_MODULE);
socket_buff = nlmsg_new(256, GFP_KERNEL);
nlsk_mh = nlmsg_put(socket_buff, 0, 0, NLMSG_DONE, strlen(msg), 0);
NETLINK_CB(socket_buff).pid = 0; // kernel pid
NETLINK_CB(socket_buff).dst_group = MY_GROUP;
strcpy(nlmsg_data(nlsk_mh), msg);
nlmsg_multicast(socket, socket_buff, 0, MY_GROUP, GFP_KERNEL);
return;
}
When I try to compile the aforementioned code using:
gcc netlink_module.c -o netlink.o
I receive the following error:
netlink_module.c:2:10: fatal error: net/sock.h: No such file or directory #include < net/sock.h > compilation terminated.
I tried to search for the error but most of the search result come back for sys/socket.h file but not for net/sock.h
Can someone point out what is going wrong?