#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <clamav.h>
int main(int argc, char **argv)
{
int fd, ret, no = 0;
unsigned long int size = 0;
long double mb;
const char *virname;
struct cl_node *root = NULL;
struct cl_limits limits;
if(argc != 2) {
printf("Usage: %s file\n", argv[0]);
exit(2);
}
if((fd = open(argv[1], O_RDONLY)) == -1) {
printf("Can't open file %s\n", argv[1]);
exit(2);
}
if((ret = cl_loaddbdir(cl_retdbdir(), &root, &no))) {
printf("cl_loaddbdir: %s\n", cl_perror(ret));
close(fd);
exit(2);
}
printf("Loaded %d signatures.\n", no);
if((ret = cl_build(root))) {
printf("Database initialization error: %s\n", cl_strerror(ret));;
cl_free(root);
close(fd);
exit(2);
}
memset(&limits, 0, sizeof(struct cl_limits));
limits.maxfiles = 1000;
limits.maxfilesize = 10 * 1048576;
limits.maxreclevel = 5;
limits.maxratio = 200;
limits.archivememlim = 0;
if((ret = cl_scandesc(fd, &virname, &size, root, &limits, CL_SCAN_STDOPT)) == CL_VIRUS)
printf("Virus detected: %s\n", virname);
else {
printf("No virus detected.\n");
if(ret != CL_CLEAN)
printf("Error: %s\n", cl_perror(ret));
}
close(fd);
mb = size * (CL_COUNT_PRECISION / 1024) / 1024.0;
printf("Data scanned: %2.2Lf Mb\n", mb);
cl_free(root);
exit(ret == CL_VIRUS ? 1 : 0);
}