in reply to Re: How to use Inline::C properly
in thread How to use Inline::C properly

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 :(

Replies are listed 'Best First'.
Re^3: How to use Inline::C properly
by ikegami (Patriarch) on Mar 07, 2007 at 01:29 UTC

    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.

Re^3: How to use Inline::C properly
by geekphilosopher (Friar) on Mar 07, 2007 at 02:48 UTC

    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 :)

        I think you're right to take a step back and learn some basic Perl and C before trying to tackle this one. When you do get back to it, here's a hint: you need to convert the string representation of an IP "192.168.1.1", which is a char * (or SVPV, in Perl) into the packed 32-bit integer representation (_u32). I've seen this done a few different ways - usually it means breaking up the string into 4 individual bytes and then packing them into a single 4-byte (32-bit) integer, using bit-math or sometimes a union.

        -sam