diff options
-rw-r--r-- | core.cpp | 34 |
1 files changed, 21 insertions, 13 deletions
@@ -700,20 +700,12 @@ void Server::close() { } -int main(int argc, char **argv) { - clientCount = 0; - for (int i = 0; i < CLIENT_LIMIT; i++) - clients[i] = NULL; - serverCount = 0; - for (int i = 0; i < SERVER_LIMIT; i++) - servers[i] = NULL; - - +bool initTLS() { int ret; ret = gnutls_global_init(); if (ret != GNUTLS_E_SUCCESS) { printf("gnutls_global_init failure: %s\n", gnutls_strerror(ret)); - return 1; + return false; } unsigned int bits = gnutls_sec_param_to_pk_bits(GNUTLS_PK_DH, GNUTLS_SEC_PARAM_LEGACY); @@ -721,25 +713,41 @@ int main(int argc, char **argv) { ret = gnutls_dh_params_init(&dh_params); if (ret != GNUTLS_E_SUCCESS) { printf("dh_params_init failure: %s\n", gnutls_strerror(ret)); - return 1; + return false; } ret = gnutls_dh_params_generate2(dh_params, bits); if (ret != GNUTLS_E_SUCCESS) { printf("dh_params_generate2 failure: %s\n", gnutls_strerror(ret)); - return 1; + return false; } gnutls_certificate_allocate_credentials(&clientCreds); ret = gnutls_certificate_set_x509_key_file(clientCreds, "ssl_test.crt", "ssl_test.key", GNUTLS_X509_FMT_PEM); if (ret != GNUTLS_E_SUCCESS) { printf("set_x509_key_file failure: %s\n", gnutls_strerror(ret)); - return 1; + return false; } gnutls_certificate_set_dh_params(clientCreds, dh_params); gnutls_certificate_allocate_credentials(&serverCreds); + return true; +} + + +int main(int argc, char **argv) { + clientCount = 0; + for (int i = 0; i < CLIENT_LIMIT; i++) + clients[i] = NULL; + serverCount = 0; + for (int i = 0; i < SERVER_LIMIT; i++) + servers[i] = NULL; + + + if (!initTLS()) + return 0; + DNS::start(); |