免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 892 | 回复: 1
打印 上一主题 下一主题

急!!!实现netfilter钩子函数,编译报错! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-06-07 17:14 |只看该作者 |倒序浏览
向netfilter注册了NF_IP_FORWARD钩子函数,自己实现的函数如下,
目的无非就是想得到源IP地址和目的IP地址,编译后报错如下
struct iphdr *hdr = skb->nh.iph;这行dereferencing pointer to incomplete type
想不明白,请问这是怎么回事呀?

static unsigned int My_ip_forward(
                                 unsigned int hooknum,
                                 struct sk_buff ** pskb,
                                 const struct net_device *in,
                                 const struct net_device *out,
                                 int (*okfn) (struct sk_buff *)
                                 )
{

        struct in_addr *srcaddr, *dstaddr;
        //__u32 *srcaddr, *dstaddr;
        struct sk_buff *skb = *pskb;
        if(skb)
        {
                struct iphdr *hdr = skb->nh.iph;
               

                srcaddr = ( struct in_addr * )(hdr->saddr);
        }
        return NF_ACCEPT;
}

论坛徽章:
0
2 [报告]
发表于 2006-06-08 09:21 |只看该作者

sorry

不好意思,我忘记包含<linux/ip.h>了,加上去后编译没有问题了。
但是我还是有一点不明白,我的Makefile 如下
============================================================
TARGET=netfilter_01
WARN=-W  -Wall -Wstrict-prototypes -Wmissing-prototypes
INCLUDE=-isystem /lib/modules/`uname -r`/build/include
#INCLUDE=-I/usr/src/linux-`uname -r`/include
DEF=-DMODULE -D__KERNEL__ -D__USE_TO_IPV4__
CFLAGS=-c ${DEF} ${WARN} ${INCLUDE}
CC=gcc
SRC=${TARGET}.c
${TARGET}:
        ${CC} ${CFLAGS} ${SRC}

clean:
        rm -rf $(TARGET).o
==========================================================

        编译器干嘛报这个错嘛,dereferencing pointer to incomplete type。
struct iphdr 定义在 /usr/include/linux/ip.h里,我没有包含这个文件,
应该报 struct iphdr *hdr  类型没有定义呀。
        还有一个更奇怪的,我包含错了一个文件。#include <net/ipv4.h> ,其实
根本就没有这个文件,为什么不报错呀。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP