//kernel:2.4.20-8
#include <linux/module.h>
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/net.h>
#include <linux/version.h>
#include <asm/unistd.h>
#include <asm/processor.h>
#include <linux/tqueue.h>
#include <linux/interrupt.h>
#include <linux/time.h>
#include <linux/types.h>
#include <linux/wait.h>
#include <asm/uaccess.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/if_arp.h>
#define ARP_DATA_LEN 80
#define DEV_NAME "eth1"
DECLARE_WAIT_QUEUE_HEAD(tm);
DECLARE_WAIT_QUEUE_HEAD(tm1);
int finish=1;
char *sMac=NULL;
MODULE_PARM(sMac,"s");
struct sk_buff *pSkb = NULL;
struct sk_buff * CreatArpData()
{
struct sk_buff *skb= NULL;
struct net_device *dev;
struct ethhdr sEthHeader ;
struct arphdr sArp ;
dev = dev_get_by_name(DEV_NAME);
skb = dev_alloc_skb (ARP_DATA_LEN + 2);
if(skb != NULL)
{
skb->dev = dev;
skb_reserve (skb, 2);
memcpy(sEthHeader.h_dest,"\xff\xff\xff\xff\xff\xff",6);
memcpy(sEthHeader.h_source,sMac,6);
sEthHeader.h_proto = 0x0608;
memcpy(skb->data,&sEthHeader,sizeof(struct ethhdr));
skb_put(skb, sizeof(struct ethhdr));
skb->mac.ethernet = skb->data;
sArp.ar_hrd = 0x0100;
sArp.ar_pro = 0x0008;
sArp.ar_hln = 0x06;
sArp.ar_pln = 0x04;
sArp.ar_op = 0x0100;
memcpy(skb->data+sizeof(struct ethhdr),&sArp,sizeof(struct arphdr));
skb_put(skb, sizeof(struct arphdr));
memcpy(skb->data+sizeof(struct ethhdr)+ sizeof(struct arphdr),sMac,6);
memcpy(skb->data+sizeof(struct ethhdr)+ sizeof(struct arphdr)+6,"\xc0\xa8\x0f\x01",4);
memcpy(skb->data+sizeof(struct ethhdr)+ sizeof(struct arphdr)+6+4,"\x0\x0\x0\x0\x0\x0",6);
memcpy(skb->data+sizeof(struct ethhdr)+ sizeof(struct arphdr)+6+4+6,"\xc0\xa8\x0f\xfe",4);
skb_put(skb, 6+4+6+4);
skb->protocol = eth_type_trans (skb, dev);
skb_push(skb,sizeof(struct ethhdr));
return skb;
}
return NULL;
}
int BroadArpMain()
{
sigset_t tmpsig ;
sprintf(current->comm, "arpSend");
spin_lock_irq(¤t->sighand->siglock);
tmpsig = current->blocked;
siginitsetinv(¤t->blocked, sigmask(SIGKILL) | sigmask(SIGSTOP));
recalc_sigpending();
spin_unlock_irq(¤t->sighand->siglock);
daemonize();
pSkb = CreatArpData() ;
if(pSkb != NULL)
{
do
{
dev_queue_xmit(pSkb) ;
pSkb = CreatArpData() ;
interruptible_sleep_on_timeout(&tm,100);
}while(finish);
}
else
{
printk("pSkb is NULL\n");
}
return 0;
}
int __init BroadArp_init(void)
{
(void)kernel_thread(BroadArpMain,NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND);
return 0;
}
void __exit BroadArp_exit(void)
{
finish =0;
interruptible_sleep_on_timeout(&tm1,1000);
}
module_init(BroadArp_init);
module_exit(BroadArp_exit);
Makefile:
MODULE = broadArp
CFLAGS += -Wall -DEXPORT_SYMTAB -DMODULE -D__KERNEL__ -DLINUX
CFLAGS += -I/usr/src/linux-2.4/include
SOURCE= \
broadArp.c
OBJS = $(SOURCE:%.c=obj/%.o)
$(MODULE).o: $(OBJS)
$(LD) -r -o $@ $(OBJS)
obj/%.o:%.c
@mkdir -p obj
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -fr obj $(OBJS) $(MODULE).o