MMDVMHost-Private/UDPSocket.cpp

355 lines
8.9 KiB
C++
Raw Normal View History

2016-01-14 18:45:04 +00:00
/*
* Copyright (C) 2006-2016,2020 by Jonathan Naylor G4KLX
2016-01-14 18:45:04 +00:00
*
* 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
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "UDPSocket.h"
#include <cassert>
#if !defined(_WIN32) && !defined(_WIN64)
#include <cerrno>
#include <cstring>
#endif
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
#if defined(HAVE_LOG_H)
#include "Log.h"
#else
#define LogError(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__)
#define LogInfo(fmt, ...) ::fprintf(stderr, fmt "\n", ## __VA_ARGS__)
#endif
2016-01-14 18:45:04 +00:00
CUDPSocket::CUDPSocket(const std::string& address, unsigned int port) :
m_address_save(address),
m_port_save(port),
m_counter(0U)
2016-01-14 18:45:04 +00:00
{
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
for (int i = 0; i < UDP_SOCKET_MAX; i++) {
m_address[i] = "";
m_port[i] = 0U;
m_af[i] = 0U;
m_fd[i] = -1;
}
2016-01-14 18:45:04 +00:00
}
CUDPSocket::CUDPSocket(unsigned int port) :
m_address_save(),
m_port_save(port),
m_counter(0U)
2016-01-14 18:45:04 +00:00
{
for (int i = 0; i < UDP_SOCKET_MAX; i++) {
m_address[i] = "";
m_port[i] = 0U;
m_af[i] = 0U;
m_fd[i] = -1;
}
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
}
2016-01-14 18:45:04 +00:00
CUDPSocket::~CUDPSocket()
{
2020-09-20 20:31:32 +00:00
}
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()
{
2016-01-14 18:45:04 +00:00
#if defined(_WIN32) || defined(_WIN64)
::WSACleanup();
#endif
}
int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_storage& addr, unsigned int& address_length)
{
struct addrinfo hints;
::memset(&hints, 0, sizeof(hints));
return lookup(hostname, port, addr, address_length, hints);
}
int CUDPSocket::lookup(const std::string& hostname, unsigned int port, sockaddr_storage& addr, unsigned int& address_length, struct addrinfo& hints)
2016-01-14 18:45:04 +00:00
{
std::string portstr = std::to_string(port);
struct addrinfo *res;
/* port is always digits, no needs to lookup service */
hints.ai_flags |= AI_NUMERICSERV;
int err = getaddrinfo(hostname.empty() ? NULL : hostname.c_str(), portstr.c_str(), &hints, &res);
if (err != 0) {
sockaddr_in* paddr = (sockaddr_in*)&addr;
::memset(paddr, 0x00U, address_length = sizeof(sockaddr_in));
paddr->sin_family = AF_INET;
paddr->sin_port = htons(port);
paddr->sin_addr.s_addr = htonl(INADDR_NONE);
LogError("Cannot find address for host %s", hostname.c_str());
return err;
2016-01-14 18:45:04 +00:00
}
::memcpy(&addr, res->ai_addr, address_length = res->ai_addrlen);
2016-01-14 18:45:04 +00:00
freeaddrinfo(res);
2016-01-14 18:45:04 +00:00
return 0;
}
bool CUDPSocket::match(const sockaddr_storage& addr1, const sockaddr_storage& addr2, IPMATCHTYPE type)
{
if (addr1.ss_family != addr2.ss_family)
return false;
if (type == IMT_ADDRESS_AND_PORT) {
switch (addr1.ss_family) {
case AF_INET:
struct sockaddr_in *in_1, *in_2;
in_1 = (struct sockaddr_in*)&addr1;
in_2 = (struct sockaddr_in*)&addr2;
return (in_1->sin_addr.s_addr == in_2->sin_addr.s_addr) && (in_1->sin_port == in_2->sin_port);
case AF_INET6:
struct sockaddr_in6 *in6_1, *in6_2;
in6_1 = (struct sockaddr_in6*)&addr1;
in6_2 = (struct sockaddr_in6*)&addr2;
return IN6_ARE_ADDR_EQUAL(&in6_1->sin6_addr, &in6_2->sin6_addr) && (in6_1->sin6_port == in6_2->sin6_port);
default:
return false;
}
} else if (type == IMT_ADDRESS_ONLY) {
switch (addr1.ss_family) {
case AF_INET:
struct sockaddr_in *in_1, *in_2;
in_1 = (struct sockaddr_in*)&addr1;
in_2 = (struct sockaddr_in*)&addr2;
return in_1->sin_addr.s_addr == in_2->sin_addr.s_addr;
case AF_INET6:
struct sockaddr_in6 *in6_1, *in6_2;
in6_1 = (struct sockaddr_in6*)&addr1;
in6_2 = (struct sockaddr_in6*)&addr2;
return IN6_ARE_ADDR_EQUAL(&in6_1->sin6_addr, &in6_2->sin6_addr);
default:
return false;
}
} else {
return false;
}
}
bool CUDPSocket::isNone(const sockaddr_storage& addr)
{
struct sockaddr_in *in = (struct sockaddr_in *)&addr;
return ((addr.ss_family == AF_INET) && (in->sin_addr.s_addr == htonl(INADDR_NONE)));
}
bool CUDPSocket::open(const sockaddr_storage& address)
{
return open(address.ss_family);
}
bool CUDPSocket::open(unsigned int af)
2016-01-14 18:45:04 +00:00
{
return open(0, af, m_address_save, m_port_save);
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
}
bool CUDPSocket::open(const unsigned int index, const unsigned int af, const std::string& address, const unsigned int port)
{
sockaddr_storage addr;
unsigned int addrlen;
struct addrinfo hints;
::memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_PASSIVE;
hints.ai_family = af;
/* to determine protocol family, call lookup() first. */
int err = lookup(address, port, addr, addrlen, hints);
if (err != 0) {
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
LogError("The local address is invalid - %s", address.c_str());
return false;
}
int fd = ::socket(addr.ss_family, SOCK_DGRAM, 0);
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
if (fd < 0) {
2016-01-14 18:45:04 +00:00
#if defined(_WIN32) || defined(_WIN64)
LogError("Cannot create the UDP socket, err: %lu", ::GetLastError());
#else
LogError("Cannot create the UDP socket, err: %d", errno);
#endif
return false;
}
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
m_address[index] = address;
m_port[index] = port;
m_af[index] = addr.ss_family;
m_fd[index] = fd;
if (port > 0U) {
2016-01-14 18:45:04 +00:00
int reuse = 1;
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
if (::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) == -1) {
2016-01-14 18:45:04 +00:00
#if defined(_WIN32) || defined(_WIN64)
LogError("Cannot set the UDP socket option, err: %lu", ::GetLastError());
#else
LogError("Cannot set the UDP socket option, err: %d", errno);
#endif
return false;
}
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
if (::bind(fd, (sockaddr*)&addr, addrlen) == -1) {
2016-01-14 18:45:04 +00:00
#if defined(_WIN32) || defined(_WIN64)
LogError("Cannot bind the UDP address, err: %lu", ::GetLastError());
#else
LogError("Cannot bind the UDP address, err: %d", errno);
#endif
return false;
}
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
LogInfo("Opening UDP port on %u", port);
2016-01-14 18:45:04 +00:00
}
return true;
}
int CUDPSocket::read(unsigned char* buffer, unsigned int length, sockaddr_storage& address, unsigned int &address_length)
2016-01-14 18:45:04 +00:00
{
assert(buffer != NULL);
assert(length > 0U);
// Check that the readfrom() won't block
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
int i, n;
struct pollfd pfd[UDP_SOCKET_MAX];
for (i = n = 0; i < UDP_SOCKET_MAX; i++) {
if (m_fd[i] >= 0) {
pfd[n].fd = m_fd[i];
pfd[n].events = POLLIN;
n++;
}
}
// no socket descriptor to receive
if (n == 0)
return 0;
// Return immediately
2016-01-14 18:45:04 +00:00
#if defined(_WIN32) || defined(_WIN64)
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
int ret = WSAPoll(pfd, n, 0);
2016-01-14 18:45:04 +00:00
#else
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
int ret = ::poll(pfd, n, 0);
2016-01-14 18:45:04 +00:00
#endif
if (ret < 0) {
#if defined(_WIN32) || defined(_WIN64)
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
LogError("Error returned from UDP poll, err: %lu", ::GetLastError());
2016-01-14 18:45:04 +00:00
#else
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
LogError("Error returned from UDP poll, err: %d", errno);
2016-01-14 18:45:04 +00:00
#endif
return -1;
}
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
int index;
for (i = 0; i < n; i++) {
// round robin
index = (i + m_counter) % n;
if (pfd[index].revents & POLLIN)
break;
}
if (i == n)
2016-01-14 18:45:04 +00:00
return 0;
#if defined(_WIN32) || defined(_WIN64)
int size = sizeof(sockaddr_storage);
2016-01-14 18:45:04 +00:00
#else
socklen_t size = sizeof(sockaddr_storage);
2016-01-14 18:45:04 +00:00
#endif
#if defined(_WIN32) || defined(_WIN64)
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
int len = ::recvfrom(pfd[index].fd, (char*)buffer, length, 0, (sockaddr *)&address, &size);
2016-01-14 18:45:04 +00:00
#else
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
ssize_t len = ::recvfrom(pfd[index].fd, (char*)buffer, length, 0, (sockaddr *)&address, &size);
2016-01-14 18:45:04 +00:00
#endif
if (len <= 0) {
#if defined(_WIN32) || defined(_WIN64)
LogError("Error returned from recvfrom, err: %lu", ::GetLastError());
#else
LogError("Error returned from recvfrom, err: %d", errno);
#endif
return -1;
}
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
m_counter++;
address_length = size;
2016-01-14 18:45:04 +00:00
return len;
}
bool CUDPSocket::write(const unsigned char* buffer, unsigned int length, const sockaddr_storage& address, unsigned int address_length)
2016-01-14 18:45:04 +00:00
{
assert(buffer != NULL);
assert(length > 0U);
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
bool result = false;
for (int i = 0; i < UDP_SOCKET_MAX; i++) {
if (m_fd[i] < 0 || m_af[i] != address.ss_family)
continue;
2016-01-14 18:45:04 +00:00
#if defined(_WIN32) || defined(_WIN64)
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
int ret = ::sendto(m_fd[i], (char *)buffer, length, 0, (sockaddr *)&address, address_length);
2016-01-14 18:45:04 +00:00
#else
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
ssize_t ret = ::sendto(m_fd[i], (char *)buffer, length, 0, (sockaddr *)&address, address_length);
2016-01-14 18:45:04 +00:00
#endif
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
if (ret < 0) {
2016-01-14 18:45:04 +00:00
#if defined(_WIN32) || defined(_WIN64)
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
LogError("Error returned from sendto, err: %lu", ::GetLastError());
2016-01-14 18:45:04 +00:00
#else
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
LogError("Error returned from sendto, err: %d", errno);
2016-01-14 18:45:04 +00:00
#endif
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
} else {
2016-01-14 18:45:04 +00:00
#if defined(_WIN32) || defined(_WIN64)
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
if (ret == int(length))
result = true;
2016-01-14 18:45:04 +00:00
#else
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
if (ret == ssize_t(length))
result = true;
2016-01-14 18:45:04 +00:00
#endif
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
}
}
2016-01-14 18:45:04 +00:00
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
return result;
2016-01-14 18:45:04 +00:00
}
void CUDPSocket::close()
{
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
for (int i = 0; i < UDP_SOCKET_MAX; i++)
close(m_fd[i]);
}
void CUDPSocket::close(const unsigned int index)
{
if (m_fd[index] >= 0) {
2016-01-14 18:45:04 +00:00
#if defined(_WIN32) || defined(_WIN64)
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
::closesocket(m_fd[index]);
2016-01-14 18:45:04 +00:00
#else
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
::close(m_fd[index]);
2016-01-14 18:45:04 +00:00
#endif
UDPSocket renewal Currently there is six variations of (IPv4) UDPSocket.cpp. - FMClients, NXDNClients, P25Clients, YSFClients(YSFParrot) use ::fprintf() for logging - YSFClients(YSFReflector) use LogError() and LogInfo() for logging special open(string &bindaddr) function - YSFClients(YSFGateway), DAPNETGateway use LogError() and LogInfo() for logging - P25Clients, DMRGateway use LogError() for logging no LogInfo("Opening UDP port on") message - NXDNClients use LogError() for logging no LogInfo("Opening UDP port on") message add #include <ifaddrs.h> - MMDVMHost use LogError() for logging no LogInfo("Opening UDP port on") message no assert(!address.empty()) at constructor to avoid explosion, commonized them. switch ::fprintf()/LogError by #define HAVE_LOG_H always display LogInfo("Opening UDP port on") message delete #include <ifaddrs.h>, this is not needed no assert(!address.empty()) at constructor and to support YSFReflector, add multiple socket support. default is #define UDP_SOCKET_MAX 1 so normally this feature is disabled. added these functions. CUDPSocket() (constructor without any parameters) open(index, af, addr, port) close(index) CUDPSocket() means CUDPSocket(address = "", port = 0) index selects socket, address and port is defined at open. to have compatibility for old codes, these function works as CUDPSocket(addr, port) store addr and port to index #0 CUDPSocket(port) store addr = "" and port to index #0 open() open with addr and port of index #0, AF_UNSPEC open(af) open with addr and port of index #0, specified af close() close *all* sockets read/write operation is for all opened sockets.
2020-09-06 03:09:37 +00:00
m_fd[index] = -1;
}
2016-01-14 18:45:04 +00:00
}