git-svn: trunk@4362
Török Edvin authored on 2008/11/10 07:04:22... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Sun Nov 9 22:37:29 EET 2008 (edwin) |
|
2 |
+------------------------------------ |
|
3 |
+ * contrib/clamdtop/Makefile, contrib/clamdtop/clamdtop.c: clamdtop: |
|
4 |
+ Apply mingw32 patches from Gianluigi Tiesi <sherpya*netfarm.it> |
|
5 |
+ |
|
1 | 6 |
Sat Nov 8 17:24:59 EET 2008 (edwin) |
2 | 7 |
------------------------------------ |
3 | 8 |
* libclamav/blob.h, libclamav/cab.h, libclamav/jsparse/js-norm.c: |
... | ... |
@@ -1,9 +1,17 @@ |
1 | 1 |
CFLAGS=-O2 -g -Wall -W -Wshadow |
2 | 2 |
CC=gcc |
3 |
-OBJS= clamdtop.o |
|
3 |
+OBJS=clamdtop.o |
|
4 |
+LDFLAGS= |
|
5 |
+CPPFLAGS= |
|
6 |
+ |
|
7 |
+ifeq ($(MSYSTEM),MINGW32) |
|
8 |
+LIBS=-lpdcurses -lws2_32 |
|
9 |
+else |
|
10 |
+LIBS=-lncurses |
|
11 |
+endif |
|
4 | 12 |
|
5 | 13 |
clamdtop: $(OBJS) Makefile |
6 |
- $(CC) $(CFLAGS) $(OBJS) -lncurses -o $@ |
|
14 |
+ $(CC) $(CPPFLAGS) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS) |
|
7 | 15 |
|
8 | 16 |
clean: |
9 | 17 |
rm -f clamdtop $(OBJS) |
... | ... |
@@ -29,11 +29,18 @@ |
29 | 29 |
#include <time.h> |
30 | 30 |
#include <ctype.h> |
31 | 31 |
#include <signal.h> |
32 |
+#ifdef _WIN32 |
|
33 |
+#include <windows.h> |
|
34 |
+#include <winsock2.h> |
|
35 |
+/* this is not correct, perhaps winsock errors are not mapped on errno */ |
|
36 |
+#define herror perror |
|
37 |
+#else |
|
32 | 38 |
#include <netdb.h> |
33 | 39 |
#include <arpa/inet.h> |
34 | 40 |
#include <netinet/in.h> |
35 | 41 |
#include <sys/socket.h> |
36 | 42 |
#include <sys/un.h> |
43 |
+#endif |
|
37 | 44 |
#include <sys/time.h> |
38 | 45 |
#include <assert.h> |
39 | 46 |
#include <errno.h> |
... | ... |
@@ -237,8 +244,8 @@ static void show_bar(WINDOW *win, size_t i, unsigned live, unsigned idle, |
237 | 237 |
int y,x; |
238 | 238 |
unsigned len = 47; |
239 | 239 |
unsigned start = 1; |
240 |
- unsigned activ = ((live-idle)*(len - start - 2) + (max/2)) / max; |
|
241 |
- unsigned dim = idle*(len - start - 2) / max; |
|
240 |
+ unsigned activ = max ? ((live-idle)*(len - start - 2) + (max/2)) / max : 0; |
|
241 |
+ unsigned dim = max ? idle*(len - start - 2) / max : 0; |
|
242 | 242 |
unsigned rem = len - activ - dim - start-2; |
243 | 243 |
|
244 | 244 |
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, ...) |
301 | 301 |
static int make_connection(const char *soname, conn_t *conn) |
302 | 302 |
{ |
303 | 303 |
int s; |
304 |
+#ifdef _WIN32 |
|
305 |
+ { |
|
306 |
+#else |
|
304 | 307 |
if(access(soname, F_OK) == 0) { |
305 | 308 |
struct sockaddr_un addr; |
306 | 309 |
s = socket(AF_UNIX, SOCK_STREAM, 0); |
... | ... |
@@ -317,6 +327,7 @@ static int make_connection(const char *soname, conn_t *conn) |
317 | 317 |
return -1; |
318 | 318 |
} |
319 | 319 |
} else { |
320 |
+#endif |
|
320 | 321 |
struct sockaddr_in server; |
321 | 322 |
struct hostent *hp; |
322 | 323 |
unsigned port = 0; |
... | ... |
@@ -584,11 +595,22 @@ int main(int argc, char *argv[]) |
584 | 584 |
fd_set rfds; |
585 | 585 |
struct timeval tv_last, tv; |
586 | 586 |
|
587 |
+#ifdef _WIN32 |
|
588 |
+ WSADATA wsaData; |
|
589 |
+ if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { |
|
590 |
+ fprintf(stderr, "Error at WSAStartup(): %d\n", WSAGetLastError()); |
|
591 |
+ exit(1); |
|
592 |
+ } |
|
593 |
+ |
|
594 |
+ if (make_connection(argc > 1 ? argv[1] : "localhost:3310", &conn) < 0) |
|
595 |
+ exit(2); |
|
596 |
+#else |
|
587 | 597 |
/* TODO: parse clamd.conf */ |
588 | 598 |
if (make_connection(argc > 1 ? argv[1] : "/tmp/clamd.socket", &conn) < 0) |
589 | 599 |
exit(2); |
590 | 600 |
|
591 | 601 |
signal(SIGPIPE, SIG_IGN); |
602 |
+#endif |
|
592 | 603 |
|
593 | 604 |
gettimeofday(&tv_conn, NULL); |
594 | 605 |
send_string(&conn, "SESSION\nVERSION\n"); |