diff options
author | Jack Lloyd <[email protected]> | 2017-12-23 07:33:40 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-12-23 07:57:20 -0500 |
commit | f40f25f17a2965ca03d42a17599ced5d5f6d46ab (patch) | |
tree | 88600f381b24f25e44048a6f4ef866dc7125f36a /src/cli/tls_server.cpp | |
parent | ffc1ac4da043f8fa9a59cc2d83f7fb0744340a14 (diff) |
Add wrapper functions to clean up cli code using sockets
Diffstat (limited to 'src/cli/tls_server.cpp')
-rw-r--r-- | src/cli/tls_server.cpp | 47 |
1 files changed, 4 insertions, 43 deletions
diff --git a/src/cli/tls_server.cpp b/src/cli/tls_server.cpp index 02c15bf7b..6c0b049a2 100644 --- a/src/cli/tls_server.cpp +++ b/src/cli/tls_server.cpp @@ -14,35 +14,12 @@ #include <botan/tls_policy.h> #include <botan/hex.h> #include <botan/internal/os_utils.h> -#include "credentials.h" #include <list> #include <fstream> -#if defined(BOTAN_TARGET_OS_IS_WINDOWS) -#include <winsock2.h> -#include <WS2tcpip.h> - -// definitions in tls_client.cpp -int close(int fd); -int read(int s, void* buf, size_t len); -int send(int s, const uint8_t* buf, size_t len, int flags); - -typedef size_t ssize_t; -#else -#include <sys/types.h> -#include <sys/time.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> -#include <unistd.h> -#include <errno.h> -#include <fcntl.h> -#endif - -#if !defined(MSG_NOSIGNAL) - #define MSG_NOSIGNAL 0 -#endif +#include "credentials.h" +#include "socket_utils.h" namespace Botan_CLI { @@ -51,28 +28,12 @@ class TLS_Server final : public Command public: TLS_Server() : Command("tls_server cert key --port=443 --type=tcp --policy= --dump-traces=") { -#if defined(BOTAN_TARGET_OS_IS_WINDOWS) - WSAData wsa_data; - WORD wsa_version = MAKEWORD(2, 2); - - if(::WSAStartup(wsa_version, &wsa_data) != 0) - { - throw CLI_Error("WSAStartup() failed: " + std::to_string(WSAGetLastError())); - } - - if(LOBYTE(wsa_data.wVersion) != 2 || HIBYTE(wsa_data.wVersion) != 2) - { - ::WSACleanup(); - throw CLI_Error("Could not find a usable version of Winsock.dll"); - } -#endif + init_sockets(); } ~TLS_Server() { -#if defined(BOTAN_TARGET_OS_IS_WINDOWS) - ::WSACleanup(); -#endif + stop_sockets(); } void go() override |