problem with netfilter hook function struct skbuff *sock is null..

Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users problem with netfilter hook function struct skbuff *sock is null..
# 1  
Old 11-09-2009
problem with netfilter hook function struct skbuff *sock is null..

iam trying to built a i have used netfilter for it.
in function main_hook sock_buff is returning null and in my log file continuously "sock buff null" is printed plse help to solve this problem..
(using print_string iam printing strings on current terminal (terminal we ping))

#include <linux/ip.h>  
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/netdevice.h>
#include <linux/init.h>
#include <linux/sched.h>	
#include <linux/tty.h>		
#include <linux/version.h> 
#include <linux/in.h>
# define NF_IP_PRE_ROUTING 0  
static struct nf_hook_ops netfilter_ops_in; 
struct sk_buff *sock_buff;
struct iphdr *ipptr;
static void print_string(char *str)
	struct tty_struct *my_tty;
        my_tty = current->signal->tty;

	if (my_tty != NULL) {

		((my_tty->driver)->ops->write) (my_tty,str,strlen(str));	

		((my_tty->driver)->ops->write) (my_tty, "\015\012", 2);

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*))
    sock_buff = *skb;
    if(!sock_buff){ printk("sock buff null\n"); return NF_ACCEPT; }
    printk(KERN_ALERT "sockbuff is not zero\n");
    ipptr=(struct iphdr *)skb_network_header(sock_buff);                   
            printk(KERN_ALERT "ipptr is ZERO\n"); 
            return NF_ACCEPT; 
    if(ipptr->saddr == in_aton(""))
         print_string("packet dropped(\n");             
         return NF_DROP; 
    return NF_ACCEPT;
int init_module()
        netfilter_ops_in.hook                   =       (nf_hookfn *)main_hook;                     =       PF_INET;
        netfilter_ops_in.hooknum                =       NF_IP_PRE_ROUTING;
        netfilter_ops_in.priority               =       NF_IP_PRI_FIRST;
        printk("firewall Setuped\n");
return 0;
void cleanup()
nf_unregister_hook(&netfilter_ops_in); /*unregister NF_IP_PRE_ROUTING hook*/


# 2  
Old 01-21-2010
Hammer & Screwdriver Re: problem with netfilter hook function struct skbuff *sock is null..



the parameters vary a mong the linux versions:

with the linux versions >= 2,6,20 , the declaration of hook function must be : hookf(......., struct sk_buff *skb) , that means ONLY one asterisk.


Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Malloc function returning NULL

Hi All, I am using malloc function for allocating dynamic memory. When I am using below code on Linux server its working fine, but When I am trying the same code on HP UNIX server its returning NULL. below is a fragment of code in which it is giving problem. tmp = (format_tree... (4 Replies)
Discussion started by: Taher Saifuddin
4 Replies

2. Programming

Implementing function outside struct

I have this code where I have declared a struct with some functions. Trying to write the function implementation outside the struct declaration and do not know how to proceed. #ifndef ParseEl_hh #define ParseEl_hh #include <iostream> #include <fstream> #include "DynBaseObj.hh"... (7 Replies)
Discussion started by: kristinu
7 Replies

3. Programming

Storing C++-struct in file - problem when adding new item in struct

Hi, I have received an application that stores some properties in a file. The existing struct looks like this: struct TData { UINT uSizeIncludingStrings; // copy of Telnet data struct UINT uSize; // basic properties: TCHAR szHost; //defined in Sshconfig UINT iPortNr; TCHAR... (2 Replies)
Discussion started by: Powerponken
2 Replies

4. Programming

Problem with implementing the times() function in C (struct tms times return zero/negative values)

Hello, i'm trying to implement the times() function and i'm programming in C. I'm using the "struct tms" structure which consists of the fields: The tms_utime structure member is the CPU time charged for the execution of user instructions of the calling process. The tms_stime structure... (1 Reply)
Discussion started by: g_p
1 Replies

5. Programming

Problem defining a struct

I have the following code and getting the compilation errors baseLib/DynBaseObj.h:80: error: expected constructor, destructor, or type conversion before (' token baseLib/DynBaseObj.h:89: error: expected constructor, destructor, or type conversion before (' token baseLib/DynBaseObj.h:101:... (0 Replies)
Discussion started by: kristinu
0 Replies

6. Shell Programming and Scripting

converting from c struct to function

Hey Guys, I need your help where I have a C structure and I want it to be converted into corresponding function. Example: typedef struct { unsigned long LineNum; //1025-4032 unsigned short KeyNum; /*tbd*/ char Key; /*between 1-3*/... (1 Reply)
Discussion started by: skyos
1 Replies

7. Programming

http sock problem

hi am senthil am doing my server-client prog in C++ to send and receive sms through the API .. in which server is a webserver(remote server) and my prog act as a client.. i will form a url based on the HTTP 1.0 protocol.. and hit the server through socket send funtion.. by hitting the... (1 Reply)
Discussion started by: senkerth
1 Replies

8. Programming

Problem accessing struct member

I have a struct as follows... struct A { int a; ucontext_t X; //ucontext_t is another structure } How do I define a pointer to the above structure variable X of the type ucontext_t from within another function? eg. void foo() { struct A a; /////WHAT COMES IN... (1 Reply)
Discussion started by: jacques83
1 Replies

9. Programming

struct tm problem

I receive an integer as argument for a function. within function definition i want it to be of type struct tm. eg.. main() { int a; ...... } function(...,..,a,..) int a; { struct tm tm; if(!a) ^ time(&a); ^ ... (4 Replies)
Discussion started by: bankpro
4 Replies

10. Programming

Problem in registering new netfilter target module

Friends I'm facing a big problem trying to extend the netfilter. Somone please help me with your quick reply (any hint) as I've to meet a deadline. My problem is that I've written a new netfilter target module and its corresponding userspace program for iptables to change the packet type of a... (0 Replies)
Discussion started by: Rakesh Ranjan
0 Replies
Login or Register to Ask a Question