You show some output, but you don't say what else happened. Did it segfault (trap)? Hang? Just terminate silently?

I've never used Pcap, so anything I say at this point is a guess, but a few things stand out in your code.

  1. You are passing a loop count of 0 to loop().

    The docs say:

    Read $count packets from the packet capture descriptor $pcap and call the perl function &callback with an argument of $user_data. If $count is negative, then the function loops forever or until an error occurs. Returns 0 if $count is exhausted, -1 on error, and -2 if the loop terminated due to a call to pcap_breakloop() before any packets were processed.

    Which suggest to me that if you want to capture 5 seconds of input and then break the loop, you should be passing -1 for the loop count.

  2. Your callback_capture() sub is empty.

    You probably ought to try adding a print statement in there to see a) if you are being call back and b) are you being passed anything.

  3. You should definitely be checking (printing) the returns from the Pcap subs--they might be very informative.

    I'd suggest using warn instead fo print for your debug and trace messages as stderr is unbuffered and you may not be seeing stuff that has been printed to stdout but not yet flushed.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^7: Shared variables between threads by BrowserUk
in thread Shared variables between threads by Saladino

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.