Chinaunix
标题:
急!!!实现netfilter钩子函数,编译报错!
[打印本页]
作者:
fzy8888cn
时间:
2006-06-07 17:14
标题:
急!!!实现netfilter钩子函数,编译报错!
向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;
}
作者:
fzy8888cn
时间:
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> ,其实
根本就没有这个文件,为什么不报错呀。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2