changeset 64:6a3a917303e4

Some random cleanups, bring back WinSock support.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 Nov 2008 22:33:35 +0200
parents afd90bbb3af6
children e763ef5cfd53
files Makefile.w32 libnnchat.c libnnchat.h nnchat.c
diffstat 4 files changed, 32 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile.w32	Tue Nov 11 22:06:07 2008 +0200
+++ b/Makefile.w32	Tue Nov 11 22:33:35 2008 +0200
@@ -1,14 +1,14 @@
 #
 # For win32 version cross-compilation with MiNGW suite @ Linux
 #
-PATH=/usr/local/cross-tools/i386-mingw32/bin:/usr/bin:/bin
+PATH=/usr/local/i386-mingw32/bin:/usr/bin:/bin
 PREFIX=./win32/
 BINPATH=./win32/
 
 # C-compiler, flags and linker flags
 CC=gcc
 CFLAGS=-DHAVE_STRING_H
-LDFLAGS=-L/usr/local/cross-tools/lib -liberty -lws2_32 -s
+LDFLAGS=-L/usr/local/i386-mingw32/lib/ -liberty -lws2_32 -s
 
 # Miscellaneous
 RM=rm
--- a/libnnchat.c	Tue Nov 11 22:06:07 2008 +0200
+++ b/libnnchat.c	Tue Nov 11 22:33:35 2008 +0200
@@ -51,7 +51,11 @@
 void closeConnection(const int sock)
 {
 	if (sock >= 0) {
+#ifdef __WIN32
+		closesocket(sock);
+#else
 		close(sock);
+#endif
 	}
 }
 
--- a/libnnchat.h	Tue Nov 11 22:06:07 2008 +0200
+++ b/libnnchat.h	Tue Nov 11 22:33:35 2008 +0200
@@ -8,11 +8,16 @@
 
 #include <stdio.h>
 #include <unistd.h>
+#ifdef __WIN32
+#warning Compiling for Windows
+#include <winsock.h>
+#else
 #include <sys/socket.h>
-#include <sys/types.h>
 #include <arpa/inet.h>
-#include <sys/time.h>
 #include <netdb.h>
+#endif
+#include <sys/types.h>
+
 #include <errno.h>
 #include "th_string.h"
 
--- a/nnchat.c	Tue Nov 11 22:06:07 2008 +0200
+++ b/nnchat.c	Tue Nov 11 22:33:35 2008 +0200
@@ -9,7 +9,11 @@
 #include <string.h>
 #include <errno.h>
 #include <time.h>
+#ifdef __WIN32
+#include <curses.h>
+#else
 #include <ncurses.h>
+#endif
 
 
 #define SET_MAX_BACKBUF (1024)
@@ -492,8 +496,7 @@
 		BOOL isMine = strcmp(p, optUserName) == 0;
 		t = stripXMLTags(s);
 		h = decodeStr2(t);
-		printMsg("½5½<½%d½%s½5½>½%d½ %s½0½\n",
-			isMine ? 14 : 15, p, isMine ? 16 : 0, h);
+		printMsg("½5½<½%d½%s½5½>½0½ %s\n", isMine ? 14 : 15, p, h);
 		th_free(h);
 		th_free(t);
 	}
@@ -741,7 +744,19 @@
 	
 	if (!argsOK)
 		return -2;
-	
+
+
+#ifdef __WIN32
+	{
+	/* Initialize WinSock, if needed */
+	WSADATA wsaData;
+	int err = WSAStartup(0x0200, &wsaData);
+	if (err != 0) {
+		THERR("Could not initialize WinSock DLL: %d\n", err);
+		return -3;
+    }
+#endif
+
 	/* Open logfile */
 	if (optLogFilename) {
 		THMSG(1, "Opening logfile '%s'\n", optLogFilename);
@@ -777,7 +792,7 @@
 		goto err_exit;
 	} else {
 		ssize_t gotBuf;
-		char tmpBuf[4096];
+		char tmpBuf[SET_BUFSIZE];
 		gotBuf = recv(tmpSocket, tmpBuf, sizeof(tmpBuf), 0);
 		tmpBuf[gotBuf-1] = 0;
 		THMSG(2, "Probe got: %s\n", tmpBuf);