diff --git a/src/ccodecstream.cpp b/src/ccodecstream.cpp index 356d1fc..5354f5c 100644 --- a/src/ccodecstream.cpp +++ b/src/ccodecstream.cpp @@ -103,7 +103,15 @@ bool CCodecStream::Init(uint16 uiPort) } // create socket address, family based on transcoder listen address +#ifdef LISTEN_IPV4 +#ifdef LISTEN_IPV6 s = (AF_INET == m_Ip.GetFamily()) ? g_Reflector.GetListenIPv4() : g_Reflector.GetListenIPv6(); +#else + s = g_Reflector.GetListenIPv4(); +#endif +#else + s = g_Reflector.GetListenIPv6(); +#endif CIp ip(m_Ip.GetFamily(), m_uiPort, s); // create our socket diff --git a/src/cdcsprotocol.cpp b/src/cdcsprotocol.cpp index ee2ed6c..4fb4c9d 100644 --- a/src/cdcsprotocol.cpp +++ b/src/cdcsprotocol.cpp @@ -36,7 +36,7 @@ bool CDcsProtocol::Init(void) { // base class - if (! Initialize("DCS", DCS_PORT)) + if (! Initialize("DCS", DCS_PORT, DSTAR_IPV4, DSTAR_IPV6)) return false; // update time @@ -61,8 +61,8 @@ void CDcsProtocol::Task(void) CDvFramePacket *Frame; // handle incoming packets -#ifdef DSTAR_IPV6 -#ifdef DSTAR_IPV4 +#if DSTAR_IPV6==true +#if DSTAR_IPV4==true if ( ReceiveDS(Buffer, Ip, 20) ) #else if ( Receive6(Buffer, Ip, 20) ) diff --git a/src/cdextraprotocol.cpp b/src/cdextraprotocol.cpp index 0a8460a..00f8398 100644 --- a/src/cdextraprotocol.cpp +++ b/src/cdextraprotocol.cpp @@ -38,7 +38,7 @@ bool CDextraProtocol::Init(void) { // base class - if (! Initialize("XRF", DEXTRA_PORT)) + if (! Initialize("XRF", DEXTRA_PORT, DSTAR_IPV4, DSTAR_IPV6)) return false; // update time @@ -64,8 +64,8 @@ void CDextraProtocol::Task(void) CDvLastFramePacket *LastFrame; // any incoming packet ? -#ifdef DSTAR_IPV6 -#ifdef DSTAR_IPV4 +#if DSTAR_IPV6==true +#if DSTAR_IPV4==true if ( ReceiveDS(Buffer, Ip, 20) ) #else if ( Receive6(Buffer, Ip, 20) ) diff --git a/src/cdmrmmdvmprotocol.cpp b/src/cdmrmmdvmprotocol.cpp index 01e1c4f..54b6c00 100644 --- a/src/cdmrmmdvmprotocol.cpp +++ b/src/cdmrmmdvmprotocol.cpp @@ -57,7 +57,7 @@ static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 }; bool CDmrmmdvmProtocol::Init(void) { // base class - if (! Initialize(NULL, DMRMMDVM_PORT)) + if (! Initialize(NULL, DMRMMDVM_PORT, DMR_IPV4, DMR_IPV6)) return false; // update time @@ -90,8 +90,8 @@ void CDmrmmdvmProtocol::Task(void) CDvLastFramePacket *LastFrame; // handle incoming packets -#ifdef DMR_IPV6 -#ifdef DMR_IPV4 +#if DMR_IPV6==true +#if DMR_IPV4==true if ( ReceiveDS(Buffer, Ip, 20) ) #else if ( Receive6(Buffer, Ip, 20) ) diff --git a/src/cdmrplusprotocol.cpp b/src/cdmrplusprotocol.cpp index bf2dfd4..1f98981 100644 --- a/src/cdmrplusprotocol.cpp +++ b/src/cdmrplusprotocol.cpp @@ -50,7 +50,7 @@ static uint8 g_DmrSyncMSData[] = { 0x0D,0x5D,0x7F,0x77,0xFD,0x75,0x70 }; bool CDmrplusProtocol::Init() { // base class - if (! Initialize(NULL, DMRPLUS_PORT)) + if (! Initialize(NULL, DMRPLUS_PORT, DMR_IPV4, DMR_IPV6)) return false; // update time @@ -79,8 +79,8 @@ void CDmrplusProtocol::Task(void) CDvFramePacket *Frames[3]; // handle incoming packets -#ifdef DMR_IPV6 -#ifdef DMR_IPV4 +#if DMR_IPV6==true +#if DMR_IPV4==true if ( ReceiveDS(Buffer, Ip, 20) ) #else if ( Receive6(Buffer, Ip, 20) ) diff --git a/src/cdplusprotocol.cpp b/src/cdplusprotocol.cpp index e866353..9624f6a 100644 --- a/src/cdplusprotocol.cpp +++ b/src/cdplusprotocol.cpp @@ -37,7 +37,7 @@ bool CDplusProtocol::Init(void) { // base class - if (! Initialize("REF", DPLUS_PORT)) + if (! Initialize("REF", DPLUS_PORT, DSTAR_IPV4, DSTAR_IPV6)) return false; // update time @@ -62,8 +62,8 @@ void CDplusProtocol::Task(void) CDvLastFramePacket *LastFrame; // handle incoming packets -#ifdef DSTAR_IPV6 -#ifdef DSTAR_IPV4 +#if DSTAR_IPV6==true +#if DSTAR_IPV4==true if ( ReceiveDS(Buffer, Ip, 20) ) #else if ( Receive6(Buffer, Ip, 20) ) diff --git a/src/cprotocol.cpp b/src/cprotocol.cpp index d6b9aca..f45cc91 100644 --- a/src/cprotocol.cpp +++ b/src/cprotocol.cpp @@ -66,7 +66,7 @@ CProtocol::~CProtocol() //////////////////////////////////////////////////////////////////////////////////////// // initialization -bool CProtocol::Initialize(const char *type, uint16 port) +bool CProtocol::Initialize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6) { // init reflector apparent callsign m_ReflectorCallsign = g_Reflector.GetCallsign(); @@ -80,24 +80,30 @@ bool CProtocol::Initialize(const char *type, uint16 port) // create our sockets #ifdef LISTEN_IPV4 - CIp ip4(AF_INET, port, g_Reflector.GetListenIPv4()); - if ( ip4.IsSet() ) + if (has_ipv4) { - if (! m_Socket4.Open(ip4)) - return false; + CIp ip4(AF_INET, port, g_Reflector.GetListenIPv4()); + if ( ip4.IsSet() ) + { + if (! m_Socket4.Open(ip4)) + return false; + } } #endif #ifdef LISTEN_IPV6 - CIp ip6(AF_INET6, port, g_Reflector.GetListenIPv6()); - if ( ip6.IsSet() ) - { - if (! m_Socket6.Open(ip6)) + if (has_ipv6) + { + CIp ip6(AF_INET6, port, g_Reflector.GetListenIPv6()); + if ( ip6.IsSet() ) { - m_Socket4.Close(); - return false; + if (! m_Socket6.Open(ip6)) + { + m_Socket4.Close(); + return false; + } } - } + } #endif // start thread; @@ -105,12 +111,8 @@ bool CProtocol::Initialize(const char *type, uint16 port) if (m_pThread == NULL) { std::cerr << "Could not start DCS thread!" << std::endl; -#ifdef LISTEN_IPV4 m_Socket4.Close(); -#endif -#ifdef LISTEN_IPV6 m_Socket6.Close(); -#endif return false; } @@ -135,12 +137,8 @@ void CProtocol::Close(void) delete m_pThread; m_pThread = NULL; } -#ifdef LISTEN_IPV4 m_Socket4.Close(); -#endif -#ifdef LISTEN_IPV6 m_Socket6.Close(); -#endif } //////////////////////////////////////////////////////////////////////////////////////// @@ -307,21 +305,16 @@ uint32 CProtocol::ModuleToDmrDestId(char m) const //////////////////////////////////////////////////////////////////////////////////////// // Receivers -#ifdef LISTEN_IPV6 bool CProtocol::Receive6(CBuffer &buf, CIp &ip, int time_ms) { return m_Socket6.Receive(buf, ip, time_ms); } -#endif -#ifdef LISTEN_IPV4 bool CProtocol::Receive4(CBuffer &buf, CIp &ip, int time_ms) { return m_Socket4.Receive(buf, ip, time_ms); } -#endif -#if defined(LISTEN_IPV4) && defined(LISTEN_IPV6) bool CProtocol::ReceiveDS(CBuffer &buf, CIp &ip, int time_ms) { auto fd4 = m_Socket4.GetSocket(); @@ -358,7 +351,6 @@ bool CProtocol::ReceiveDS(CBuffer &buf, CIp &ip, int time_ms) else return m_Socket6.ReceiveFrom(buf, ip); } -#endif //////////////////////////////////////////////////////////////////////////////////////// // dual stack senders @@ -366,16 +358,12 @@ bool CProtocol::ReceiveDS(CBuffer &buf, CIp &ip, int time_ms) void CProtocol::Send(const CBuffer &buf, const CIp &Ip) const { switch (Ip.GetFamily()) { -#ifdef LISTEN_IPV4 case AF_INET: m_Socket4.Send(buf, Ip); break; -#endif -#ifdef LISTEN_IPV6 case AF_INET6: m_Socket6.Send(buf, Ip); break; -#endif default: std::cerr << "Wrong family: " << Ip.GetFamily() << std::endl; break; @@ -385,16 +373,12 @@ void CProtocol::Send(const CBuffer &buf, const CIp &Ip) const void CProtocol::Send(const char *buf, const CIp &Ip) const { switch (Ip.GetFamily()) { -#ifdef LISTEN_IPV4 case AF_INET: m_Socket4.Send(buf, Ip); break; -#endif -#ifdef LISTEN_IPV6 case AF_INET6: m_Socket6.Send(buf, Ip); break; -#endif default: std::cerr << "ERROR: wrong family: " << Ip.GetFamily() << std::endl; break; @@ -404,16 +388,12 @@ void CProtocol::Send(const char *buf, const CIp &Ip) const void CProtocol::Send(const CBuffer &buf, const CIp &Ip, uint16_t port) const { switch (Ip.GetFamily()) { -#ifdef LISTEN_IPV4 case AF_INET: m_Socket4.Send(buf, Ip, port); break; -#endif -#ifdef LISTEN_IPV6 case AF_INET6: m_Socket6.Send(buf, Ip, port); break; -#endif default: std::cerr << "Wrong family: " << Ip.GetFamily() << " on port " << port << std::endl; break; @@ -423,16 +403,12 @@ void CProtocol::Send(const CBuffer &buf, const CIp &Ip, uint16_t port) const void CProtocol::Send(const char *buf, const CIp &Ip, uint16_t port) const { switch (Ip.GetFamily()) { -#ifdef LISTEN_IPV4 case AF_INET: m_Socket4.Send(buf, Ip, port); break; -#endif -#ifdef LISTEN_IPV6 case AF_INET6: m_Socket6.Send(buf, Ip, port); break; -#endif default: std::cerr << "Wrong family: " << Ip.GetFamily() << " on port " << port << std::endl; break; diff --git a/src/cprotocol.h b/src/cprotocol.h index 4b1955a..1d7a939 100644 --- a/src/cprotocol.h +++ b/src/cprotocol.h @@ -77,7 +77,7 @@ public: virtual ~CProtocol(); // initialization - bool Initialize(const char *, uint16); + bool Initialize(const char *type, const uint16 port, const bool has_ipv4, const bool has_ipv6); virtual void Close(void); // queue @@ -122,15 +122,9 @@ protected: virtual char DmrDstIdToModule(uint32) const; virtual uint32 ModuleToDmrDestId(char) const; -#ifdef LISTEN_IPV6 bool Receive6(CBuffer &buf, CIp &Ip, int time_ms); -#endif -#ifdef LISTEN_IPV4 bool Receive4(CBuffer &buf, CIp &Ip, int time_ms); -#endif -#if defined(LISTEN_IPV4) && defined(LISTEN_IPV6) bool ReceiveDS(CBuffer &buf, CIp &Ip, int time_ms); -#endif void Send(const CBuffer &buf, const CIp &Ip) const; void Send(const char *buf, const CIp &Ip) const; @@ -138,12 +132,8 @@ protected: void Send(const char *buf, const CIp &Ip, uint16 port) const; // socket -#ifdef LISTEN_IPV4 CUdpSocket m_Socket4; -#endif -#ifdef LISTEN_IPV6 CUdpSocket m_Socket6; -#endif // streams std::list m_Streams; diff --git a/src/ctranscoder.cpp b/src/ctranscoder.cpp index 92b092a..6c28335 100644 --- a/src/ctranscoder.cpp +++ b/src/ctranscoder.cpp @@ -69,7 +69,7 @@ CTranscoder::~CTranscoder() bool CTranscoder::Init(void) { - // create port to the transcoder + // create address to the transcoder auto s = g_Reflector.GetTranscoderIp(); m_Ip.Initialize(strchr(s, ':') ? AF_INET6 : AF_INET, TRANSCODER_PORT, s); @@ -81,7 +81,15 @@ bool CTranscoder::Init(void) } // now open the transcoder port +#ifdef LISTEN_IPV4 +#ifdef LISTEN_IPV6 s = (AF_INET == m_Ip.GetFamily()) ? g_Reflector.GetListenIPv4() : g_Reflector.GetListenIPv6(); +#else + s = g_Reflector.GetListenIPv4(); +#endif +#else + s = g_Reflector.GetListenIPv6(); +#endif CIp tc(m_Ip.GetFamily(), TRANSCODER_PORT, s); // create our socket diff --git a/src/cudpsocket.cpp b/src/cudpsocket.cpp index d3a1e61..4ce9447 100644 --- a/src/cudpsocket.cpp +++ b/src/cudpsocket.cpp @@ -31,10 +31,7 @@ //////////////////////////////////////////////////////////////////////////////////////// // constructor -CUdpSocket::CUdpSocket() -{ - m_fd = -1; -} +CUdpSocket::CUdpSocket() : m_fd(-1) {} //////////////////////////////////////////////////////////////////////////////////////// // destructor diff --git a/src/cxlxprotocol.cpp b/src/cxlxprotocol.cpp index 2de1093..4a42012 100644 --- a/src/cxlxprotocol.cpp +++ b/src/cxlxprotocol.cpp @@ -37,7 +37,7 @@ bool CXlxProtocol::Init(void) { - if (! Initialize("XLX", XLX_PORT)) + if (! Initialize("XLX", XLX_PORT, XLX_IPV4, XLX_IPV6)) return false; // update time @@ -63,8 +63,8 @@ void CXlxProtocol::Task(void) CDvLastFramePacket *LastFrame; // any incoming packet ? -#ifdef XLX_IPV6 -#ifdef XLX_IPV4 +#if XLX_IPV6==true +#if XLX_IPV4==true if ( ReceiveDS(Buffer, Ip, 20) ) #else if ( Receive6(Buffer, Ip, 20) ) diff --git a/src/cysfprotocol.cpp b/src/cysfprotocol.cpp index b5034dc..b513dc6 100644 --- a/src/cysfprotocol.cpp +++ b/src/cysfprotocol.cpp @@ -48,7 +48,7 @@ CYsfProtocol::CYsfProtocol() bool CYsfProtocol::Init(void) { // base class - if (! Initialize("YSF", YSF_PORT)) + if (! Initialize("YSF", YSF_PORT, YSF_IPV4, YSF_IPV6)) return false; // init the wiresx cmd handler @@ -101,8 +101,8 @@ void CYsfProtocol::Task(void) } // handle incoming packets -#ifdef YSF_IPV6 -#ifdef YSF_IPV4 +#if YSF_IPV6==true +#if YSF_IPV4==true if ( ReceiveDS(Buffer, Ip, 20) ) #else if ( Receive6(Buffer, Ip, 20) ) diff --git a/src/main.h b/src/main.h index 1ea7f22..49a16ac 100644 --- a/src/main.h +++ b/src/main.h @@ -51,7 +51,7 @@ #if ! defined(LISTEN_IPV4) && ! defined(LISTEN_IPV6) && ! defined(CALLSIGN) #define CALLSIGN "XLX797" #define LISTEN_IPV4 "10.1.10.61" -#define LISTEN_IPV6 "any" +#define LISTEN_IPV6 "::" #define TRANSCODER_IP "127.0.0.1" #endif @@ -60,19 +60,15 @@ #endif //// Module configuration -#ifdef LISTEN_IPV4 -#define DSTAR_IPV4 -#define DMR_IPV4 -#define YSF_IPV4 -#define XLX_IPV4 -#endif - -#ifdef LISTEN_IPV6 -#define DSTAR_IPV6 -//#define DMR_IPV6 // these are off beacuse there are none available for IPv6 -//#define YSF_IPV6 -//#define XLX_IPV6 -#endif +#define DSTAR_IPV4 true +#define DMR_IPV4 true +#define YSF_IPV4 true +#define XLX_IPV4 true + +#define DSTAR_IPV6 true +#define DMR_IPV6 false +#define YSF_IPV6 false +#define XLX_IPV6 false // version -----------------------------------------------------