Skip to contentSkip to conversation

Just starting with libipq

DISCUSSION Duncan Godfrey 2 participants 3 messages May 5, 2005 – May 6, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

Hello,

I was wondering if someone would be able to help me, Im just starting out with some libipq development and Im trying to compile some example source code from a tutorial site (I have compiled the source on the man page an it worked fine).

Everytime I compile it with gcc -o quick quick.c -libpq, I get the following errors:

quick.c:56: error: dereferencing pointer to incomplete type quick.c:58: error: dereferencing pointer to incomplete type

Has anyone else had a similar experience? Thanks in advance for any help.

Duncan

The code is:

#include <linux/netfilter.h>
#include <libipq.h>
#include <stdio.h>

#define BUFSIZE 2048

static void die(struct ipq_handle *h)
{
ipq_perror("passer");
ipq_destroy_handle(h);
exit(1);
}

int main(int argc, char **argv)
{
int status;
unsigned char buf[BUFSIZE];

struct ipq_handle *h;

h = ipq_create_handle(0, PF_INET);
if (!h)
die(h);

status = ipq_set_mode(h, IPQ_COPY_PACKET, BUFSIZE); if (status < 0)
die(h);

do{

   status = ipq_read(h, buf, BUFSIZE, 0);
   if (status < 0)
     die(h);
                      
   switch (ipq_message_type(buf)) {
   case NLMSG_ERROR:
     fprintf(stderr, "Received error message %d\n",
         ipq_get_msgerr(buf));
     break;
       
   case IPQM_PACKET: {
     ipq_packet_msg_t *m = ipq_get_packet(buf);
     struct iphdr *ip = (struct iphdr*) m->payload;

     struct tcphdr *tcp = (struct tcphdr*) (m->payload + (4 * ip->ihl));
                                
     int port = htons(tcp->dest);       
                             
     status = ipq_set_verdict(h, m->packet_id,
                  NF_ACCEPT, 0, NULL);
     if (status < 0)
   die(h);
     break;

}

default:

     fprintf(stderr, "Unknown message type!\n");
     break;

}
} while (1);

ipq_destroy_handle(h);
return 0;
}

#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoting Duncan Godfrey on 2005-05-05 14:11 UTC:

Quoted 7 lines

I was wondering if someone would be able to help me, Im just starting out with some libipq development and Im trying to compile some example source code from a tutorial site (I have compiled the source on the man page an it worked fine).

Everytime I compile it with gcc -o quick quick.c -libpq, I get the following errors:

- -lipq not -libipq :)

Quoted 6 lines

quick.c:56: error: dereferencing pointer to incomplete type quick.c:58: error: dereferencing pointer to incomplete type

     struct iphdr *ip = (struct iphdr*) m->payload;

     struct tcphdr *tcp = (struct tcphdr*) (m->payload + (4 * ip->ihl));

The error message means gcc does not know of a struct/union that you are using. So it has to be either the "m" variable or then "ip" and "tcp" variables. In this case, it's the latter, you are missing these includes:

#include <linux/ip.h>
#include <linux/tcp.h>

Add them and it should work. Good luck :)

- --
- - xkr47
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCe2gHxyF48ZTvn+4RAjDdAJ0b2SMjV0xh/l84RBDdU4t+ClkjewCdFPhL 9lrHlGEIm1MBp68PkOQYizI=
=n7Wy
-----END PGP SIGNATURE-----

#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoting Jonas Berlin on 2005-05-06 12:50 UTC:

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

quick.c:56: error: dereferencing pointer to incomplete type quick.c:58: error: dereferencing pointer to incomplete type

    struct iphdr *ip = (struct iphdr*) m->payload;

    struct tcphdr *tcp = (struct tcphdr*) (m->payload + (4 * ip->ihl));

Sorry for bad quote, the lines with errors were actually:

      struct tcphdr *tcp = (struct tcphdr*) (m->payload + (4 * ip->ihl));

      int port = htons(tcp->dest);

.. since the error message occurs when using a structure/union, not when
declaring it. Nevertheless, it was just my quote bug, the solution
stays the same :)

- --
- - xkr47
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCe2kCxyF48ZTvn+4RAqcLAKC1lDLBikCu4nnq+3xwtluH8L2v1wCfdhr/ vc8bGniDkxJ8veM9StUFYhA=
=PRXh
-----END PGP SIGNATURE-----