qq_20738807 2016-12-14 14:25 采纳率: 0%
浏览 1517

Linux 下学习hook函数使用时用GCC编译报错

使用linux下netfilter和hook函数,使用结构体nf_hook_ops定义时总是报错 invalid use of undefined type ‘struct nf_hook_ops’,我已经在添加了该有的头文件,代码和网上很多一样,就是简单的netfilter hook代码。求dalao解惑!linux是火帽3.2.2-5,。代码和编译情况如下:


#ifndef MODULE
#define MODULE
#endif

#ifndef __KERNEL__
#define __KERNEL__
#endif

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>



/*hook处理函数*/
unsigned int hook_func(unsigned int hook,
                struct sk_buff *skb,
                const struct net_device *in,
                const struct net_device *out,
                int (*okfn)(struct sk_buff *));





/*注册hook函数数据结构*/
static struct nf_hook_ops my_hook;





/*初始化程序*/
int init_module()
{
        my_hook.hook=hook_func;
        //my_hook.owner=THIS_MODULE;
        my_hook.pf= PF_INET;
        my_hook.hooknum= NF_IP_LOCAL_IN;
        my_hook.priority = NF_IP_PRI_FIRST;

    nf_register_hook(my_hook);//注册入内核

    return 0;
}





/*清除钩子*/
void cleanup_moudule()
{
    nf_unregister_hook(&my_hook);//将用户定义的钩子从内核中删除
}

gcc编译报错:

Myfirewall.c:21: warning: struct net_device' declared inside parameter list
Myfirewall.c:21: warning: its scope is only this definition or declaration, which is probably not what you want
Myfirewall.c:21: warning:
struct sk_buff' declared inside parameter list
Myfirewall.c: In function init_module':
Myfirewall.c:37: invalid use of undefined type
struct nf_hook_ops'
Myfirewall.c:39: invalid use of undefined type struct nf_hook_ops'
Myfirewall.c:40: invalid use of undefined type
struct nf_hook_ops'
Myfirewall.c:41: invalid use of undefined type struct nf_hook_ops'
Myfirewall.c:43:
my_hook' has an incomplete type
Myfirewall.c: At top level:
Myfirewall.c:28: storage size of `my_hook' isn't known

  • 写回答

1条回答 默认 最新

  • dabocaiqq 2016-12-14 15:37
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?