Just cleaning up some things that may be needed in the tree
[tpg/acess2.git] / Usermode / Applications / testclient_src / main.c
1 /*
2  * Acess2 Test Client
3  */
4 #include <acess/sys.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7
8 /**
9  * \fn int main(int argc, char *argv[])
10  * \brief Entrypoint
11  */
12 int main(int argc, char *argv[])
13 {
14          int    con = -1;
15          int    len;
16         uint16_t        port;
17         uint8_t buf[4] = {10,0,2,1};
18         uint8_t data[4096];     // Packet Data
19          
20         con = open("/Devices/ip/1/tcpc", OPENFLAG_READ|OPENFLAG_WRITE);
21         if(con == -1) {
22                 fprintf(stderr, "Unable top open TCP client '/Devices/ip/1/tcpc'\n");
23                 return -1;
24         }
25         
26         port = 80;      ioctl(con, 5, &port);   // Set Remote Port
27         ioctl(con, 6, buf);     // Set remote IP
28         ioctl(con, 7, NULL);    // Connect
29         
30         #define REQ_STR "GET / HTTP/1.1\r\n"\
31                 "Host: prelude\r\n"\
32                 "User-Agent: Acess2 TCP Test Client\r\n"\
33                 "\r\n"
34         
35         write(con, sizeof(REQ_STR)-1, REQ_STR);
36         
37         len = read(con, 4096, data);
38         close(con);
39         if( len == -1 ) {
40                 printf("Connection closed on us\n");
41                 return 0;
42         }
43         if( len != 0 )
44         {
45                 printf("Packet Data: (%i bytes)\n", len);
46                 printf("%s\n", data);
47                 printf("--- EOP ---\n");
48         }
49         return 0;
50 }

UCC git Repository :: git.ucc.asn.au