All of lore.kernel.org
 help / color / mirror / Atom feed
* Pb for get target info
@ 2004-02-28 12:36 Frédéric Massot
  0 siblings, 0 replies; only message in thread
From: Frédéric Massot @ 2004-02-28 12:36 UTC (permalink / raw)
  To: netfilter-devel

Hello,

I write a C program (libiptc 1.2.9) which lists the rules using the MARK
target.

The list returned by the program must contain the value of the mark
(setting with --set-mark) and the values of the counters.

For the moment, I list the values of the counters for the rules which 
use the MARK target, but I block to read the value of the MARK.

I took as a starting point the sources of the programs iptables and
iptables-save, and I block on the strange function "find_target".

Can you help me, please ?
Best regards.

Below the source code of the program.

PS: If the developers of the libiptc read me, would be a good idea to 
have a function "iptc_get_target_info" which returned the target 
information.


<---------SOURCE CODE--------------->

#include <stdio.h>
#include <libiptc.h>
#include <iptables.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

int
main(void)
{
   iptc_handle_t h;
   const char *chain = NULL;
   const struct ipt_entry *e;
   const char *target_name;
   struct iptables_target *target = NULL;
   const struct ipt_entry_target *t;

   h = iptc_init("mangle");
   if(!h)
   {
     fprintf(stderr, "Can't initialize: %s\n", iptc_strerror(errno));
     return EXIT_FAILURE;
   }

   for (chain = iptc_first_chain(&h);
        chain; chain = iptc_next_chain(&h))
   {
     e = iptc_first_rule(chain, &h);

     while(e)
     {
       t = ipt_get_target((struct ipt_entry *)e);

       if (!iptc_is_chain(chain, h))
       	target = find_target(chain, TRY_LOAD);
       else
	target = find_target(IPT_STANDARD_TARGET,
                      LOAD_MUST_SUCCEED);

       target_name = iptc_get_target(e, &h);
       if (target_name &&
           (strncmp(target_name, "MARK", strlen("MARK")) == 0))		      {
         printf("%s - ", target_name);
         printf("[%llu:%llu]\n", e->counters.pcnt,
  			        e->counters.bcnt);
         if(target->print) target->print(&e->ip, t, 0x0041);
       }
       e = iptc_next_rule(e, &h);
     }
   }

   iptc_free(&h);
   return EXIT_SUCCESS;
}



-- 
==============================================
|              FREDERIC MASSOT               |
|     http://www.juliana-multimedia.com      |
|   mailto:frederic@juliana-multimedia.com   |
===========================Debian=GNU/Linux===

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-02-28 12:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-28 12:36 Pb for get target info Frédéric Massot

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.