Is Perl really not good at this low level packet handling things?

Any other languages would have the same problem. The reason it's hard it's because p0f uses an undocumented communication format that varies from machine to machine.

I did adjust the bigendian to little endian on PC.

I thought that if you didn't specify one, it would use the machine's native byte order. Are you sure you need to specify the ByteOrder and alignments?

The pack did pack src, dst ip into query , but response always says no connection

IP addresses are usually big endian (i.e. in the same order as in dotted form) on all systems.

01 01 A8 C0
should be
C0 A8 01 01
(192.168.1.1)

Use tag to mark the appropriate fields as big endian. That means you should have:

my $c = Convert::Binary::C->new(); eval { $c->parse_file("p0f-query.h"); 1 } or die("Unable to parse p0f-query.h: $@\n"); $c->tag('p0f_query.src_ad', ByteOrder => 'BigEndian'); $c->tag('p0f_query.dst_ad', ByteOrder => 'BigEndian'); $c->tag('p0f_response.genre', Format => 'String'); $c->tag('p0f_response.detail', Format => 'String'); $c->tag('p0f_response.link', Format => 'String'); $c->tag('p0f_response.tos', Format => 'String');

The port might need to be big endian too.


In reply to Re^19: p0fq.pl and pack by ikegami
in thread p0fq.pl and pack? by macli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.