in reply to How to use Inline::C properly

It looks to me like you're trying to treat a string containing an IP address ("192.168.1.1") as an integer:

   src_add  = inet_addr(SvIVX(Inline_Stack_Item(1)));

That takes the first stack item, the SVPV "192.168.1.1", and tries to treat it as an integer by calling SvIVX on it. It's not an integer, so this won't work. I'm not sure if it returns garbage or 0 or what, but it certainly can't be what you want!

-sam

Replies are listed 'Best First'.
Re^2: How to use Inline::C properly
by macli (Beadle) on Mar 07, 2007 at 00:05 UTC
    No, it is not what I want.:)
    I just could not figure out which api I should use. after reading the man page, I still got no clue :(

      src_add  = inet_addr(SvIVX(Inline_Stack_Item(1)));
      should be
      src_add  = inet_addr(SvPVX(Inline_Stack_Item(1)));

      Same for dst_add.

        Hi ikegami, Thanks for replying again, I looked it up in the perlapi:

        SvPVX Returns a pointer to the physical string in the SV. The SV must contain a string.

        seems the right api, but it still failes with the same error

        As I am new to perl, and C, There is too much I need to know, I am going to step back and learn from the basics :) I will just leave this problem alone for a while.

      Why expose yourself to these Perl internals if you don't need to (besides instructional reasons)?

      int p0fq(SV* name1, ...)

      is a bit of a messy signature (since you have to manually pull things off the stack later. Why not try

      int p0fq(char* socket, char* src_ip, int src_port, char * dst_ip, int dst_port)

      Inline will handle the ugly glue for you :)

      UPDATE change char* dst_port to int dst_port. Thanks to Util for catching that.

        I tried your suggestion, it has type declaration conflicts error because the type defined in header types.h are different for src_ip,src_port...
        I even tried the same type declared in types.h as:
        int p0fq(_s32 p0f_socket, _u32 src_ip, _u16 s_port, _u32 dst_ip, _u16 +d_port)

        Perl complains that the p0fq funcion not defined.I will just leave this problem alone for a while before I gain more knowledge about Perl and C, thanks :)