Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 29th, 2010  |  syntax: C  |  size: 0.71 KB  |  views: 113  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <linux/netfilter.h>
  2. #include <linux/netfilter_ipv4.h>
  3.  
  4. static unsigned int my_nf_hookfn(unsigned int hooknum,
  5.                                  struct sk_buff *skb,
  6.                                  const struct net_device *in,
  7.                                  const struct net_device *out,
  8.                                  int (*okfn)(struct sk_buff *))
  9. {
  10.         /* process packet */
  11.         //...
  12.  
  13.         return NF_ACCEPT;
  14. }
  15.  
  16. static struct nf_hook_ops my_nfho = {
  17.         .owner       = THIS_MODULE,
  18.         .hook        = my_nf_hookfn,
  19.         .hooknum     = NF_IP_LOCAL_IN,
  20.         .pf          = PF_INET,
  21.         .priority    = NF_IP_PRI_FIRST
  22. };
  23.  
  24. int __init my_hook_init(void)
  25. {
  26.         return nf_register_hook(&my_nfho);
  27. }
  28.  
  29. void __exit my_hook_exit(void)
  30. {
  31.         nf_unregister_hook(&my_nfho);
  32. }
  33.  
  34. module_init(my_hook_init);
  35. module_exit(my_hook_exit);