Changeset 579 in ntrip


Ignore:
Timestamp:
Nov 20, 2007, 1:54:05 PM (16 years ago)
Author:
stoecker
Message:

added Windows fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ntripclient/ntripclient.c

    r550 r579  
    11/*
    22  Easy example NTRIP client for POSIX.
    3   $Id: ntripclient.c,v 1.34 2007/10/08 08:03:19 stoecker Exp $
     3  $Id: ntripclient.c,v 1.35 2007/10/26 14:56:47 stuerze Exp $
    44  Copyright (C) 2003-2005 by Dirk Stoecker <soft@dstoecker.de>
    55   
     
    2222#include <ctype.h>
    2323#include <getopt.h>
    24 #include <signal.h>
    2524#include <stdio.h>
    2625#include <stdlib.h>
    27 #include <unistd.h>
    2826#include <errno.h>
    2927#include <string.h>
    30 #include <netdb.h>
    31 #include <sys/types.h>
    32 #include <netinet/in.h>
    33 #include <sys/socket.h>
    3428#include <time.h>
     29
     30#ifdef WINDOWSVERSION
     31  #include <winsock.h>
     32  typedef SOCKET sockettype;
     33  typedef u_long in_addr_t;
     34  typedef size_t socklen_t;
     35#else
     36  typedef int sockettype;
     37  #include <signal.h>
     38  #include <fcntl.h>
     39  #include <unistd.h>
     40  #include <arpa/inet.h>
     41  #include <sys/socket.h>
     42  #include <netinet/in.h>
     43  #include <netdb.h>
     44
     45  #define closesocket(sock)       close(sock)
     46  #define ALARMTIME   (2*60)
     47#endif
    3548
    3649#ifndef COMPILEDATE
     
    4255
    4356#define MAXDATASIZE 1000 /* max number of bytes we can get at once */
    44 #define ALARMTIME   (2*60)
    4557
    4658/* CVS revision and version */
    47 static char revisionstr[] = "$Revision: 1.34 $";
    48 static char datestr[]     = "$Date: 2007/10/08 08:03:19 $";
     59static char revisionstr[] = "$Revision: 1.35 $";
     60static char datestr[]     = "$Date: 2007/10/26 14:56:47 $";
    4961
    5062enum MODE { HTTP = 1, RTSP = 2, NTRIP1 = 3, AUTO = 4, END };
     
    6375  int         mode;
    6476};
    65 
    66 
    6777
    6878/* option parsing */
     
    8898#define ARGOPT "-d:m:bhp:r:s:u:n:S:R:M:"
    8999
     100int stop = 0;
     101#ifndef WINDOWSVERSION
    90102#ifdef __GNUC__
    91103static __attribute__ ((noreturn)) void sighandler_alarm(
     
    99111}
    100112
    101 int stop = 0;
    102113#ifdef __GNUC__
    103114static void sighandler_int(int sig __attribute__((__unused__)))
     
    109120  stop = 1;
    110121}
     122#endif /* WINDOWSVERSION */
    111123
    112124static const char *encodeurl(const char *req)
     
    127139      *urlenc++ = h[*req >> 4];
    128140      *urlenc++ = h[*req & 0x0f];
    129       *req++;
     141      req++;
    130142    }
    131143  }
     
    165177            *Buffer++ = h[*url >> 4];
    166178            *Buffer++ = h[*url & 0x0f];
    167             *url++;
     179            url++;
    168180          }     
    169181       }
     
    433445  setbuf(stdin, 0);
    434446  setbuf(stderr, 0);
     447#ifndef WINDOWSVERSION
    435448  signal(SIGALRM,sighandler_alarm);
    436449  signal(SIGINT,sighandler_int);
    437450  alarm(ALARMTIME);
     451#else
     452  WSADATA wsaData;
     453  if(WSAStartup(MAKEWORD(1,1),&wsaData))
     454  {
     455    fprintf(stderr, "Could not init network access.\n");
     456    return 20;
     457  }
     458#endif
    438459
    439460  if(getargs(argc, argv, &args))
     
    442463    do
    443464    {
    444       int sockfd, numbytes; 
     465      sockettype sockfd;
     466      int numbytes; 
    445467      char buf[MAXDATASIZE];
    446468      struct sockaddr_in their_addr; /* connector's address information */
     
    453475      if(sleeptime)
    454476      {
     477#ifdef WINDOWSVERSION
     478        Sleep(sleeptime*1000);
     479#else
    455480        sleep(sleeptime);
     481#endif
    456482        sleeptime += 2;
    457483      }
     
    460486        sleeptime = 1;
    461487      }
     488#ifndef WINDOWSVERSION
    462489      alarm(ALARMTIME);
     490#endif
    463491      if(args.proxyhost)
    464492      {
     
    681709                (struct sockaddr*) &addrRTP, &len)) > 0)
    682710                {
     711#ifndef WINDOWSVERSION
    683712                  alarm(ALARMTIME);
     713#endif
    684714                  if(i >= 12+1 && (unsigned char)buf[0] == (2 << 6) && buf[1] == 0x60)
    685715                  {
     
    820850          int chunksize = 0;
    821851
    822           while(!stop && (numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) != -1)
     852          while(!stop && (numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) > 0)
    823853          {
     854#ifndef WINDOWSVERSION
    824855            alarm(ALARMTIME);
     856#endif
    825857            if(!k)
    826858            {
    827859              if(numbytes > 17 && (!strncmp(buf, "HTTP/1.1 200 OK\r\n", 17)
    828860              || !strncmp(buf, "HTTP/1.0 200 OK\r\n", 17)))
    829               {
     861              {
    830862                const char *datacheck = "Content-Type: gnss/data\r\n";
    831863                const char *chunkycheck = "Transfer-Encoding: chunked\r\n";
     
    945977          while(!stop && (numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) > 0)
    946978          {
     979#ifndef WINDOWSVERSION
    947980            alarm(ALARMTIME);
     981#endif
    948982            fwrite(buf, (size_t)numbytes, 1, stdout);
    949983          }
    950984        }
    951         close(sockfd);
     985        closesocket(sockfd);
    952986      }
    953987    } while(args.data && *args.data != '%' && !stop);
Note: See TracChangeset for help on using the changeset viewer.