All of lore.kernel.org
 help / color / mirror / Atom feed
* printing packet data
@ 2004-12-22  2:50 linux lover
  2004-12-22 13:54 ` Lukas Ruf
  2004-12-23  2:49 ` linux lover
  0 siblings, 2 replies; 3+ messages in thread
From: linux lover @ 2004-12-22  2:50 UTC (permalink / raw)
  To: kernelnewbies; +Cc: netfilter-devel

Hi all,
I want to print skb->data contents in kernel module using netfilter module at
NF_HOOK NF_IP_LOCAL_OUT. How can i do that? I know how to write netfilter
module like this one
#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>

          static struct nf_hook_ops nfho1;
          static unsigned char *packet_ip = "\x7f\x00\x00\x0b";

          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");
                if (sb->nh.iph->saddr == *(unsigned int *)packet_ip)
                 {
 /*CODE REQUIRE TO BE INCLUDED HERE*/
                  return NF_ACCEPT;
          }
               else
                    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");

But how can i print those HEX codes in packet?
regards,
linux.lover

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: printing packet data
  2004-12-22  2:50 printing packet data linux lover
@ 2004-12-22 13:54 ` Lukas Ruf
  2004-12-23  2:49 ` linux lover
  1 sibling, 0 replies; 3+ messages in thread
From: Lukas Ruf @ 2004-12-22 13:54 UTC (permalink / raw)
  To: linux lover; +Cc: Kernel Newbies, netfilter development

> linux lover <linux.lover2004@gmail.com> [2004-12-22 13:54]:
>
> But how can i print those HEX codes in packet?  regards, linux.lover

simply make use of printk() and print the content of the packet.

wbr,
Lukas
-- 
Lukas Ruf           | Wanna know anything about raw |
<http://www.lpr.ch> | IP? -> <http://www.rawip.org> |
eMail Style Guide: <http://www.rawip.org/style.html>|

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: printing packet data
  2004-12-22  2:50 printing packet data linux lover
  2004-12-22 13:54 ` Lukas Ruf
@ 2004-12-23  2:49 ` linux lover
  1 sibling, 0 replies; 3+ messages in thread
From: linux lover @ 2004-12-23  2:49 UTC (permalink / raw)
  To: kernelnewbies; +Cc: netfilter-devel

Hello Lukas,
            As you said i  use following printk with for loop and
included at hook_func1.
 for (i=0;i<5;i++)
    printk(KERN_DEBUG"Packet data is %02x\t",sb->data[i]);
But i am not getting any output in /var/log/messages. Where am i
wrong? I specified to print only 5 chars at start to check whether i
can get packet dump or not?
         What else should i include in module code i posted already
with above lines?
regards,
linux.lover

On Wed, 22 Dec 2004 08:20:42 +0530, linux lover
<linux.lover2004@gmail.com> wrote:
> Hi all,
> I want to print skb->data contents in kernel module using netfilter module at
> NF_HOOK NF_IP_LOCAL_OUT. How can i do that? I know how to write netfilter
> module like this one
> #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>
> 
>           static struct nf_hook_ops nfho1;
>           static unsigned char *packet_ip = "\x7f\x00\x00\x0b";
> 
>           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");
>                 if (sb->nh.iph->saddr == *(unsigned int *)packet_ip)
>                  {
>  /*CODE REQUIRE TO BE INCLUDED HERE*/
>                   return NF_ACCEPT;
>           }
>                else
>                     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");
> 
> But how can i print those HEX codes in packet?
> regards,
> linux.lover
>

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-12-23  2:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-12-22  2:50 printing packet data linux lover
2004-12-22 13:54 ` Lukas Ruf
2004-12-23  2:49 ` linux lover

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.