/********************************************************** * Example for a transport protocol * Compile: * gcc -I/lib/modules/'uname -r'/build/include -c file.c **********************************************************/ #ifndef _KERNEL_ #define _KERNEL_ #endif #ifndef MODULE #define MODULE #endif #include <linux/module.h> #include <linux/version.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/skbuff.h> #include <linux/in.h> #include <net/protocol.h> MODULE_AUTHOR("Test Author (fixme@Linux-netzwerkarchitektur.de)"); MODULE_DESCRIPTION("Module with a layer-4 test protocol"); int test_proto_rcv(struct sk_buff *skb); static struct inet_protocol test_protocol = { &test_proto_rcv, /* protocol handler */ NULL, /* error control */ NULL, /* next */ IPPROTO_TCP, /* protocol ID */ 0, /* copy */ NULL, /* data */ " Test_Protocol" /* name */ }; int test_proto_rcv(struct sk_buff *skb) { printk(KERN_DEBUG "Test protocol: Packet Received with length: %u\n", skb->len); return skb->len; } int init_module(void) { inet_add_protocol(&test_protocol); return 0; } void cleanup_module(void) { inet_del_protocol(&test_protocol); }