diff --git a/DAPNETGateway.cpp b/DAPNETGateway.cpp index 15cdd27..0bec73a 100644 --- a/DAPNETGateway.cpp +++ b/DAPNETGateway.cpp @@ -1,5 +1,5 @@ /* -* Copyright (C) 2018 by Jonathan Naylor G4KLX +* Copyright (C) 2018,2020 by Jonathan Naylor G4KLX * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -114,6 +114,7 @@ m_regexBlacklist(), m_regexWhitelist(), m_mmdvmFree(false) { + CUDPSocket::startup(); } CDAPNETGateway::~CDAPNETGateway() @@ -122,6 +123,8 @@ CDAPNETGateway::~CDAPNETGateway() delete *it; m_queue.clear(); + + CUDPSocket::shutdown(); } int CDAPNETGateway::run() diff --git a/UDPSocket.cpp b/UDPSocket.cpp index 382925f..3f6192a 100644 --- a/UDPSocket.cpp +++ b/UDPSocket.cpp @@ -37,12 +37,6 @@ m_address_save(address), m_port_save(port), m_counter(0U) { -#if defined(_WIN32) || defined(_WIN64) - WSAData data; - int wsaRet = ::WSAStartup(MAKEWORD(2, 2), &data); - if (wsaRet != 0) - LogError("Error from WSAStartup"); -#endif for (int i = 0; i < UDP_SOCKET_MAX; i++) { m_address[i] = ""; m_port[i] = 0U; @@ -56,12 +50,6 @@ m_address_save(), m_port_save(port), m_counter(0U) { -#if defined(_WIN32) || defined(_WIN64) - WSAData data; - int wsaRet = ::WSAStartup(MAKEWORD(2, 2), &data); - if (wsaRet != 0) - LogError("Error from WSAStartup"); -#endif for (int i = 0; i < UDP_SOCKET_MAX; i++) { m_address[i] = ""; m_port[i] = 0U; @@ -72,6 +60,20 @@ m_counter(0U) CUDPSocket::~CUDPSocket() { +} + +void CUDPSocket::startup() +{ +#if defined(_WIN32) || defined(_WIN64) + WSAData data; + int wsaRet = ::WSAStartup(MAKEWORD(2, 2), &data); + if (wsaRet != 0) + LogError("Error from WSAStartup"); +#endif +} + +void CUDPSocket::shutdown() +{ #if defined(_WIN32) || defined(_WIN64) ::WSACleanup(); #endif diff --git a/UDPSocket.h b/UDPSocket.h index 3f5585b..6e3846c 100644 --- a/UDPSocket.h +++ b/UDPSocket.h @@ -60,8 +60,12 @@ public: void close(); void close(const unsigned int index); + static void startup(); + static void shutdown(); + static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length); static int lookup(const std::string& hostName, unsigned int port, sockaddr_storage& address, unsigned int& address_length, struct addrinfo& hints); + static bool match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type = IMT_ADDRESS_AND_PORT); static bool isNone(const sockaddr_storage& addr);