InBlock.gif[root@server1 ~]# cat send.c
InBlock.gif /*                                                                                                            
InBlock.gif * $Id: hello.c,v 1.5 2004/10/26 03:32:21 corbet Exp $    
InBlock.gif */
                                                                                                        
InBlock.gif#include <linux/init.h>
InBlock.gif#include <linux/module.h>
InBlock.gif#include <lp.h>
InBlock.gifMODULE_LICENSE( "Dual BSD/GPL");
InBlock.gif
InBlock.gif int send = 0;
InBlock.gifmodule_param(send, int, S_IRUGO);
InBlock.gif
InBlock.gifnet_device_t * NIC = NULL;
InBlock.gif
InBlock.gif int lp_recv(sk_buff_t * skb, net_device_t * dev, packet_type_t * pt, net_device_t * d){
InBlock.gif                PDEBUG( "lp_recv is being invoked\n");
InBlock.gif                 return NET_RX_SUCCESS;
InBlock.gif}
InBlock.gif
InBlock.gifpacket_type_t lp_ptype = {
InBlock.gif                .type = __constant_htons(ETH_P_LP),
InBlock.gif                .func = lp_recv,
InBlock.gif                .dev = NULL,
InBlock.gif                .af_packet_priv = NULL,
InBlock.gif};
InBlock.gif
InBlock.gif int lp_send_skb(sk_buff_t * skb)
InBlock.gif{
InBlock.gif                ethhdr_t * eth = NULL;
InBlock.gif                 char * dest = kmalloc(ETH_ALEN, GFP_KERNEL);
InBlock.gif                 if(!dest)
InBlock.gif                {
InBlock.gif                                PDEBUG( "alloc dest fail");
InBlock.gif                }
InBlock.gif                dest[0] = 0x00;
InBlock.gif                dest[1] = 0x16;
InBlock.gif                dest[2] = 0x3e;
InBlock.gif                dest[3] = 0x53;
InBlock.gif                dest[4] = 0x12;
InBlock.gif                dest[5] = 0x51;
InBlock.gif
InBlock.gif                skb->data_len = 0;
InBlock.gif                skb->len =    LINK_HDR + 10;
InBlock.gif                skb->tail = skb->data + LINK_HDR + 10;
InBlock.gif                skb->mac.raw = skb->nh.raw = skb->h.raw = skb->data;
InBlock.gif                skb->dev = NIC;
InBlock.gif                skb->protocol = htons(ETH_P_LP);
InBlock.gif                eth = (ethhdr_t *)skb->data;
InBlock.gif                eth->h_proto = htons(ETH_P_LP);
InBlock.gif                memcpy(eth->h_dest, dest, ETH_ALEN);
InBlock.gif                memcpy(eth->h_source, NIC->dev_addr, ETH_ALEN);
InBlock.gif                 if(dev_queue_xmit(skb)){
InBlock.gif                                 return -1;
InBlock.gif                }
InBlock.gif                 return 0;
InBlock.gif}
InBlock.gif
InBlock.gif static int send_init( void)
InBlock.gif{
InBlock.gif                sk_buff_t * skb;
InBlock.gif                 if(!(NIC = dev_get_by_name( "eth0")))
InBlock.gif                {
InBlock.gif                                PDEBUG( "NIC is null\n");
InBlock.gif                                 return -ENODEV;
InBlock.gif                }
InBlock.gif                dev_add_pack(&lp_ptype);
InBlock.gif                PDEBUG( "lp init\n");
InBlock.gif                 if(send)
InBlock.gif                {
InBlock.gif                                 if(!(skb = alloc_skb(LINK_HDR+10, GFP_KERNEL)))
InBlock.gif                                {
InBlock.gif                                                PDEBUG( "alloc skb fail\n");
InBlock.gif                                }
InBlock.gif                                 if(!lp_send_skb(skb))
InBlock.gif                                {
InBlock.gif                                                PDEBUG( "send success\n");
InBlock.gif                                }
InBlock.gif                                kfree_skb(skb);
InBlock.gif                }
InBlock.gif                 return 0;
InBlock.gif}
InBlock.gif
InBlock.gif static void send_exit( void)
InBlock.gif{
InBlock.gif                dev_remove_pack(&lp_ptype);
InBlock.gif                dev_put(NIC);
InBlock.gif                PDEBUG( "lp exit\n");
InBlock.gif}
InBlock.gif
InBlock.gifmodule_init(send_init);
InBlock.gifmodule_exit(send_exit);