水滴
分类: LINUX
2018-05-18 17:14:50
要让使络协议栈能够接收一种新协议是很简单的,我们要做的仅仅
是编写协议,使协议可以正常接收;
#include linux/module.h
#include linux/kernel.h
#include linux/if_arp.h
#include linux/init.h
#include linux/net.h
#include linux/rculist.h
#include linux/skbuff.h
#include linux/socket.h
#include asm/unaligned.h
#include net/sock.h
#ifndef ETH_P_WSMP
#define ETH_P_WSMP 0x88DC
#endif
static int wsmp_rcv(struct sk_buff *skb, struct net_device *dev,
struct packet_type *pt, struct net_device *orig_dev)
{
struct sock *sk;
printk(KERN_EMERG "wsmp_rcv\n");
if (skb->pkt_type == PACKET_OTHERHOST){
goto drop;
}
netif_rx(skb);
return NET_RX_SUCCESS;
drop:
kfree_skb(skb);
return NET_RX_DROP;
}
static struct packet_type wsmp_packet_type __read_mostly = {
.type = cpu_to_be16(ETH_P_WSMP),
.func = wsmp_rcv,
};
static int __init wsmp_init(void)
{
printk(KERN_EMERG "wsmp_init\n");
dev_add_pack(&wsmp_packet_type);
return 0;
}
static void __exit wsmp_exit(void)
{
printk(KERN_EMERG "wsmp_exit\n");
dev_remove_pack(&wsmp_packet_type);
}
module_init(wsmp_init);
module_exit(wsmp_exit);
MODULE_DESCRIPTION("Message Protocol");
MODULE_LICENSE("GPL");
MODULE_AUTHOR("xxxx>");