免费注册 查看新帖 |

Chinaunix

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

2.6.22下Netfilter的网络监听程序 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-13 16:14 |只看该作者 |倒序浏览
在2.6.22中skbuff发生了变化,使得我以前的防火墙程序在新内核中无法使用了,主要是可以当作一个网络数据监视,当然还是不完善的。今天搞了一下,终于又可以了,下面是程序:
/*This program is wrote by helight--Zhenwen Xu
*version 0.1
*2008-04-13
*/
#define DRIVER_AUTHOR "Net4-Helight"
#define DRIVER_DESC   "A sample test"
#include
#include
#include
#include
#include
#include
#include
MODULE_LICENSE("GPL");
/*regist the hooks*/
static struct nf_hook_ops nfho;
unsigned int hook_func(unsigned int hookunm,struct sk_buff **skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff *))
{
int i=0;
struct tcphdr *tcph;
struct iphdr *iph;
struct sk_buff *pskb=*skb;
printk("\n the pskb->protocol :%d",pskb->protocol);
printk("MAC--mark:%d\n",(unsigned int)pskb->pkt_type);
iph=(struct iphdr*)pskb->network_header;
printk("IPHDR:%d\n",(unsigned int)iph->protocol);
printk("IP: [%u.%u.%u.%u]-->[%u.%u.%u.%u]",NIPQUAD(iph->saddr),NIPQUAD(iph->daddr));
if(iph->protocol==6)
{
    tcph=(struct tcphdr*)pskb->transport_header;
    printk("TCP: [%u]-->[%u]",ntohs(tcph->source),ntohs(tcph->dest));
    printk("\n");
}
return NF_ACCEPT;
}
/*init the module*/
static int init_sniffer(void)
{
nfho.hook=hook_func;
nfho.hooknum=NF_IP_PRE_ROUTING;
nfho.pf=PF_INET;
nfho.priority=NF_IP_PRI_FIRST;
nf_register_hook(&nfho);
printk("This is helight's sniffer\n");
return 0;
}
/*Clear the module*/
void exit_sniffer(void)
{
printk("This is helight's sniffer\n");
nf_unregister_hook(&nfho);
}
module_init(init_sniffer);
module_exit(exit_sniffer);
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/65841/showart_529452.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP