关于netlink的问题
在网上抄了段代码
#include <linux/autoconf.h>
#include <linux/module.h>
#include <linux/version.h>
#include <linux/skbuff.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <net/sock.h>
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/netlink.h>
struct sock *nl_sk = NULL;
void nl_data_ready (struct sock *sk, int len)
{
wake_up_interruptible(sk-> sleep);
}
void netlink_test() {
struct sk_buff *skb = NULL;
struct nlmsghdr *nlh = NULL;
int err;
u32 pid;
nl_sk = netlink_kernel_create(NETLINK_TEST,
nl_data_ready);
/* wait for message coming down from user-space */
skb = skb_recv_datagram(nl_sk, 0, 0, &err);
nlh = (struct nlmsghdr *)skb-> data;
printk( "%s: received netlink message payload:%s\n ",
__FUNCTION__, NLMSG_DATA(nlh));
pid = nlh-> nlmsg_pid; /*pid of sending process */
NETLINK_CB(skb).groups = 0; /* not in mcast group */
NETLINK_CB(skb).pid = 0; /* from kernel */
NETLINK_CB(skb).dst_pid = pid;
NETLINK_CB(skb).dst_groups = 0; /* unicast */
netlink_unicast(nl_sk, skb, pid, MSG_DONTWAIT);
sock_release(nl_sk-> socket);
}
static int my_module_init(void){
printk(KERN_INFO "initializing Netlink Socket!\n ");
netlink_test();
return 0;
}
static void netlink_clear(void)
{
printk(KERN_INFO "GOod Bye!\n ");
}
module_init(my_module_init);
module_exit(netlink_clear);
在fc6下编译,出错说struct sock没有名为sleep的成员,2.6.18内核的sock变了吗?
------解决方案--------------------sk_sleep
------解决方案--------------------头文件变了