In this chapter, we develop a simple time server that displays the time to an HTTPS client. This program is an adaptation of time_server.c from Chapter 2, Getting to Grips with Socket APIs, which served the time over plain HTTP. Our program begins by including the chapter header, defining main(), and initializing Winsock on Windows. The code for this is as follows:
/*tls_time_server.c*/#include "chap10.h"int main() {#if defined(_WIN32) WSADATA d; if (WSAStartup(MAKEWORD(2, 2), &d)) { fprintf(stderr, "Failed to initialize.\n"); return 1; }#endif
The OpenSSL library is then initialized with the following code:
/*tls_time_server.c continued*/ SSL_library_init(); OpenSSL_add_all_algorithms(); SSL_load_error_strings();
An ...