A simple ClamAV client to stream files to the ClamAV daemon clamd for antivirus scanning.
Please note: The functions ping_socket
and scan_socket
are only available on Unix platforms.
Add this to your Cargo.toml
:
toml
[dependencies]
clamav-client = "0.1.3"
```rust let clamdhostaddress = "localhost:3310";
// Ping clamd to make sure the server is available and accepting TCP connections let clamdavailable = match clamavclient::pingtcp(clamdhostaddress) { Ok(pingresponse) => pingresponse == b"PONG\0", Err() => false, };
if !clamdavailable { println!("Cannot ping clamd at {}", clamdhost_address); return; }
// Scan file for viruses let filepath = "virus.txt"; let scanresponse = clamavclient::scantcp(filepath, clamdhostaddress, None).unwrap(); let fileclean = clamavclient::clean(&scanresponse).unwrap(); if fileclean { println!("No virus found in {}", filepath); } else { println!("The file {} is infected!", file_path); } ```