3
#include "../../testsuite/test.hpp"
6
void EchoClientError(SSL_CTX* ctx, SSL* ssl, SOCKET_T& sockfd, const char* msg)
15
void echoclient_test(void* args)
19
WSAStartup(0x0002, &wsd);
29
bool inCreated = false;
30
bool outCreated = false;
32
set_args(argc, argv, *static_cast<func_args*>(args));
34
fin = fopen(argv[1], "r");
38
fout = fopen(argv[2], "w");
42
if (!fin) err_sys("can't open input file");
43
if (!fout) err_sys("can't open output file");
47
SSL_METHOD* method = SSLv23_client_method();
48
SSL_CTX* ctx = SSL_CTX_new(method);
50
SSL* ssl = SSL_new(ctx);
52
SSL_set_fd(ssl, sockfd);
54
if (SSL_connect(ssl) != SSL_SUCCESS)
55
EchoClientError(ctx, ssl, sockfd, "SSL_connect failed");
60
while (fgets(send, sizeof(send), fin)) {
62
int sendSz = strlen(send) + 1;
63
if (SSL_write(ssl, send, sendSz) != sendSz)
64
EchoClientError(ctx, ssl, sockfd, "SSL_write failed");
66
if (strncmp(send, "quit", 4) == 0) {
67
fputs("sending server shutdown command: quit!\n", fout);
71
if (SSL_read(ssl, reply, sizeof(reply)) > 0)
80
if (inCreated) fclose(fin);
81
if (outCreated) fclose(fout);
83
((func_args*)args)->return_code = 0;
87
#ifndef NO_MAIN_DRIVER
89
int main(int argc, char** argv)
96
echoclient_test(&args);
99
return args.return_code;
102
#endif // NO_MAIN_DRIVER