21 #include "../../testsuite/test.hpp"
24 void EchoClientError(
SSL_CTX* ctx,
SSL* ssl, SOCKET_T& sockfd,
const char*
msg)
33 void echoclient_test(
void* args)
37 WSAStartup(0x0002, &wsd);
47 bool inCreated =
false;
48 bool outCreated =
false;
50 set_args(argc, argv, *static_cast<func_args*>(args));
52 fin = fopen(argv[1],
"r");
56 fout = fopen(argv[2],
"w");
60 if (!fin) err_sys(
"can't open input file");
61 if (!fout) err_sys(
"can't open output file");
66 SSL_CTX* ctx = SSL_CTX_new(method);
68 SSL* ssl = SSL_new(ctx);
70 SSL_set_fd(ssl, sockfd);
72 if (SSL_connect(ssl) != SSL_SUCCESS)
73 EchoClientError(ctx, ssl, sockfd,
"SSL_connect failed");
78 while (fgets(send,
sizeof(send), fin)) {
80 int sendSz = (int)strlen(send) + 1;
81 if (SSL_write(ssl, send, sendSz) != sendSz)
82 EchoClientError(ctx, ssl, sockfd,
"SSL_write failed");
84 if (strncmp(send,
"quit", 4) == 0) {
85 fputs(
"sending server shutdown command: quit!\n", fout);
89 if (SSL_read(ssl, reply,
sizeof(reply)) > 0)
98 if (inCreated) fclose(fin);
99 if (outCreated) fclose(fout);
105 #ifndef NO_MAIN_DRIVER
107 int main(
int argc,
char** argv)
114 echoclient_test(&args);
117 return args.return_code;
120 #endif // NO_MAIN_DRIVER