Well, I've got another question.
Now that I've got my code working it would seem I am not doing something as far as deleting connections. I am seeing the memory usage continue to climb with time. I understand that a connection will use an amount of memory equal to it's total size but shouldn't that memory be released back to the pool once I write the file? Am I supposed to delete each connection in my callback after I save it?
I am really just using the example code with a couple lines to save the content as a file.
#!/usr/bin/perl
use strict;
use Net::Pcap;
use Sniffer::HTTP;
my $VERBOSE = 1;
my $sniffer = Sniffer::HTTP->new(
callbacks => {
request => sub { my ($req,$conn) = @_; print $req->uri,"\n" if
+$req },
response => sub { my ($res,$req,$conn) = @_;
print $req->uri,"\n" if ($req);
return if (length $res->content == 0);
(my $filename = $req->uri)=~s/.*\///;
open (FILE,">",$filename);
print FILE $res->content;
close FILE;
},
log => sub { print $_[0] if $VERBOSE },
tcp_log => sub { print $_[0] if $VERBOSE > 1 },
},
timeout => 1*60, # seconds after which a connection is considered st
+ale
stale_connection => sub { my ($s,$conn,$key) = @_;
my %test=%$conn;
$conn->log->("$key is stale.");
$s->remove_connection($key);
},
);
$sniffer->run('eth0'); # uses the "best" default device
I see how the stale_connection callback does this but the request and response callbacks do not get the information that stale_connection uses to delete the connection. Or am I supposed to be creating a new $sniffer->run() for each connection?
I have certainly missed something.
Thanks again for all your help.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.