clamdtop: Apply mingw32 patches from Gianluigi Tiesi <sherpya*netfarm.it>

git-svn: trunk@4362
0.95
Török Edvin 17 years ago
parent 2bbbd2380f
commit ce9368870d
  1. 5
      ChangeLog
  2. 12
      contrib/clamdtop/Makefile
  3. 26
      contrib/clamdtop/clamdtop.c

@ -1,3 +1,8 @@
Sun Nov 9 22:37:29 EET 2008 (edwin)
------------------------------------
* contrib/clamdtop/Makefile, contrib/clamdtop/clamdtop.c: clamdtop:
Apply mingw32 patches from Gianluigi Tiesi <sherpya*netfarm.it>
Sat Nov 8 17:24:59 EET 2008 (edwin)
------------------------------------
* libclamav/blob.h, libclamav/cab.h, libclamav/jsparse/js-norm.c:

@ -1,9 +1,17 @@
CFLAGS=-O2 -g -Wall -W -Wshadow
CC=gcc
OBJS= clamdtop.o
OBJS=clamdtop.o
LDFLAGS=
CPPFLAGS=
ifeq ($(MSYSTEM),MINGW32)
LIBS=-lpdcurses -lws2_32
else
LIBS=-lncurses
endif
clamdtop: $(OBJS) Makefile
$(CC) $(CFLAGS) $(OBJS) -lncurses -o $@
$(CC) $(CPPFLAGS) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS)
clean:
rm -f clamdtop $(OBJS)

@ -29,11 +29,18 @@
#include <time.h>
#include <ctype.h>
#include <signal.h>
#ifdef _WIN32
#include <windows.h>
#include <winsock2.h>
/* this is not correct, perhaps winsock errors are not mapped on errno */
#define herror perror
#else
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/un.h>
#endif
#include <sys/time.h>
#include <assert.h>
#include <errno.h>
@ -237,8 +244,8 @@ static void show_bar(WINDOW *win, size_t i, unsigned live, unsigned idle,
int y,x;
unsigned len = 47;
unsigned start = 1;
unsigned activ = ((live-idle)*(len - start - 2) + (max/2)) / max;
unsigned dim = idle*(len - start - 2) / max;
unsigned activ = max ? ((live-idle)*(len - start - 2) + (max/2)) / max : 0;
unsigned dim = max ? idle*(len - start - 2) / max : 0;
unsigned rem = len - activ - dim - start-2;
assert(activ + 2 < len && activ+dim + 2 < len && activ+dim+rem + 2 < len && "Invalid values");
@ -301,6 +308,9 @@ static void print_con_error(const char *fmt, ...)
static int make_connection(const char *soname, conn_t *conn)
{
int s;
#ifdef _WIN32
{
#else
if(access(soname, F_OK) == 0) {
struct sockaddr_un addr;
s = socket(AF_UNIX, SOCK_STREAM, 0);
@ -317,6 +327,7 @@ static int make_connection(const char *soname, conn_t *conn)
return -1;
}
} else {
#endif
struct sockaddr_in server;
struct hostent *hp;
unsigned port = 0;
@ -584,11 +595,22 @@ int main(int argc, char *argv[])
fd_set rfds;
struct timeval tv_last, tv;
#ifdef _WIN32
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) {
fprintf(stderr, "Error at WSAStartup(): %d\n", WSAGetLastError());
exit(1);
}
if (make_connection(argc > 1 ? argv[1] : "localhost:3310", &conn) < 0)
exit(2);
#else
/* TODO: parse clamd.conf */
if (make_connection(argc > 1 ? argv[1] : "/tmp/clamd.socket", &conn) < 0)
exit(2);
signal(SIGPIPE, SIG_IGN);
#endif
gettimeofday(&tv_conn, NULL);
send_string(&conn, "SESSION\nVERSION\n");

Loading…
Cancel
Save