diff options
author | lv-426 <oxcafebaby@yahoo.com> | 2008-06-04 01:34:03 +0000 |
---|---|---|
committer | lv-426 <oxcafebaby@yahoo.com> | 2008-06-04 01:34:03 +0000 |
commit | d21b9465d9f44f636a112dcbedf331ce4e4e5f35 (patch) | |
tree | 5d8ad7e72bd7cf94672edd76761d8ce542d9cb3a | |
parent | 21e2642e4e815fa3db42073c5090614b9eff7d70 (diff) | |
download | libmicrohttpd-d21b9465d9f44f636a112dcbedf331ce4e4e5f35.tar.gz libmicrohttpd-d21b9465d9f44f636a112dcbedf331ce4e4e5f35.zip |
remove echo client
-rw-r--r-- | src/examples/https_echo_client_example.c | 153 |
1 files changed, 0 insertions, 153 deletions
diff --git a/src/examples/https_echo_client_example.c b/src/examples/https_echo_client_example.c deleted file mode 100644 index 04e26c74..00000000 --- a/src/examples/https_echo_client_example.c +++ /dev/null | |||
@@ -1,153 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of libmicrohttpd | ||
3 | (C) 2007 Christian Grothoff | ||
4 | |||
5 | libmicrohttpd is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | libmicrohttpd is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with libmicrohttpd; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file https_echo_client.c | ||
23 | * @brief a simple echo client to use in conjuction with the echo TLS server. | ||
24 | * @author LV-426 | ||
25 | */ | ||
26 | |||
27 | #if HAVE_CONFIG_H | ||
28 | # include <config.h> | ||
29 | #endif | ||
30 | |||
31 | #include <stdio.h> | ||
32 | #include <stdlib.h> | ||
33 | #include <string.h> | ||
34 | #include <sys/types.h> | ||
35 | #include <sys/socket.h> | ||
36 | #include <arpa/inet.h> | ||
37 | #include <unistd.h> | ||
38 | #include <gnutls/gnutls.h> | ||
39 | |||
40 | #define MAX_BUF 1024 | ||
41 | #define SA struct sockaddr | ||
42 | #define MSG "GET / HTTP/1.0\r\n\r\n" | ||
43 | |||
44 | extern int tcp_connect (void); | ||
45 | extern void tcp_close (int sd); | ||
46 | |||
47 | int | ||
48 | main (int argc, char **argv) | ||
49 | { | ||
50 | int ret, sd, ii, err; | ||
51 | gnutls_session_t session; | ||
52 | char buffer[MAX_BUF + 1]; | ||
53 | gnutls_anon_client_credentials_t anoncred; | ||
54 | |||
55 | struct sockaddr_in servaddr4; | ||
56 | const struct sockaddr *servaddr; | ||
57 | struct sockaddr_in sa; | ||
58 | socklen_t addrlen; | ||
59 | |||
60 | if (argc < 2) | ||
61 | { | ||
62 | printf ("Usage : %s SERVER-PORT\n", argv[0]); | ||
63 | return 1; | ||
64 | } | ||
65 | |||
66 | gnutls_global_init (); | ||
67 | |||
68 | gnutls_anon_allocate_client_credentials (&anoncred); | ||
69 | |||
70 | /* Initialize TLS session */ | ||
71 | gnutls_init (&session, GNUTLS_CLIENT); | ||
72 | |||
73 | /* Use default priorities */ | ||
74 | gnutls_priority_set_direct (session, "PERFORMANCE:+ANON-DH:!ARCFOUR-128", | ||
75 | NULL); | ||
76 | |||
77 | /* put the anonymous credentials to the current session */ | ||
78 | gnutls_credentials_set (session, GNUTLS_CRD_ANON, anoncred); | ||
79 | |||
80 | sd = socket (AF_INET, SOCK_STREAM, 0); | ||
81 | memset (&sa, '\0', sizeof (sa)); | ||
82 | sa.sin_family = AF_INET; | ||
83 | sa.sin_port = htons (atoi (argv[1])); | ||
84 | inet_pton (AF_INET, "127.0.0.1", &sa.sin_addr); | ||
85 | |||
86 | /* connect to the peer */ | ||
87 | err = connect (sd, (struct sockaddr *) &sa, sizeof (sa)); | ||
88 | if (err < 0) | ||
89 | { | ||
90 | fprintf (stderr, "Connect error\n"); | ||
91 | exit (1); | ||
92 | } | ||
93 | |||
94 | gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) sd); | ||
95 | |||
96 | /* Perform the TLS handshake */ | ||
97 | ret = gnutls_handshake (session); | ||
98 | |||
99 | if (ret < 0) | ||
100 | { | ||
101 | fprintf (stderr, "*** Handshake failed\n"); | ||
102 | gnutls_perror (ret); | ||
103 | goto end; | ||
104 | } | ||
105 | else | ||
106 | { | ||
107 | printf ("- Handshake was completed\n"); | ||
108 | } | ||
109 | |||
110 | for (;;) | ||
111 | { | ||
112 | /**/ scanf ("%s", buffer); | ||
113 | |||
114 | if (strcmp (buffer, "exit") == 0) | ||
115 | { | ||
116 | gnutls_record_send (session, buffer, strlen (MSG)); | ||
117 | break; | ||
118 | } | ||
119 | gnutls_record_send (session, buffer, strlen (MSG)); | ||
120 | |||
121 | ret = gnutls_record_recv (session, buffer, MAX_BUF); | ||
122 | if (ret == 0) | ||
123 | { | ||
124 | printf ("- Peer has closed the TLS connection\n"); | ||
125 | goto end; | ||
126 | } | ||
127 | else if (ret < 0) | ||
128 | { | ||
129 | fprintf (stderr, "*** Error: %s\n", gnutls_strerror (ret)); | ||
130 | break; | ||
131 | } | ||
132 | |||
133 | printf ("- Received %d bytes: ", ret); | ||
134 | for (ii = 0; ii < ret; ii++) | ||
135 | { | ||
136 | fputc (buffer[ii], stdout); | ||
137 | } | ||
138 | fputs ("\n", stdout); | ||
139 | } | ||
140 | |||
141 | end: | ||
142 | |||
143 | shutdown (sd, SHUT_RDWR); | ||
144 | close (sd); | ||
145 | |||
146 | gnutls_deinit (session); | ||
147 | |||
148 | gnutls_anon_free_client_credentials (anoncred); | ||
149 | |||
150 | gnutls_global_deinit (); | ||
151 | |||
152 | return 0; | ||
153 | } | ||