rp

simple email tools
git clone https://git.parazyd.org/rp
Log | Files | Refs | README | LICENSE

nettest.c (897B)


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