rohrpost

A commandline mail client to change the world as we see it.
git clone git://r-36.net/rohrpost
Log | Files | Refs | README | LICENSE

nettest.c (923B)


      1 /*
      2  * Copy me if you can.
      3  * by 20h
      4  */
      5 
      6 /*
      7  * gcc --std=gnu99 -lssl -I.. -o nettest nettest.c net.c ind.c
      8  */
      9 
     10 #include <unistd.h>
     11 #include <stdio.h>
     12 #include <stdlib.h>
     13 #include <strings.h>
     14 
     15 #include "net.h"
     16 
     17 void
     18 main(void)
     19 {
     20 	net_t *net;
     21 	char buf[4097];
     22 	int len;
     23 
     24 	memset(&buf, 0, sizeof(buf));
     25 
     26 	printf("net_new tcps!www.facebook.com!https\n");
     27 	net = net_new("tcps!www.facebook.com!https");
     28 	if (net == NULL) {
     29 		perror("net_new");
     30 		exit(EXIT_FAILURE);
     31 	}
     32 	printf("net_connect\n");
     33 	if (net_connect(net)) {
     34 		perror("net_connect");
     35 		exit(EXIT_FAILURE);
     36 	}
     37 
     38 	printf("net_printf GET / HTTP 1.1 ...\n");
     39 	net_printf(net, "GET / HTTP/1.1\r\nHost: www.facebook.com\r\n"
     40 			"Connection: close\r\n\r\n");
     41 
     42 	printf("net_read\n");
     43 	while((len = net_read(net, buf, sizeof(buf)-1)) > 0)
     44 		fwrite(buf, len, 1, stdout);
     45 
     46 	printf("net_close\n");
     47 	net_close(net);
     48 	printf("net_free\n");
     49 	net_free(net);
     50 
     51 	exit(EXIT_SUCCESS);
     52 }
     53