3 #include <sys/select.h>
6 #define _FILE_OFFSET_BITS 64 /* for curl_off_t magic */
9 int fd_read(int fd
, void *buf
, size_t len
)
12 bytes_read
= read(fd
,buf
,len
);
16 int fd_write(int fd
, void *buf
, size_t len
)
19 bytes_written
= write(fd
,buf
,len
);
23 int fdcopy(int fdin
, int fdout
)
28 if((n
=fd_read(fdin
,buf
,SIZE
))<0)
30 fprintf(stderr
,"Read Error\n");
37 if(fd_write(fdout
,buf
,n
)!=n
)
39 fprintf(stderr
,"Write Error\n");
46 void wait_and_act(int sockfd
)
48 struct timeval timeout
;
49 int rc
; /* select() return code */
50 long timeout_ms
= 1000;
63 /* set timeout to wait */
64 timeout
.tv_sec
= timeout_ms
/1000;
65 timeout
.tv_usec
= (timeout_ms
%1000)*1000;
67 FD_SET(fileno(stdin
), &fdread
);
68 FD_SET(sockfd
, &fdread
);
69 /* FD_SET(sockfd, &fdwrite); */
74 (fd_set
*)&fdexcep
, &timeout
);
78 fprintf(stderr
,"select() error\n");
83 /* fprintf(stderr,"Timeout\n"); */
85 /* use FD_ISSET() to check what happened, then read/write accordingly */
86 if (FD_ISSET(fileno(stdin
), &fdread
))
88 if(fdcopy(fileno(stdin
),sockfd
))
91 if (FD_ISSET(sockfd
,&fdread
))
93 if(fdcopy(sockfd
,fileno(stdout
)))
99 int main(int argc
, char *argv
[])
103 CURL
*hnd
= curl_easy_init();
105 /* Hard coded for convenience currently. Obviously we'll change this to
106 read from the command line at some point */
107 curl_easy_setopt(hnd
, CURLOPT_URL
, "http://godeater.dyndns.org:443/");
108 curl_easy_setopt(hnd
, CURLOPT_PROXY
, "10.1.23.219:8080");
109 curl_easy_setopt(hnd
, CURLOPT_PROXYUSERPWD
, "gbchlb:X344ekl25");
110 curl_easy_setopt(hnd
, CURLOPT_USERAGENT
, "curl/7.16.4 (i686-pc-linux-gnu) libcurl/7.16.4 GnuTLS/1.4.4 zlib/1.2.3 c-ares/1.4.0");
111 curl_easy_setopt(hnd
, CURLOPT_HTTPPROXYTUNNEL
, 1);
112 curl_easy_setopt(hnd
, CURLOPT_CONNECT_ONLY
, 1);
113 curl_easy_setopt(hnd
, CURLOPT_VERBOSE
, 1);
114 ret
= curl_easy_perform(hnd
);
118 /* Extract socket, and select() */
119 ret
= curl_easy_getinfo(hnd
, CURLINFO_LASTSOCKET
, &sckt
);
120 if((sckt
==-1) || ret
){
121 fprintf(stderr
,"[ERR] Couldn't get socket");
126 wait_and_act((int)sckt
);
129 curl_easy_cleanup(hnd
);