in reply to another core dump

With either BrowserUK's fixes alone, or my fixes alone does not work, but put them together it works now. It has been working for half hour already, with I using intensively all the time, and there is no core.

I am now using low level socket instead of IO::Socket::INET, without this fix, it still cores, but I now tend to believe that's also because of memory usage, as IO::Socket::INET creates more overhead.

If you monitor what some of those sites are downloading without your notice, you will be surprised...Wow!

Thanks BrowserUK and his long posts as he does always ;-P

use threads; use strict; use warnings; my $banned_type = { "cab" => 1, "class" => 1, "dat" => 1, "exe" => 1, "gif" => 1, "js" => 1, "swf" => 1 }; my $banned_site = { "ad.doubleclick.net" => 1, "search-itnow.com" => 1, "www.ftstock.com" => 1, "www.newshub.com" => 1 }; use constant RES_400 => "HTTP/1.1 400 Bad Request\r\n\r\n"; my $proto = getprotobyname('tcp'); socket(BROWSER_LISTENER, PF_INET, SOCK_STREAM, $proto) || die "Failed +to create socket: $!"; setsockopt(BROWSER_LISTENER, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) | +| die "Failed to setsockopt: $!"; bind(BROWSER_LISTENER, sockaddr_in(8080, INADDR_ANY)) || die "Failed t +o bind: $!"; listen(BROWSER_LISTENER, SOMAXCONN) || die "Failed to listen: $!"; print "Internet filter started\n"; while (1) { my $browser; accept($browser, BROWSER_LISTENER); my $req; sysread($browser, $req, 10000); my $host = ($req =~ m/Host:\s*(.*?)\r/)[0]; my $page = ($req =~ m/^(?:GET|POST|HEAD)\s*(.*?)\s/)[0]; print "Received request for [$host, $page]\n"; if ($host && $page) { if (is_banned_site($host) || is_banned_type($page)) { print "[$host, $page] is banned\n"; print $browser RES_400; close($browser); } else { my $tid = threads->create(\&process_one_req, $browser, $re +q, $host)->detach(); } } else { close($browser); } } sub process_one_req { my ($browser, $req, $host) = @_; my $iaddr = inet_aton($host) || die "no host: $host"; my $paddr = sockaddr_in(80, $iaddr); $proto = getprotobyname('tcp'); my $remote; socket($remote, PF_INET, SOCK_STREAM, $proto) || die "socket: $!"; connect($remote, $paddr) || die "connect: $!"; print $remote $req; my $chunk; while (sysread($remote, $chunk, 10000)) { print $browser $chunk; debug($chunk) if ($req =~ m/^POST/); } close($remote); undef($remote); close($browser); undef($browser); undef($req); undef($host); } sub is_banned_site { my $site = shift; return 1 if (exists($banned_site->{$site})); if ($site =~ m/offeroptimizer/) { return 1; } if ($site =~ m/revenue.net$/) { return 1; } if ($site =~ m/popupsponsor.com$/) { return 1; } if ($site =~ m/hitbox.com$/) { return 1; } return 0; } sub is_banned_type { return (exists($banned_type->{(split(/\./, shift))[-1]})) ? 1 : 0; }