- Timestamp:
- Nov 20, 2007, 1:54:05 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ntripclient/ntripclient.c
r550 r579 1 1 /* 2 2 Easy example NTRIP client for POSIX. 3 $Id: ntripclient.c,v 1.3 4 2007/10/08 08:03:19 stoeckerExp $3 $Id: ntripclient.c,v 1.35 2007/10/26 14:56:47 stuerze Exp $ 4 4 Copyright (C) 2003-2005 by Dirk Stoecker <soft@dstoecker.de> 5 5 … … 22 22 #include <ctype.h> 23 23 #include <getopt.h> 24 #include <signal.h>25 24 #include <stdio.h> 26 25 #include <stdlib.h> 27 #include <unistd.h>28 26 #include <errno.h> 29 27 #include <string.h> 30 #include <netdb.h>31 #include <sys/types.h>32 #include <netinet/in.h>33 #include <sys/socket.h>34 28 #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 35 48 36 49 #ifndef COMPILEDATE … … 42 55 43 56 #define MAXDATASIZE 1000 /* max number of bytes we can get at once */ 44 #define ALARMTIME (2*60)45 57 46 58 /* CVS revision and version */ 47 static char revisionstr[] = "$Revision: 1.3 4$";48 static char datestr[] = "$Date: 2007/10/ 08 08:03:19$";59 static char revisionstr[] = "$Revision: 1.35 $"; 60 static char datestr[] = "$Date: 2007/10/26 14:56:47 $"; 49 61 50 62 enum MODE { HTTP = 1, RTSP = 2, NTRIP1 = 3, AUTO = 4, END }; … … 63 75 int mode; 64 76 }; 65 66 67 77 68 78 /* option parsing */ … … 88 98 #define ARGOPT "-d:m:bhp:r:s:u:n:S:R:M:" 89 99 100 int stop = 0; 101 #ifndef WINDOWSVERSION 90 102 #ifdef __GNUC__ 91 103 static __attribute__ ((noreturn)) void sighandler_alarm( … … 99 111 } 100 112 101 int stop = 0;102 113 #ifdef __GNUC__ 103 114 static void sighandler_int(int sig __attribute__((__unused__))) … … 109 120 stop = 1; 110 121 } 122 #endif /* WINDOWSVERSION */ 111 123 112 124 static const char *encodeurl(const char *req) … … 127 139 *urlenc++ = h[*req >> 4]; 128 140 *urlenc++ = h[*req & 0x0f]; 129 *req++;141 req++; 130 142 } 131 143 } … … 165 177 *Buffer++ = h[*url >> 4]; 166 178 *Buffer++ = h[*url & 0x0f]; 167 *url++;179 url++; 168 180 } 169 181 } … … 433 445 setbuf(stdin, 0); 434 446 setbuf(stderr, 0); 447 #ifndef WINDOWSVERSION 435 448 signal(SIGALRM,sighandler_alarm); 436 449 signal(SIGINT,sighandler_int); 437 450 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 438 459 439 460 if(getargs(argc, argv, &args)) … … 442 463 do 443 464 { 444 int sockfd, numbytes; 465 sockettype sockfd; 466 int numbytes; 445 467 char buf[MAXDATASIZE]; 446 468 struct sockaddr_in their_addr; /* connector's address information */ … … 453 475 if(sleeptime) 454 476 { 477 #ifdef WINDOWSVERSION 478 Sleep(sleeptime*1000); 479 #else 455 480 sleep(sleeptime); 481 #endif 456 482 sleeptime += 2; 457 483 } … … 460 486 sleeptime = 1; 461 487 } 488 #ifndef WINDOWSVERSION 462 489 alarm(ALARMTIME); 490 #endif 463 491 if(args.proxyhost) 464 492 { … … 681 709 (struct sockaddr*) &addrRTP, &len)) > 0) 682 710 { 711 #ifndef WINDOWSVERSION 683 712 alarm(ALARMTIME); 713 #endif 684 714 if(i >= 12+1 && (unsigned char)buf[0] == (2 << 6) && buf[1] == 0x60) 685 715 { … … 820 850 int chunksize = 0; 821 851 822 while(!stop && (numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) != -1)852 while(!stop && (numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) > 0) 823 853 { 854 #ifndef WINDOWSVERSION 824 855 alarm(ALARMTIME); 856 #endif 825 857 if(!k) 826 858 { 827 859 if(numbytes > 17 && (!strncmp(buf, "HTTP/1.1 200 OK\r\n", 17) 828 860 || !strncmp(buf, "HTTP/1.0 200 OK\r\n", 17))) 829 861 { 830 862 const char *datacheck = "Content-Type: gnss/data\r\n"; 831 863 const char *chunkycheck = "Transfer-Encoding: chunked\r\n"; … … 945 977 while(!stop && (numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) > 0) 946 978 { 979 #ifndef WINDOWSVERSION 947 980 alarm(ALARMTIME); 981 #endif 948 982 fwrite(buf, (size_t)numbytes, 1, stdout); 949 983 } 950 984 } 951 close (sockfd);985 closesocket(sockfd); 952 986 } 953 987 } while(args.data && *args.data != '%' && !stop);
Note:
See TracChangeset
for help on using the changeset viewer.