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 12-30-2007, 06:13 PM   #1
Sarfraz
LQ Newbie
 
Registered: Dec 2007
Posts: 1

Rep: Reputation: 0
Angry whats wrong with this module


I am writing a module for getting the udp packets @ kernel level. I am running the following code by using virtual Linux Kernel for debugging purpose(using uml script...). Whats wrong with this


----------------------------------------------


#define __LITTLE_ENDIAN_BITFIELD
#include <linux/ip.h>
#include <linux/kernel.h>
#include <linux/signal.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/if_arp.h>
#include <linux/skbuff.h>
#include <linux/udp.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/tty.h>
#include <linux/version.h>
#include <linux/slab.h>
#include <linux/list.h>
#include <linux/workqueue.h>


#define E_INVALID_ARGS -1
#define E_OUT_OF_MEMORY -2

#define MAX_KEY_LEN 20
#define MAX_VALUE_LEN 20

MODULE_LICENSE("GPL");

static struct nf_hook_ops netfilter_ops;
unsigned char *port = "\x13\x8d";

struct udphdr *udp_header;
struct tty_struct *my_tty = NULL;
static int pkts = 0;
struct workqueue_struct *knfd_wq;
static char *interface = "lo";
struct sk_buff *sock_buff;

extern __sum16 skb_checksum_complete(struct sk_buff *skb);

unsigned int main_hook(unsigned int hooknum,
struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff*))
{

struct sk_buff *sock_buff = *skb;
//struct Tupple* t = ethernet_packet_parser(*skb);


printk(KERN_ALERT"i m in the start\n");


if(!sock_buff){ return NF_ACCEPT;}
//if(!(sock_buff->nh.iph)){ return NF_ACCEPT;}

if(sock_buff->protocol!=17)
{
printk(KERN_ALERT"i m out , protcol: %d \n",sock_buff->protocol);
return NF_ACCEPT;
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
///////////////// PROBLEM PROBLEM PROBLEM PROBLEM ///////////
///// I never reach there Even i send UDP packets
/////// to my machine... ///////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

printk(KERN_ALERT"\n\ni got it \r\n");

return 0;

}

int init_module()
{
printk(KERN_ALERT"init_module called\r\n");
netfilter_ops.hook = main_hook;
netfilter_ops.pf = PF_INET;
netfilter_ops.hooknum = NF_IP_PRE_ROUTING;
netfilter_ops.priority = NF_IP_PRI_FIRST;
nf_register_hook(&netfilter_ops);

printk(KERN_ALERT"Module loaded\n\r");
net_enable_timestamp();

return 0;
}
 
  


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
What is this, whats wrong w/ me? colinstu General 11 12-19-2006 06:50 AM
whats wrong with my sound? HNjerry Linux - Software 0 03-02-2004 11:12 AM
Whats wrong with my network? erik_wout_ew2 Linux - Networking 13 11-13-2003 10:50 AM
Whats wrong with this? OlRoy Programming 2 05-28-2003 01:21 PM

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

All times are GMT -5. The time now is 03:08 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