#
# ClamAV Daemon
#
use IO::Socket;

if ($clamd) {
    do_log(2,"Using clamd");
    my $sock = IO::Socket::INET->new('127.0.0.1:3310');
    if (defined $sock) {
	$sock->print("SCAN $TEMPDIR/parts\n");
	$sock->flush;
	chomp($output = $sock->getline);
	$sock->close;
	do_log(2,$output);
	if ($output =~ /FOUND$/) {	# no errors, a virus was found
	    $scanner_errors = 0;
	    @virusname = ($output =~ /: (.+) FOUND/g);
	    return 1;  # 'true' indicates virus found and stops further checking
	} elsif ($output =~ /OK$/) {            # no errors, no viruses
	    $scanner_errors = 0;
	} elsif ($output =~ /ERROR$/) {
	    do_log(0,"Virus scanner failure: ScannerDaemon - UNKNOWN STATUS (error code: $output)");
	}
    } else {
	do_log(0,"Virus scanner failure: Clamd - can't connect to daemon");
    }
}
