hi there,
This is gaurav,i am trying to implement a network sniffer application which will snoop on the network traffic and redirects it to a virtual network device 'sniffer' created by me... i have created the skeleton of the driver but i am stuck while writing the handler for the ETH_P_ALL...please help me out...i am posting the code which i thought was correct....do suggest the changes if required...thanks in advance...
Best Regards,
Gaurav Holey
PHP Code:
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/init.h>
/*================================================================
Function Prototypes
==================================================================*/
Sniffer_Init_Module(void);
Sniffer_open(struct net_device*);
Sniffer_release(struct net_device*);
void Sniffer_Cleanup_Module(void);
static int Sniffer_xmit(struct sk_buff*,struct net_device*);
int Sniffer_func(struct sk_buff*,struct net_device*,struct packet_type*);
struct net_device *sniffer;
struct packet_type *mypkt;
int Sniffer_Init_module(void)
{
int result;
sniffer = alloc_netdev(0,"Sniffer",Sniffer_Init);
if(sniffer == NULL)
goto out;
if((sniffer = register_netdev(sniffer))){
printk(KERN_ALERT "Error %d : network Device Sniffer could not initialized",result);
return result;
}
out: printk(KERN_ALERT "\n Error Initializing the Device");
}
int Sniffer_Init(struct net_device *dev)
{
dev->open = Sniffer_open;
dev->stop = Sniffer_release;
dev->hard_start_xmit= Sniffer_xmit;
printk(KERN_ALERT "Network Device sniffer Initialized");
/*Protocol Handler Registeration*/
mypkt->type = htons(ETH_P_ALL);
mypkt->dev = NULL;
mypkt->func = Sniffer_func;
mypkt->data = NULL;
mypkt->next = NULL;
dev_add_pack(&mypkt);
return 0;
}
int Sniffer_open(struct net_device *dev)
{
printk(KERN_ALERT "Network Device sniffer is UP");
netif_start_queue(dev);
return 0;
}
int Sniffer_release(struct net_device *dev)
{
printk(KERN_ALERT "Network Device sniffer Closed \n");
netif_stop_queue(dev);
return 0;
}
int Sniffer_func(struct sk_buff *skb,struct net_device *dev,struct packet_type *pkt)
{
/* ?????? what to write here ?????? */
/*How to redirect the traffic to virtual device*/
}
void Sniffer_Cleanup_Module(void)
{
printk(KERN_ALERT "Network Device sniffer Uninitialized\n");
unregister_netdev(&sniffer);
}
module_init (Sniffer_Init_Module);
module_exit (Sniffer_Cleanup_Module);
-- INSERT --