📄 test.c
字号:
#ifndef __KERNEL__ #define __KERNEL__#endif#ifndef MODULE #define MODULE#endif
#include <linux/module.h>#include <linux/sched.h>#include <linux/kernel.h> /* printk() */#include <linux/init.h>//#include <linux/in.h>#include <linux/netdevice.h> /* struct device, and other headers */#include <linux/etherdevice.h> /* eth_type_trans *///#include <linux/ip.h> /* struct iphdr *///#include <linux/tcp.h> /* struct tcphdr */static int test_init(struct net_device *dev);static int test_open(struct net_device *dev);static int test_release(struct net_device *dev); static int test_config(struct net_device *dev, struct ifmap *map);static int test_tx(struct sk_buff *skb, struct net_device *dev);int test_init_module(void);void test_cleanup(void);#define DEVICE_NAME "test" /* name for messaging */module_init(test_init_module);module_exit(test_cleanup);/********************************************************************************************************/
static struct net_device net_test ={ name: "eth0", init: test_init,}; static int test_init(struct net_device *dev){ ether_setup(dev); /* assign some of the fields */ dev->open = test_open; dev->stop = test_release; dev->set_config = test_config; dev->hard_start_xmit = test_tx; dev->flags &= ~(IFF_BROADCAST | IFF_LOOPBACK | IFF_MULTICAST); //dev->get_stats = test_stats; //dev->tx_timeout = test_tx_timeout; //dev->watchdog_timeo = timeout; //dev->do_ioctl = test_ioctl; SET_MODULE_OWNER(dev); //dev->priv = kmalloc(sizeof(struct test_priv), GFP_KERNEL); return 0;} static int test_config(struct net_device *dev, struct ifmap *map){ return 0;} static int test_tx(struct sk_buff *skb, struct net_device *dev){ return 0;} static int test_open(struct net_device *dev){ MOD_INC_USE_COUNT; netif_start_queue(dev); return 0; /* success */} static int test_release(struct net_device *dev) { netif_stop_queue(dev); MOD_DEC_USE_COUNT; return(0); } int test_init_module(void){ int result; result = register_netdev(&net_test); if (result < 0) { printk(KERN_ERR DEVICE_NAME ": error %i registering device \"%s\"\n", result, net_test.name); return(result); } printk(KERN_ERR DEVICE_NAME ": init OK\n"); return(0); } void test_cleanup(void){ unregister_netdev(&net_test);}/*********************************************************************************************************** End Of File********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -