# HG changeset patch # User Matti Hamalainen # Date 1226435615 -7200 # Node ID 6a3a917303e408af60d0855fe2865f516f214d68 # Parent afd90bbb3af67caedde3df5a3ee5326237f5420b Some random cleanups, bring back WinSock support. diff -r afd90bbb3af6 -r 6a3a917303e4 Makefile.w32 --- 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 diff -r afd90bbb3af6 -r 6a3a917303e4 libnnchat.c --- 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 } } diff -r afd90bbb3af6 -r 6a3a917303e4 libnnchat.h --- 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 #include +#ifdef __WIN32 +#warning Compiling for Windows +#include +#else #include -#include #include -#include #include +#endif +#include + #include #include "th_string.h" diff -r afd90bbb3af6 -r 6a3a917303e4 nnchat.c --- 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 #include #include +#ifdef __WIN32 +#include +#else #include +#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);