[prev in list] [next in list] [prev in thread] [next in thread] 

List:       netfilter-devel
Subject:    Is my program is correct to print packet data part at IP layer?
From:       linux lover <linux_lover2004 () yahoo ! com>
Date:       2004-12-31 12:13:03
Message-ID: 20041231121303.59844.qmail () web52204 ! mail ! yahoo ! com
[Download RAW message or body]

Respected sir,
            I request you to please check my program
and reply me whether it is the correct way of getting
packets data part at IP layer? I am using netfilter
and dumping its output to unsigned string. I just want
to know the results return by following program is
correct or wrong?
regards,
linux_lover.

#define MODULE
#define __KERNEL__

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>

#include <linux/string.h>

static struct nf_hook_ops nfho1;

unsigned int hook_func1(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 *sb = *skb;
  printk(KERN_DEBUG "calling hook_func at
NF_IP_LOCAL_OUT\n");
      unsigned char *packet;
      unsigned int buflen;
      int  i=0;
      buflen=sb->len;
      packet=kmalloc(buflen,GFP_USER);
      memset(packet,'\0',buflen);
      printk(KERN_DEBUG "Length of skb->data in hook
function = %d\n", buflen);
      strncpy(packet,sb->data,buflen);
      printk(KERN_DEBUG "packet contents of sb->data
in hook function = %02x\n", packet);

     return NF_ACCEPT;
}

static int __init init(void)   
  {
              nfho1.hook     = hook_func1;
              nfho1.hooknum  = NF_IP_LOCAL_OUT;
              nfho1.pf       = PF_INET;
              nfho1.priority = NF_IP_PRI_FIRST;
              nf_register_hook(&nfho1);
              return 0;
          }

static void __exit fini(void)
          {
              nf_unregister_hook(&nfho1);
          }
module_init(init);
module_exit(fini);
MODULE_LICENSE("GPL");




		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - What will yours do?
http://my.yahoo.com 

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic