内核部分
#include <net/genetlink.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
int ctl_test_function(struct sk_buff *skb, struct genl_info *info)
{
printk("get process pid=%d cmd=%d pid=%d type=%d\n",info->snd_pid,info->genlhdr->cmd,info->nlhdr->nlmsg_pid,info->nlhdr->nlmsg_type);
return 0;
}
struct genl_family test_ctl = {
.id=1023, //消息类型
.name="testnet",
.version=0x02,
};
struct genl_ops test_ctl_ops={
.cmd = 100,//自己先设置一个命令
.doit = ctl_test_function,
};
static int __init testnlk_init(void)
{
if(genl_register_family(&test_ctl) != 0)
{
printk("register faimly error\n");
return -1;
}
if(genl_register_ops(&test_ctl,&test_ctl_ops) != 0)
{
printk("Register ops error\n");
goto out;
}