Index: trunk/ntripclient/ntripclient.c
===================================================================
--- trunk/ntripclient/ntripclient.c	(revision 550)
+++ trunk/ntripclient/ntripclient.c	(revision 579)
@@ -1,5 +1,5 @@
 /*
   Easy example NTRIP client for POSIX.
-  $Id: ntripclient.c,v 1.34 2007/10/08 08:03:19 stoecker Exp $
+  $Id: ntripclient.c,v 1.35 2007/10/26 14:56:47 stuerze Exp $
   Copyright (C) 2003-2005 by Dirk Stoecker <soft@dstoecker.de>
     
@@ -22,15 +22,28 @@
 #include <ctype.h>
 #include <getopt.h>
-#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <errno.h>
 #include <string.h>
-#include <netdb.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
 #include <time.h>
+
+#ifdef WINDOWSVERSION
+  #include <winsock.h>
+  typedef SOCKET sockettype;
+  typedef u_long in_addr_t;
+  typedef size_t socklen_t;
+#else
+  typedef int sockettype;
+  #include <signal.h>
+  #include <fcntl.h>
+  #include <unistd.h>
+  #include <arpa/inet.h>
+  #include <sys/socket.h>
+  #include <netinet/in.h>
+  #include <netdb.h>
+
+  #define closesocket(sock)       close(sock)
+  #define ALARMTIME   (2*60)
+#endif
 
 #ifndef COMPILEDATE
@@ -42,9 +55,8 @@
 
 #define MAXDATASIZE 1000 /* max number of bytes we can get at once */
-#define ALARMTIME   (2*60)
 
 /* CVS revision and version */
-static char revisionstr[] = "$Revision: 1.34 $";
-static char datestr[]     = "$Date: 2007/10/08 08:03:19 $";
+static char revisionstr[] = "$Revision: 1.35 $";
+static char datestr[]     = "$Date: 2007/10/26 14:56:47 $";
 
 enum MODE { HTTP = 1, RTSP = 2, NTRIP1 = 3, AUTO = 4, END };
@@ -63,6 +75,4 @@
   int         mode;
 };
-
-
 
 /* option parsing */
@@ -88,4 +98,6 @@
 #define ARGOPT "-d:m:bhp:r:s:u:n:S:R:M:"
 
+int stop = 0;
+#ifndef WINDOWSVERSION
 #ifdef __GNUC__
 static __attribute__ ((noreturn)) void sighandler_alarm(
@@ -99,5 +111,4 @@
 }
 
-int stop = 0;
 #ifdef __GNUC__
 static void sighandler_int(int sig __attribute__((__unused__)))
@@ -109,4 +120,5 @@
   stop = 1;
 }
+#endif /* WINDOWSVERSION */
 
 static const char *encodeurl(const char *req)
@@ -127,5 +139,5 @@
       *urlenc++ = h[*req >> 4];
       *urlenc++ = h[*req & 0x0f];
-      *req++;
+      req++;
     }
   }
@@ -165,5 +177,5 @@
             *Buffer++ = h[*url >> 4];
             *Buffer++ = h[*url & 0x0f];
-            *url++;
+            url++;
           }      
        }
@@ -433,7 +445,16 @@
   setbuf(stdin, 0);
   setbuf(stderr, 0);
+#ifndef WINDOWSVERSION
   signal(SIGALRM,sighandler_alarm);
   signal(SIGINT,sighandler_int);
   alarm(ALARMTIME);
+#else
+  WSADATA wsaData;
+  if(WSAStartup(MAKEWORD(1,1),&wsaData))
+  {
+    fprintf(stderr, "Could not init network access.\n");
+    return 20;
+  }
+#endif
 
   if(getargs(argc, argv, &args))
@@ -442,5 +463,6 @@
     do
     {
-      int sockfd, numbytes;  
+      sockettype sockfd;
+      int numbytes;  
       char buf[MAXDATASIZE];
       struct sockaddr_in their_addr; /* connector's address information */
@@ -453,5 +475,9 @@
       if(sleeptime)
       {
+#ifdef WINDOWSVERSION
+        Sleep(sleeptime*1000);
+#else
         sleep(sleeptime);
+#endif
         sleeptime += 2;
       }
@@ -460,5 +486,7 @@
         sleeptime = 1;
       }
+#ifndef WINDOWSVERSION
       alarm(ALARMTIME);
+#endif
       if(args.proxyhost)
       {
@@ -681,5 +709,7 @@
                 (struct sockaddr*) &addrRTP, &len)) > 0)
                 {
+#ifndef WINDOWSVERSION
                   alarm(ALARMTIME);
+#endif
                   if(i >= 12+1 && (unsigned char)buf[0] == (2 << 6) && buf[1] == 0x60)
                   {
@@ -820,12 +850,14 @@
           int chunksize = 0;
 
-          while(!stop && (numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) != -1)
+          while(!stop && (numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) > 0)
           {
+#ifndef WINDOWSVERSION
             alarm(ALARMTIME);
+#endif
             if(!k)
             {
               if(numbytes > 17 && (!strncmp(buf, "HTTP/1.1 200 OK\r\n", 17)
               || !strncmp(buf, "HTTP/1.0 200 OK\r\n", 17)))
-	      {
+              {
                 const char *datacheck = "Content-Type: gnss/data\r\n";
                 const char *chunkycheck = "Transfer-Encoding: chunked\r\n";
@@ -945,9 +977,11 @@
           while(!stop && (numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) > 0)
           {
+#ifndef WINDOWSVERSION
             alarm(ALARMTIME);
+#endif
             fwrite(buf, (size_t)numbytes, 1, stdout);
           }
         }
-        close(sockfd);
+        closesocket(sockfd);
       }
     } while(args.data && *args.data != '%' && !stop);
