免费注册 查看新帖 |

Chinaunix

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

编译程序问题,请大家帮忙看看这是为什么? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-03-28 19:35 |只看该作者 |倒序浏览
以下是一段防火墙程序(书上和网上都可以找到,程序肯定没问题):
#ifndef __KERNEL__
#define __KERNEL__ //按内核模块编译
#endif
#ifndef MODULE
#define MODULE //按设备驱动程序模块编译
#endif
#include <linux/module.h>; //最基本的内核模块头文件
#include <linux/sched.h>;
#include <linux/kernel.h>; //最基本的内核模块头文件
#include <linux/netdevice.h>;
#include <linux/ip.h>;
#include <linux/tcp.h>;
#include <linux/skbuff.h>;
#include <linux/proc_fs.h>;
#include <linux/if.h>;
#include <linux/in.h>;
#include <linux/firewall.h>;
#define SOL_ICMP 1
#define PERMIT_PORT 80 //只允许访问TCP的80端口

int zzl_input(struct firewall_ops *this,int pf,struct device *dev,
void *phdr,void *arg,struct sk_buff **pskb)
{//每当收到一个网络报时,此函数将被内核调用
struct tcphdr *tcph; //TCP的头指针
struct iphdr *iph; //IP头指针
struct sk_buff *skb=*pskb;
if (skb->;protocol==htons(ETH_P_ARP)){
printk("\nPermit a ARP Packet";
return FW_ACCEPT;//允许地址解析协议报
}
if(skb->;protocol==htons(ETH_P_RARP)){
printk("\nPermit a RARP Packet";
return FW_ACCEPT;//允许反向地址解析协议报
}
if(skb->;protocol==htons(ETH_P_IP))
{
iph=skb->;nh.iph;
if (iph->;protocol==SOL_ICMP)
{
printk("\nPermit a ICMP Packet";
return FW_ACCEPT;//允许网络控制报
}
if(iph->;protocol==SOL_TCP){
tcph=skb->;h.th;
if(tcph->;dest==PERMIT_PORT){
printk("\nPermit a valid access";
return FW_ACCEPT;//允许对TCP端口80的访问
}
}
}
return FW_REJECT;//禁止对本计算机的所有其它访问
}
int zzl_output(struct firewall_ops *this,int pf,struct device *dev,
void *phdr,void *arg,struct sk_buff **pskb)
{//程序编写方法同zzl_input函数模块
printk("\nzzl_output is called ";
return FW_SKIP;
}
int zzl_foreward(struct firewall_ops *this,int pf,struct device *dev,
void *phdr,void *arg,struct sk_buff **pskb)
{//程序编写方法同zzl_input函数模块
printk("\nzzl_foreward is called ";
return FW_SKIP;
}

struct firewall_ops zzl_ops=
{
NULL,
zzl_foreward,
zzl_input,
zzl_output,
PF_INET,
01
};

int init_module(void)
{
if(register_firewall(PF_INET,&zzl_ops)!=0)
{
printk("\nunable register firewall";
return -1;
}
printk("\nzzl_ops=%p",&zzl_ops);
return 0;
}
void cleanup_module(void)
{
printk("unload\n";
unregister_firewall(PF_INET,&zzl_ops);
}

现我用以下命令编译:
gcc -Wall -O2 -c MyFireWall.c
发生错误.

论坛徽章:
0
2 [报告]
发表于 2004-03-28 19:36 |只看该作者

编译程序问题,请大家帮忙看看这是为什么?

错误如下:
In file included from /usr/include/linux/fs.h:23,
                 from /usr/include/linux/capability.h:17,
                 from /usr/include/linux/binfmts.h:5,
                 from /usr/include/linux/sched.h:9,
                 from MyFireWall.c:8:
/usr/include/linux/string.h:8:2: warning: #warning Using kernel header in userla
nd!
In file included from /usr/include/linux/sched.h:14,
                 from MyFireWall.c:8:
/usr/include/linux/timex.h:173: field `time' has incomplete type
In file included from /usr/include/linux/bitops.h:69,
                 from /usr/include/asm/system.h:7,
                 from /usr/include/linux/sched.h:16,
                 from MyFireWall.c:8:
/usr/include/asm/bitops.h:327:2: warning: #warning This includefile is not avail
able on all architectures.
/usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers in users
pace: atomicity not guaranteed
In file included from /usr/include/linux/signal.h:4,
                 from /usr/include/linux/sched.h:25,
                 from MyFireWall.c:8:
/usr/include/asm/signal.h:107: parse error before "sigset_t"
/usr/include/asm/signal.h:110: parse error before '}' token
In file included from /usr/include/linux/sched.h:81,
                 from MyFireWall.c:8:
/usr/include/linux/timer.h:45: parse error before "spinlock_t"
/usr/include/linux/timer.h:53: parse error before '}' token
/usr/include/linux/timer.h:67: parse error before "tvec_base_t"
/usr/include/linux/timer.h:101: parse error before "tvec_bases"
/usr/include/linux/timer.h: In function `init_timer':

论坛徽章:
0
3 [报告]
发表于 2004-03-28 19:38 |只看该作者

编译程序问题,请大家帮忙看看这是为什么?

还有点不贴了,主要是这个错误:
warning: #warning Using kernel header in userla
nd!

warning: #warning Using kernel headers in users
pace: atomicity not guaranteed
请发生过类似问题的朋友进来帮忙看看,谢谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP