diff --git a/docs/changes.txt b/docs/changes.txt index 673dc9544..09306c412 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -27,6 +27,7 @@ ## - Fixed missing call to WSAStartup() and client indexing in order to start the brain server on windows +- Fixed missing call to WSACleanup() to cleanly shutdown windows sockets system - Fixed endianness and invalid separator character in outfile format of hash-mode 16801 (WPA-PMKID-PMK) * changes v4.2.1 -> v5.0.0 diff --git a/src/brain.c b/src/brain.c index e97102455..440aa93d2 100644 --- a/src/brain.c +++ b/src/brain.c @@ -3286,5 +3286,9 @@ int brain_server (const char *listen_host, const int listen_port, const char *br close (server_fd); + #if defined (_WIN) + WSACleanup(); + #endif + return 0; } diff --git a/src/hashcat.c b/src/hashcat.c index ea3eec594..91c500016 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -1026,6 +1026,28 @@ int hashcat_session_init (hashcat_ctx_t *hashcat_ctx, const char *install_folder user_options_postprocess (hashcat_ctx); + /** + * windows and sockets... + */ + + #if defined (_WIN) + if (user_options->brain_client == true) + { + WSADATA wsaData; + + WORD wVersionRequested = MAKEWORD (2,2); + + const int iResult = WSAStartup (wVersionRequested, &wsaData); + + if (iResult != NO_ERROR) + { + fprintf (stderr, "WSAStartup: %s\n", strerror (errno)); + + return -1; + } + } + #endif + /** * logfile */ @@ -1292,6 +1314,15 @@ int hashcat_session_quit (hashcat_ctx_t *hashcat_ctx) int hashcat_session_destroy (hashcat_ctx_t *hashcat_ctx) { + #if defined (_WIN) + user_options_t *user_options = hashcat_ctx->user_options; + + if (user_options->brain_client == true) + { + WSACleanup(); + } + #endif + debugfile_destroy (hashcat_ctx); dictstat_destroy (hashcat_ctx); folder_config_destroy (hashcat_ctx); diff --git a/src/user_options.c b/src/user_options.c index 476047b61..58aa084ac 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -1894,25 +1894,6 @@ int user_options_check_files (hashcat_ctx_t *hashcat_ctx) // brain #ifdef WITH_BRAIN - - #if defined (_WIN) - if (user_options->brain_client == true) - { - WSADATA wsaData; - - WORD wVersionRequested = MAKEWORD (2,2); - - const int iResult = WSAStartup (wVersionRequested, &wsaData); - - if (iResult != NO_ERROR) - { - fprintf (stderr, "WSAStartup: %s\n", strerror (errno)); - - return -1; - } - } - #endif - if (user_options->brain_host) { struct addrinfo hints;