⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test_ipv6.c

📁 LINUX内核编程,可以截获网络上IPV6数据包文
💻 C
字号:
#define __KERNEL__#define MODULE#include <linux/module.h>#include <linux/netdevice.h>#include <linux/kernel.h>#include <linux/netfilter.h>#include <linux/netfilter_ipv6.h>#include <linux/skbuff.h>#include <linux/config.h>#include <linux/errno.h>#include <linux/types.h>#include <linux/socket.h>#include <linux/sockios.h>#include <linux/sched.h>#include <linux/net.h>#include <linux/in6.h>#include <linux/icmpv6.h>#include <net/ipv6.h>#include <net/protocol.h>#include <net/transp_v6.h>#include <net/rawv6.h>#include <net/ndisc.h>#include <net/ip6_route.h>#include <net/addrconf.h>static struct nf_hook_ops nfho_pre;static struct nf_hook_ops nfho_in;static struct nf_hook_ops nfho_out;static struct nf_hook_ops nfho_post;unsigned int hook_pre_routing( unsigned int hooknum, 		struct sk_buff **skb, 		const struct net_device *in,		const struct net_device *out,		int (*okfn)(struct sk_buff *)){	struct ipv6hdr *hdr;	printk("Enter NF_IP6_PRE_ROUTING hook point ...\n");	hdr = (*skb)->nh.ipv6h;	if (hdr->version != 6)		return NF_ACCEPT;	printk(" IPv6 Packet priority =%d\n",hdr->priority);	printk(" IPv6 Packet flow_lbl[0] = %d\n", hdr->flow_lbl[0]);	printk(" IPv6 Packet nexthdr=%d\n",hdr->nexthdr);	return NF_ACCEPT;}unsigned int hook_local_in( unsigned int hooknum, 		struct sk_buff **skb, 		const struct net_device *in,		const struct net_device *out,		int (*okfn)(struct sk_buff *)){	printk("Enter NF_IP6_LOCAL_IN hook point ...\n");	return NF_ACCEPT;}unsigned int hook_local_out( unsigned int hooknum, 		struct sk_buff **skb, 		const struct net_device *in,		const struct net_device *out,		int (*okfn)(struct sk_buff *)){	printk("Enter NF_IP6_LOCAL_OUT hook point ...\n");	return NF_ACCEPT;}unsigned int hook_post( unsigned int hooknum, 		struct sk_buff **skb, 		const struct net_device *in,		const struct net_device *out,		int (*okfn)(struct sk_buff *)){	printk("Enter NF_IP6_POST_ROUTING hook point ...\n");	return NF_ACCEPT;}int init_module(){	nfho_pre.hook = hook_pre_routing;	nfho_pre.hooknum = NF_IP6_PRE_ROUTING;	nfho_pre.pf = PF_INET6;	nfho_pre.priority = NF_IP6_PRI_FIRST;	nfho_in.hook = hook_local_in;	nfho_in.hooknum = NF_IP6_LOCAL_IN;	nfho_in.pf = PF_INET6;	nfho_in.priority = NF_IP6_PRI_FIRST;	nfho_out.hook = hook_local_out;	nfho_out.hooknum = NF_IP6_LOCAL_OUT;	nfho_out.pf = PF_INET6;	nfho_out.priority = NF_IP6_PRI_FIRST;	nfho_post.hook = hook_post;	nfho_post.hooknum = NF_IP6_POST_ROUTING;	nfho_post.pf = PF_INET6;	nfho_post.priority = NF_IP6_PRI_FIRST;	nf_register_hook( &nfho_pre );	nf_register_hook( &nfho_in );	nf_register_hook( &nfho_out );		nf_register_hook( &nfho_post );		return 0;}void cleanup_module(){	nf_unregister_hook( &nfho_pre );	nf_unregister_hook( &nfho_in );	nf_unregister_hook( &nfho_out );	nf_unregister_hook( &nfho_post );}MODULE_LICENSE("GPL");

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -