Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: How to use Inline::C properly

by geekphilosopher (Friar)
on Mar 07, 2007 at 02:48 UTC ( [id://603555]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^4: How to use Inline::C properly
by macli (Beadle) on Mar 07, 2007 at 18:56 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://603555]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2024-04-24 04:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found