LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 08-02-2009, 06:43 AM   #1
gauravholey
Member
 
Registered: May 2009
Posts: 35

Rep: Reputation: 15
How to write Protocol Handler for ETH_P_ALL


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;
        }
outprintk(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_xmitSniffer_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 -- 
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
SIGSEGV handler (segmentation fauld handler) myp Programming 8 03-08-2011 02:17 PM
epiphany external protocol/url handler: can't configure ed2k fbianconi Linux - Desktop 0 07-06-2008 01:23 PM
usb drive "protocol device" - why cannot I write to it? lefty.crupps Linux - Hardware 2 04-28-2005 09:32 PM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 09:47 AM
Howto write FS handler doc anywhere? virtualuk Linux - General 0 10-27-2004 01:30 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 03:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration