2.6.22下基于Netfilter的网络监听程序
来源:互联网 发布:文章发布系统源码 编辑:程序博客网 时间:2024/06/01 09:49
在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 <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/ip.h>
#include <linux/tcp.h>
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);
/*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 <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/ip.h>
#include <linux/tcp.h>
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);
- 2.6.22下基于Netfilter的网络监听程序
- linux 基于netfilter的网内监听
- linux环境下的网络监听程序
- 基于C#的网络SNIFFER网络IP层监听程序
- netfilter的抓包程序
- 【入侵】Linux下的网络监听技术
- Linux下的网络监听技术
- linux下的Netfilter&iptables
- 基于网络监听方式的电子邮件实现基础
- 内核中基于netfilter的编译选项
- LVS基于linux内核的netfilter机制
- (一)洞悉linux下的Netfilter&iptables:什么是Netfilter?
- 洞悉linux下的Netfilter&iptables:什么是Netfilter?
- (一)洞悉linux下的Netfilter&iptables:什么是Netfilter?
- (一)洞悉linux下的Netfilter&iptables:什么是Netfilter?
- (一)洞悉linux下的Netfilter&iptables:什么是Netfilter?
- (一)洞悉linux下的Netfilter&iptables:什么是Netfilter?
- (一)洞悉linux下的Netfilter&iptables:什么是Netfilter?
- UltraWebGrid 模板列取值(转)
- 使用HibernateTemplate
- SQLDirect组件库用户指南
- DWR 入門與應用(二)
- VS2005安装项目出现:Setup.vdproj 不可恢复的生成错误的解决方法
- 2.6.22下基于Netfilter的网络监听程序
- Javascript 操作select控件大全(新增、修改、删除、选中、清空、判断存在等)
- String的正则表达式分割
- DWR 入門與應用(三)
- Eclipse快捷键大全
- 动态内存分配 (转载)
- 超级转换秀
- 安装C# Windows服务程序
- 电话从此免费 callfreee网络电话试用小记