Sync usage with man page.
[netbsd-mini2440.git] / crypto / external / bsd / openssl / dist / demos / eay / conn.c
blobc4b8f5163e1154fae3efc18475e80bf20d1c4d02
1 /* NOCW */
2 /* demos/eay/conn.c */
4 /* A minimal program to connect to a port using the sock4a protocol.
6 * cc -I../../include conn.c -L../.. -lcrypto
7 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <openssl/err.h>
11 #include <openssl/bio.h>
12 /* #include "proxy.h" */
14 extern int errno;
16 int main(argc,argv)
17 int argc;
18 char *argv[];
20 PROXY *pxy;
21 char *host;
22 char buf[1024*10],*p;
23 BIO *bio;
24 int i,len,off,ret=1;
26 if (argc <= 1)
27 host="localhost:4433";
28 else
29 host=argv[1];
31 /* Lets get nice error messages */
32 ERR_load_crypto_strings();
34 /* First, configure proxy settings */
35 pxy=PROXY_new();
36 PROXY_add_server(pxy,PROXY_PROTOCOL_SOCKS,"gromit:1080");
38 bio=BIO_new(BIO_s_socks4a_connect());
40 BIO_set_conn_hostname(bio,host);
41 BIO_set_proxies(bio,pxy);
42 BIO_set_socks_userid(bio,"eay");
43 BIO_set_nbio(bio,1);
45 p="GET / HTTP/1.0\r\n\r\n";
46 len=strlen(p);
48 off=0;
49 for (;;)
51 i=BIO_write(bio,&(p[off]),len);
52 if (i <= 0)
54 if (BIO_should_retry(bio))
56 fprintf(stderr,"write DELAY\n");
57 sleep(1);
58 continue;
60 else
62 goto err;
65 off+=i;
66 len-=i;
67 if (len <= 0) break;
70 for (;;)
72 i=BIO_read(bio,buf,sizeof(buf));
73 if (i == 0) break;
74 if (i < 0)
76 if (BIO_should_retry(bio))
78 fprintf(stderr,"read DELAY\n");
79 sleep(1);
80 continue;
82 goto err;
84 fwrite(buf,1,i,stdout);
87 ret=1;
89 if (0)
91 err:
92 if (ERR_peek_error() == 0) /* system call error */
94 fprintf(stderr,"errno=%d ",errno);
95 perror("error");
97 else
98 ERR_print_errors_fp(stderr);
100 BIO_free_all(bio);
101 if (pxy != NULL) PROXY_free(pxy);
102 exit(!ret);
103 return(ret);