All of lore.kernel.org
 help / color / mirror / Atom feed
* failed loading SNAT and DNAT library
       [not found] <20030114141102.14779.87181.Mailman@kashyyyk>
@ 2003-01-14 15:44 ` nickolay
  2003-01-16 19:12   ` Laszlo Valko
  0 siblings, 1 reply; 2+ messages in thread
From: nickolay @ 2003-01-14 15:44 UTC (permalink / raw)
  To: netfilter-devel

Hi Guys!

I'm newbe to developing netfilter code and i have some troubles 
with it. I need to working with SNAT and DNAT target rules in my 
new project, but when i trying load shared librarys libipt_SNAT.so 
for SNAT or libipt_DNAT.so for DNAT targets with dlopen(), program
executing is stopped on dlopen() call with next error:
/usr/local/lib/iptables/libipt_SNAT.so: undefined symbol: dotted_to_addr.
Compile step:
cc iptest.c -ldl -liptc -o myprog

Below i preview some major program code, please help me resolve trouble:

#include <getopt.h>
#include <sys/errno.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <dlfcn.h>
#include <time.h>
#include "/usr/local/include/libiptc/libiptc.h"
#include "/usr/local/include/iptables.h"

int main(void)
{
    iptc_handle_t h;
    const struct ipt_entry *e;
    const struct ipt_entry_target *eTarget;
    struct iptables_target *target;
    const char *chain = NULL;
    const char *tablename = "nat";
    const char *cname = NULL;
    char path[] = "/usr/local/lib/iptables/libipt_SNAT.so";
    void *ldhandler;

    if((h = iptc_init(tablename)) == NULL) {
        fprintf(stderr, "error: iptc_init() failed: %s\n", iptc_strerror(errno));
        exit(1);
    }

    for(cname = iptc_first_chain(&h); cname; cname = iptc_next_chain(&h)) {
        for(e = iptc_first_rule(cname, &h); e; e = iptc_next_rule(e, &h)) {
            eTarget = ipt_get_target((struct ipt_entry*)e);
            printf("-----------------\n");
            printf(":%s\n", eTarget->u.user.name);
            ldhandler = dlopen(path, RTLD_NOW);
            if(!ldhandler) {
                fprintf(stderr, "%s\n", dlerror());
                exit(1);
            }
        }
    }

} /* main */

--
Nickolay
nickolay@protei.ru

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

* Re: failed loading SNAT and DNAT library
  2003-01-14 15:44 ` failed loading SNAT and DNAT library nickolay
@ 2003-01-16 19:12   ` Laszlo Valko
  0 siblings, 0 replies; 2+ messages in thread
From: Laszlo Valko @ 2003-01-16 19:12 UTC (permalink / raw)
  To: nickolay; +Cc: netfilter-devel

On Tue, Jan 14, 2003 at 06:44:57PM +0300, nickolay@protei.ru wrote:
> Hi Guys!
> 
> I'm newbe to developing netfilter code and i have some troubles 
> with it. I need to working with SNAT and DNAT target rules in my 
> new project, but when i trying load shared librarys libipt_SNAT.so 
> for SNAT or libipt_DNAT.so for DNAT targets with dlopen(), program
> executing is stopped on dlopen() call with next error:
> /usr/local/lib/iptables/libipt_SNAT.so: undefined symbol: dotted_to_addr.
> Compile step:
> cc iptest.c -ldl -liptc -o myprog

Basically, you would have to export symbols from the main program (myprog)
so that the modules to be loaded can resolve symbols from the libiptc.a

Check out iptables makefiles. There's an extra -rdynamic argument to cc,
which will in turn add -export-dynamic to ld:

       -export-dynamic
              When  creating  an ELF file, add all symbols to the
              dynamic symbol table.  Normally, the dynamic symbol
              table contains only symbols which are used by a dy-
              namic object.  This option is needed for some  uses
              of dlopen.

This should do it for you.

Laszlo

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

end of thread, other threads:[~2003-01-16 19:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20030114141102.14779.87181.Mailman@kashyyyk>
2003-01-14 15:44 ` failed loading SNAT and DNAT library nickolay
2003-01-16 19:12   ` Laszlo Valko

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.