diff --git a/qrtplib/CMakeLists.txt b/qrtplib/CMakeLists.txt index 270f7107f..71382e15a 100644 --- a/qrtplib/CMakeLists.txt +++ b/qrtplib/CMakeLists.txt @@ -22,8 +22,6 @@ set (qrtplib_HEADERS rtpinternalsourcedata.h rtpipv4address.h rtpipv4destination.h - rtpipv6address.h - rtpipv6destination.h rtpkeyhashtable.h rtplibraryversion.h rtpmemorymanager.h @@ -47,7 +45,6 @@ set (qrtplib_HEADERS rtptypes.h rtpudpv4transmitter.h rtpudpv4transmitternobind.h - rtpudpv6transmitter.h rtpbyteaddress.h rtpexternaltransmitter.h rtpsocketutil.h @@ -72,9 +69,7 @@ set(qrtplib_SOURCES rtperrors.cpp rtpinternalsourcedata.cpp rtpipv4address.cpp - rtpipv6address.cpp rtpipv4destination.cpp - rtpipv6destination.cpp rtplibraryversion.cpp rtppacket.cpp rtppacketbuilder.cpp @@ -90,7 +85,6 @@ set(qrtplib_SOURCES rtptimeutilities.cpp rtpudpv4transmitter.cpp rtpudpv4transmitternobind.cpp - rtpudpv6transmitter.cpp rtpbyteaddress.cpp rtpexternaltransmitter.cpp rtpabortdescriptors.cpp diff --git a/qrtplib/rtcpapppacket.h b/qrtplib/rtcpapppacket.h index 59828d905..dacfb2265 100644 --- a/qrtplib/rtcpapppacket.h +++ b/qrtplib/rtcpapppacket.h @@ -41,9 +41,7 @@ #include "rtpconfig.h" #include "rtcppacket.h" #include "rtpstructs.h" -#ifdef RTP_SUPPORT_NETINET_IN - #include -#endif // RTP_SUPPORT_NETINET_IN +#include "rtpendian.h" namespace qrtplib { @@ -79,6 +77,7 @@ public: /** Returns the length of the actual data. */ size_t GetAPPDataLength() const; private: + RTPEndian m_endian; size_t appdatalen; }; @@ -96,7 +95,7 @@ inline uint32_t RTCPAPPPacket::GetSSRC() const return 0; uint32_t *ssrc = (uint32_t *)(data+sizeof(RTCPCommonHeader)); - return ntohl(*ssrc); + return m_endian.qToHost(*ssrc); } inline uint8_t *RTCPAPPPacket::GetName() diff --git a/qrtplib/rtcpbyepacket.h b/qrtplib/rtcpbyepacket.h index 765fb19c9..1da3676a3 100644 --- a/qrtplib/rtcpbyepacket.h +++ b/qrtplib/rtcpbyepacket.h @@ -41,9 +41,7 @@ #include "rtpconfig.h" #include "rtcppacket.h" #include "rtpstructs.h" -#ifdef RTP_SUPPORT_NETINET_IN - #include -#endif // RTP_SUPPORT_NETINET_IN +#include "rtpendian.h" namespace qrtplib { @@ -80,6 +78,7 @@ public: uint8_t *GetReasonData(); private: + RTPEndian m_endian; size_t reasonoffset; }; @@ -97,7 +96,7 @@ inline uint32_t RTCPBYEPacket::GetSSRC(int index) const if (!knownformat) return 0; uint32_t *ssrc = (uint32_t *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)*index); - return ntohl(*ssrc); + return m_endian.qToHost(*ssrc); } inline bool RTCPBYEPacket::HasReasonForLeaving() const diff --git a/qrtplib/rtcpcompoundpacket.cpp b/qrtplib/rtcpcompoundpacket.cpp index 21f43bbb5..a6456a1e9 100644 --- a/qrtplib/rtcpcompoundpacket.cpp +++ b/qrtplib/rtcpcompoundpacket.cpp @@ -41,9 +41,6 @@ #include "rtcpbyepacket.h" #include "rtcpapppacket.h" #include "rtcpunknownpacket.h" -#ifdef RTP_SUPPORT_NETINET_IN - #include -#endif // RTP_SUPPORT_NETINET_IN namespace qrtplib { @@ -132,7 +129,7 @@ int RTCPCompoundPacket::ParseData(uint8_t *data, size_t datalen) } } - length = (size_t)ntohs(rtcphdr->length); + length = (size_t)m_endian.qToHost(rtcphdr->length); length++; length *= sizeof(uint32_t); diff --git a/qrtplib/rtcpcompoundpacket.h b/qrtplib/rtcpcompoundpacket.h index 6041df7e4..3d9164d55 100644 --- a/qrtplib/rtcpcompoundpacket.h +++ b/qrtplib/rtcpcompoundpacket.h @@ -41,6 +41,7 @@ #include "rtpconfig.h" #include "rtptypes.h" #include "rtpmemoryobject.h" +#include "rtpendian.h" #include namespace qrtplib @@ -92,6 +93,7 @@ protected: void ClearPacketList(); int ParseData(uint8_t *packet, size_t len); + RTPEndian m_endian; int error; uint8_t *compoundpacket; diff --git a/qrtplib/rtcpcompoundpacketbuilder.cpp b/qrtplib/rtcpcompoundpacketbuilder.cpp index ce0c67f69..1a392e949 100644 --- a/qrtplib/rtcpcompoundpacketbuilder.cpp +++ b/qrtplib/rtcpcompoundpacketbuilder.cpp @@ -39,9 +39,6 @@ #ifdef RTP_SUPPORT_RTCPUNKNOWN #include "rtcpunknownpacket.h" #endif // RTP_SUPPORT_RTCPUNKNOWN -#ifdef RTP_SUPPORT_NETINET_IN - #include -#endif // RTP_SUPPORT_NETINET_IN #include namespace qrtplib @@ -175,14 +172,14 @@ int RTCPCompoundPacketBuilder::StartSenderReport(uint32_t senderssrc,const RTPNT report.isSR = true; uint32_t *ssrc = (uint32_t *)report.headerdata; - *ssrc = htonl(senderssrc); + *ssrc = qToBigEndian(senderssrc); RTCPSenderReport *sr = (RTCPSenderReport *)(report.headerdata + sizeof(uint32_t)); - sr->ntptime_msw = htonl(ntptimestamp.GetMSW()); - sr->ntptime_lsw = htonl(ntptimestamp.GetLSW()); - sr->rtptimestamp = htonl(rtptimestamp); - sr->packetcount = htonl(packetcount); - sr->octetcount = htonl(octetcount); + sr->ntptime_msw = qToBigEndian(ntptimestamp.GetMSW()); + sr->ntptime_lsw = qToBigEndian(ntptimestamp.GetLSW()); + sr->rtptimestamp = qToBigEndian(rtptimestamp); + sr->packetcount = qToBigEndian(packetcount); + sr->octetcount = qToBigEndian(octetcount); return 0; } @@ -211,7 +208,7 @@ int RTCPCompoundPacketBuilder::StartReceiverReport(uint32_t senderssrc) report.isSR = false; uint32_t *ssrc = (uint32_t *)report.headerdata; - *ssrc = htonl(senderssrc); + *ssrc = qToBigEndian(senderssrc); return 0; } @@ -242,15 +239,15 @@ int RTCPCompoundPacketBuilder::AddReportBlock(uint32_t ssrc,uint8_t fractionlost uint32_t *packlost = (uint32_t *)&packetslost; uint32_t packlost2 = (*packlost); - rr->ssrc = htonl(ssrc); + rr->ssrc = qToBigEndian(ssrc); rr->fractionlost = fractionlost; rr->packetslost[2] = (uint8_t)(packlost2&0xFF); rr->packetslost[1] = (uint8_t)((packlost2>>8)&0xFF); rr->packetslost[0] = (uint8_t)((packlost2>>16)&0xFF); - rr->exthighseqnr = htonl(exthighestseq); - rr->jitter = htonl(jitter); - rr->lsr = htonl(lsr); - rr->dlsr = htonl(dlsr); + rr->exthighseqnr = qToBigEndian(exthighestseq); + rr->jitter = qToBigEndian(jitter); + rr->lsr = qToBigEndian(lsr); + rr->dlsr = qToBigEndian(dlsr); report.reportblocks.push_back(Buffer(buf,sizeof(RTCPReceiverReport))); return 0; @@ -437,14 +434,14 @@ int RTCPCompoundPacketBuilder::AddBYEPacket(uint32_t *ssrcs,uint8_t numssrcs,con hdr->count = numssrcs; numwords = packsize/sizeof(uint32_t); - hdr->length = htons((uint16_t)(numwords-1)); + hdr->length = qToBigEndian((uint16_t)(numwords-1)); hdr->packettype = RTP_RTCPTYPE_BYE; uint32_t *sources = (uint32_t *)(buf+sizeof(RTCPCommonHeader)); uint8_t srcindex; for (srcindex = 0 ; srcindex < numssrcs ; srcindex++) - sources[srcindex] = htonl(ssrcs[srcindex]); + sources[srcindex] = qToBigEndian(ssrcs[srcindex]); if (reasonlength != 0) { @@ -498,11 +495,11 @@ int RTCPCompoundPacketBuilder::AddAPPPacket(uint8_t subtype,uint32_t ssrc,const hdr->padding = 0; hdr->count = subtype; - hdr->length = htons((uint16_t)(appdatawords+2)); + hdr->length = qToBigEndian((uint16_t)(appdatawords+2)); hdr->packettype = RTP_RTCPTYPE_APP; uint32_t *source = (uint32_t *)(buf+sizeof(RTCPCommonHeader)); - *source = htonl(ssrc); + *source = qToBigEndian(ssrc); buf[sizeof(RTCPCommonHeader)+sizeof(uint32_t)+0] = name[0]; buf[sizeof(RTCPCommonHeader)+sizeof(uint32_t)+1] = name[1]; @@ -545,11 +542,11 @@ int RTCPCompoundPacketBuilder::AddUnknownPacket(uint8_t payload_type, uint8_t su hdr->version = 2; hdr->padding = 0; hdr->count = subtype; - hdr->length = htons((uint16_t)(datawords+1)); + hdr->length = qToBigEndian((uint16_t)(datawords+1)); hdr->packettype = payload_type; uint32_t *source = (uint32_t *)(buf+sizeof(RTCPCommonHeader)); - *source = htonl(ssrc); + *source = qToBigEndian(ssrc); if (len > 0) memcpy((buf+sizeof(RTCPCommonHeader)+sizeof(uint32_t)),data,len); @@ -630,7 +627,7 @@ int RTCPCompoundPacketBuilder::EndBuild() size_t numwords = offset/sizeof(uint32_t); - hdr->length = htons((uint16_t)(numwords-1)); + hdr->length = qToBigEndian((uint16_t)(numwords-1)); hdr->count = count; // add entry in parent's list @@ -674,7 +671,7 @@ int RTCPCompoundPacketBuilder::EndBuild() while (sourceit != sdes.sdessources.end() && sourcecount < 31) { uint32_t *ssrc = (uint32_t *)(curbuf+offset); - *ssrc = htonl((*sourceit)->ssrc); + *ssrc = qToBigEndian((*sourceit)->ssrc); offset += sizeof(uint32_t); std::list::const_iterator itemit,itemend; @@ -709,7 +706,7 @@ int RTCPCompoundPacketBuilder::EndBuild() size_t numwords = offset/4; hdr->count = sourcecount; - hdr->length = htons((uint16_t)(numwords-1)); + hdr->length = qToBigEndian((uint16_t)(numwords-1)); p = RTPNew(GetMemoryManager(),RTPMEM_TYPE_CLASS_RTCPSDESPACKET) RTCPSDESPacket(curbuf,offset); if (p == 0) diff --git a/qrtplib/rtcpcompoundpacketbuilder.h b/qrtplib/rtcpcompoundpacketbuilder.h index 2c8f3a541..09caec6c5 100644 --- a/qrtplib/rtcpcompoundpacketbuilder.h +++ b/qrtplib/rtcpcompoundpacketbuilder.h @@ -43,6 +43,7 @@ #include "rtptimeutilities.h" #include "rtcpsdespacket.h" #include "rtperrors.h" +#include "rtpendian.h" #include namespace qrtplib @@ -372,6 +373,7 @@ private: std::list::const_iterator sdesit; }; + RTPEndian m_endian; size_t maximumpacketsize; uint8_t *buffer; bool external; diff --git a/qrtplib/rtcprrpacket.h b/qrtplib/rtcprrpacket.h index f779fe67f..9e380460e 100644 --- a/qrtplib/rtcprrpacket.h +++ b/qrtplib/rtcprrpacket.h @@ -41,9 +41,7 @@ #include "rtpconfig.h" #include "rtcppacket.h" #include "rtpstructs.h" -#ifdef RTP_SUPPORT_NETINET_IN - #include -#endif // RTP_SUPPORT_NETINET_IN +#include "rtpendian.h" namespace qrtplib { @@ -113,6 +111,8 @@ public: private: RTCPReceiverReport *GotoReport(int index) const; + + RTPEndian m_endian; }; inline uint32_t RTCPRRPacket::GetSenderSSRC() const @@ -121,7 +121,7 @@ inline uint32_t RTCPRRPacket::GetSenderSSRC() const return 0; uint32_t *ssrcptr = (uint32_t *)(data+sizeof(RTCPCommonHeader)); - return ntohl(*ssrcptr); + return m_endian.qToHost(*ssrcptr); } inline int RTCPRRPacket::GetReceptionReportCount() const { @@ -142,7 +142,7 @@ inline uint32_t RTCPRRPacket::GetSSRC(int index) const if (!knownformat) return 0; RTCPReceiverReport *r = GotoReport(index); - return ntohl(r->ssrc); + return m_endian.qToHost(r->ssrc); } inline uint8_t RTCPRRPacket::GetFractionLost(int index) const @@ -170,7 +170,7 @@ inline uint32_t RTCPRRPacket::GetExtendedHighestSequenceNumber(int index) const if (!knownformat) return 0; RTCPReceiverReport *r = GotoReport(index); - return ntohl(r->exthighseqnr); + return m_endian.qToHost(r->exthighseqnr); } inline uint32_t RTCPRRPacket::GetJitter(int index) const @@ -178,7 +178,7 @@ inline uint32_t RTCPRRPacket::GetJitter(int index) const if (!knownformat) return 0; RTCPReceiverReport *r = GotoReport(index); - return ntohl(r->jitter); + return m_endian.qToHost(r->jitter); } inline uint32_t RTCPRRPacket::GetLSR(int index) const @@ -186,7 +186,7 @@ inline uint32_t RTCPRRPacket::GetLSR(int index) const if (!knownformat) return 0; RTCPReceiverReport *r = GotoReport(index); - return ntohl(r->lsr); + return m_endian.qToHost(r->lsr); } inline uint32_t RTCPRRPacket::GetDLSR(int index) const @@ -194,7 +194,7 @@ inline uint32_t RTCPRRPacket::GetDLSR(int index) const if (!knownformat) return 0; RTCPReceiverReport *r = GotoReport(index); - return ntohl(r->dlsr); + return m_endian.qToHost(r->dlsr); } } // end namespace diff --git a/qrtplib/rtcpsdespacket.h b/qrtplib/rtcpsdespacket.h index 7d6eb01f0..874648fee 100644 --- a/qrtplib/rtcpsdespacket.h +++ b/qrtplib/rtcpsdespacket.h @@ -42,9 +42,7 @@ #include "rtcppacket.h" #include "rtpstructs.h" #include "rtpdefines.h" -#ifdef RTP_SUPPORT_NETINET_IN - #include -#endif // RTP_SUPPORT_NETINET_IN +#include "rtpendian.h" namespace qrtplib { @@ -143,6 +141,7 @@ public: #endif // RTP_SUPPORT_SDESPRIV private: + RTPEndian m_endian; uint8_t *currentchunk; int curchunknum; size_t itemoffset; @@ -203,7 +202,7 @@ inline uint32_t RTCPSDESPacket::GetChunkSSRC() const if (currentchunk == 0) return 0; uint32_t *ssrc = (uint32_t *)currentchunk; - return ntohl(*ssrc); + return m_endian.qToHost(*ssrc); } inline bool RTCPSDESPacket::GotoFirstItem() diff --git a/qrtplib/rtcpsrpacket.h b/qrtplib/rtcpsrpacket.h index 85af7280f..020b689f1 100644 --- a/qrtplib/rtcpsrpacket.h +++ b/qrtplib/rtcpsrpacket.h @@ -42,9 +42,7 @@ #include "rtcppacket.h" #include "rtptimeutilities.h" #include "rtpstructs.h" -#ifdef RTP_SUPPORT_NETINET_IN - #include -#endif // RTP_SUPPORT_NETINET_IN +#include "rtpendian.h" namespace qrtplib { @@ -125,6 +123,8 @@ public: private: RTCPReceiverReport *GotoReport(int index) const; + + RTPEndian m_endian; }; inline uint32_t RTCPSRPacket::GetSenderSSRC() const @@ -133,7 +133,7 @@ inline uint32_t RTCPSRPacket::GetSenderSSRC() const return 0; uint32_t *ssrcptr = (uint32_t *)(data+sizeof(RTCPCommonHeader)); - return ntohl(*ssrcptr); + return m_endian.qToHost(*ssrcptr); } inline RTPNTPTime RTCPSRPacket::GetNTPTimestamp() const @@ -142,7 +142,7 @@ inline RTPNTPTime RTCPSRPacket::GetNTPTimestamp() const return RTPNTPTime(0,0); RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)); - return RTPNTPTime(ntohl(sr->ntptime_msw),ntohl(sr->ntptime_lsw)); + return RTPNTPTime(m_endian.qToHost(sr->ntptime_msw),m_endian.qToHost(sr->ntptime_lsw)); } inline uint32_t RTCPSRPacket::GetRTPTimestamp() const @@ -150,7 +150,7 @@ inline uint32_t RTCPSRPacket::GetRTPTimestamp() const if (!knownformat) return 0; RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)); - return ntohl(sr->rtptimestamp); + return m_endian.qToHost(sr->rtptimestamp); } inline uint32_t RTCPSRPacket::GetSenderPacketCount() const @@ -158,7 +158,7 @@ inline uint32_t RTCPSRPacket::GetSenderPacketCount() const if (!knownformat) return 0; RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)); - return ntohl(sr->packetcount); + return m_endian.qToHost(sr->packetcount); } inline uint32_t RTCPSRPacket::GetSenderOctetCount() const @@ -166,7 +166,7 @@ inline uint32_t RTCPSRPacket::GetSenderOctetCount() const if (!knownformat) return 0; RTCPSenderReport *sr = (RTCPSenderReport *)(data+sizeof(RTCPCommonHeader)+sizeof(uint32_t)); - return ntohl(sr->octetcount); + return m_endian.qToHost(sr->octetcount); } inline int RTCPSRPacket::GetReceptionReportCount() const @@ -188,7 +188,7 @@ inline uint32_t RTCPSRPacket::GetSSRC(int index) const if (!knownformat) return 0; RTCPReceiverReport *r = GotoReport(index); - return ntohl(r->ssrc); + return m_endian.qToHost(r->ssrc); } inline uint8_t RTCPSRPacket::GetFractionLost(int index) const @@ -216,7 +216,7 @@ inline uint32_t RTCPSRPacket::GetExtendedHighestSequenceNumber(int index) const if (!knownformat) return 0; RTCPReceiverReport *r = GotoReport(index); - return ntohl(r->exthighseqnr); + return m_endian.qToHost(r->exthighseqnr); } inline uint32_t RTCPSRPacket::GetJitter(int index) const @@ -224,7 +224,7 @@ inline uint32_t RTCPSRPacket::GetJitter(int index) const if (!knownformat) return 0; RTCPReceiverReport *r = GotoReport(index); - return ntohl(r->jitter); + return m_endian.qToHost(r->jitter); } inline uint32_t RTCPSRPacket::GetLSR(int index) const @@ -232,7 +232,7 @@ inline uint32_t RTCPSRPacket::GetLSR(int index) const if (!knownformat) return 0; RTCPReceiverReport *r = GotoReport(index); - return ntohl(r->lsr); + return m_endian.qToHost(r->lsr); } inline uint32_t RTCPSRPacket::GetDLSR(int index) const @@ -240,7 +240,7 @@ inline uint32_t RTCPSRPacket::GetDLSR(int index) const if (!knownformat) return 0; RTCPReceiverReport *r = GotoReport(index); - return ntohl(r->dlsr); + return m_endian.qToHost(r->dlsr); } } // end namespace diff --git a/qrtplib/rtpconfig.h b/qrtplib/rtpconfig.h index ea951d86a..95785122b 100644 --- a/qrtplib/rtpconfig.h +++ b/qrtplib/rtpconfig.h @@ -7,7 +7,7 @@ This library was developed at the Expertise Centre for Digital Media (http://www.edm.uhasselt.be), a research center of the Hasselt University - (http://www.uhasselt.be). The library is based upon work done for + (http://www.uhasselt.be). The library is based upon work done for my thesis at the School for Knowledge Technology (Belgium/The Netherlands). Permission is hereby granted, free of charge, to any person obtaining a @@ -41,8 +41,8 @@ #define JRTPLIB_UNUSED(x) (void)(x) #endif // JRTPLIB_UNUSED -#define JRTPLIB_IMPORT -#define JRTPLIB_EXPORT +#define JRTPLIB_IMPORT +#define JRTPLIB_EXPORT #ifdef JRTPLIB_COMPILING #define JRTPLIB_IMPORTEXPORT JRTPLIB_EXPORT #else @@ -69,9 +69,9 @@ #define RTP_SUPPORT_GETLOGINR -#define RTP_SUPPORT_IPV6 +// no #define RTP_SUPPORT_IPV6 -#define RTP_SUPPORT_IPV6MULTICAST +// no #define RTP_SUPPORT_IPV6MULTICAST #define RTP_SUPPORT_IFADDRS @@ -81,7 +81,7 @@ // No support for sending unknown RTCP packets -#define RTP_SUPPORT_NETINET_IN +// no #define RTP_SUPPORT_NETINET_IN // Not using winsock sockets diff --git a/qrtplib/rtpipv6address.cpp b/qrtplib/rtpipv6address.cpp deleted file mode 100644 index 84c0ab796..000000000 --- a/qrtplib/rtpipv6address.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - - This file is a part of JRTPLIB - Copyright (c) 1999-2017 Jori Liesenborgs - - Contact: jori.liesenborgs@gmail.com - - This library was developed at the Expertise Centre for Digital Media - (http://www.edm.uhasselt.be), a research center of the Hasselt University - (http://www.uhasselt.be). The library is based upon work done for - my thesis at the School for Knowledge Technology (Belgium/The Netherlands). - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - IN THE SOFTWARE. - -*/ - -#include "rtpipv6address.h" -#include "rtpmemorymanager.h" - -#ifdef RTP_SUPPORT_IPV6 - - -namespace qrtplib -{ - -RTPAddress *RTPIPv6Address::CreateCopy(RTPMemoryManager *mgr) const -{ - JRTPLIB_UNUSED(mgr); // possibly unused - RTPIPv6Address *newaddr = RTPNew(mgr,RTPMEM_TYPE_CLASS_RTPADDRESS) RTPIPv6Address(ip,port); - return newaddr; -} - -bool RTPIPv6Address::IsSameAddress(const RTPAddress *addr) const -{ - if (addr == 0) - return false; - if (addr->GetAddressType() != RTPAddress::IPv6Address) - return false; - - const RTPIPv6Address *addr2 = (const RTPIPv6Address *)addr; - const uint8_t *ip2 = addr2->ip.s6_addr; - - if (port != addr2->port) - return false; - - for (int i = 0 ; i < 16 ; i++) - { - if (ip.s6_addr[i] != ip2[i]) - return false; - } - return true; -} - -bool RTPIPv6Address::IsFromSameHost(const RTPAddress *addr) const -{ - if (addr == 0) - return false; - if (addr->GetAddressType() != RTPAddress::IPv6Address) - return false; - - const RTPIPv6Address *addr2 = (const RTPIPv6Address *)addr; - const uint8_t *ip2 = addr2->ip.s6_addr; - for (int i = 0 ; i < 16 ; i++) - { - if (ip.s6_addr[i] != ip2[i]) - return false; - } - return true; -} - - -} // end namespace - -#endif // RTP_SUPPORT_IPV6 - diff --git a/qrtplib/rtpipv6address.h b/qrtplib/rtpipv6address.h deleted file mode 100644 index c40edff64..000000000 --- a/qrtplib/rtpipv6address.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - - This file is a part of JRTPLIB - Copyright (c) 1999-2017 Jori Liesenborgs - - Contact: jori.liesenborgs@gmail.com - - This library was developed at the Expertise Centre for Digital Media - (http://www.edm.uhasselt.be), a research center of the Hasselt University - (http://www.uhasselt.be). The library is based upon work done for - my thesis at the School for Knowledge Technology (Belgium/The Netherlands). - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - IN THE SOFTWARE. - -*/ - -/** - * \file rtpipv6address.h - */ - -#ifndef RTPIPV6ADDRESS_H - -#define RTPIPV6ADDRESS_H - -#include "rtpconfig.h" - -#ifdef RTP_SUPPORT_IPV6 - -#include "rtpaddress.h" -#include "rtptypes.h" -#ifdef RTP_SUPPORT_NETINET_IN - #include -#endif // RTP_SUPPORT_NETINET_IN - -namespace qrtplib -{ - -/** Represents an IPv6 IP address and port. - * This class is used by the UDP over IPv4 transmission component. - * When an RTPIPv6Address is used in one of the multicast functions of the - * transmitter, the port number is ignored. When an instance is used in one of - * the accept or ignore functions of the transmitter, a zero port number represents - * all ports for the specified IP address. - */ -class JRTPLIB_IMPORTEXPORT RTPIPv6Address : public RTPAddress -{ -public: - /** Creates an instance with IP address and port number set to zero. */ - RTPIPv6Address():RTPAddress(IPv6Address) { for (int i = 0 ; i < 16 ; i++) ip.s6_addr[i] = 0; port = 0; } - - /** Creates an instance with IP address \c ip and port number \c port (the port number is assumed to be in - * host byte order). */ - RTPIPv6Address(const uint8_t ip[16],uint16_t port = 0):RTPAddress(IPv6Address) { SetIP(ip); RTPIPv6Address::port = port; } - - /** Creates an instance with IP address \c ip and port number \c port (the port number is assumed to be in - * host byte order). */ - RTPIPv6Address(in6_addr ip,uint16_t port = 0):RTPAddress(IPv6Address) { RTPIPv6Address::ip = ip; RTPIPv6Address::port = port; } - ~RTPIPv6Address() { } - - /** Sets the IP address for this instance to \c ip. */ - void SetIP(in6_addr ip) { RTPIPv6Address::ip = ip; } - - /** Sets the IP address for this instance to \c ip. */ - void SetIP(const uint8_t ip[16]) { for (int i = 0 ; i < 16 ; i++) RTPIPv6Address::ip.s6_addr[i] = ip[i]; } - - /** Sets the port number for this instance to \c port, which is interpreted in host byte order. */ - void SetPort(uint16_t port) { RTPIPv6Address::port = port; } - - /** Copies the IP address of this instance in \c ip. */ - void GetIP(uint8_t ip[16]) const { for (int i = 0 ; i < 16 ; i++) ip[i] = RTPIPv6Address::ip.s6_addr[i]; } - - /** Returns the IP address of this instance. */ - in6_addr GetIP() const { return ip; } - - /** Returns the port number contained in this instance in host byte order. */ - uint16_t GetPort() const { return port; } - - RTPAddress *CreateCopy(RTPMemoryManager *mgr) const; - bool IsSameAddress(const RTPAddress *addr) const; - bool IsFromSameHost(const RTPAddress *addr) const; - -private: - in6_addr ip; - uint16_t port; -}; - -} // end namespace - -#endif // RTP_SUPPORT_IPV6 - -#endif // RTPIPV6ADDRESS_H - diff --git a/qrtplib/rtpipv6destination.cpp b/qrtplib/rtpipv6destination.cpp deleted file mode 100644 index d52c02e83..000000000 --- a/qrtplib/rtpipv6destination.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - - This file is a part of JRTPLIB - Copyright (c) 1999-2011 Jori Liesenborgs - - Contact: jori.liesenborgs@gmail.com - - This library was developed at the Expertise Centre for Digital Media - (http://www.edm.uhasselt.be), a research center of the Hasselt University - (http://www.uhasselt.be). The library is based upon work done for - my thesis at the School for Knowledge Technology (Belgium/The Netherlands). - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - IN THE SOFTWARE. - -*/ - -#include "rtpipv6destination.h" - -#ifdef RTP_SUPPORT_IPV6 - -#include "rtpinternalutils.h" - -namespace qrtplib -{ - -std::string RTPIPv6Destination::GetDestinationString() const -{ - uint16_t ip16[8]; - char str[48]; - uint16_t portbase = ntohs(rtpaddr.sin6_port); - int i,j; - for (i = 0,j = 0 ; j < 8 ; j++,i += 2) - { - ip16[j] = (((uint16_t)rtpaddr.sin6_addr.s6_addr[i])<<8); - ip16[j] |= ((uint16_t)rtpaddr.sin6_addr.s6_addr[i+1]); - } - RTP_SNPRINTF(str,48,"%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X/%d",(int)ip16[0],(int)ip16[1],(int)ip16[2],(int)ip16[3],(int)ip16[4],(int)ip16[5],(int)ip16[6],(int)ip16[7],(int)portbase); - return std::string(str); -} - -} // end namespace - -#endif // RTP_SUPPORT_IPV6 - - diff --git a/qrtplib/rtpipv6destination.h b/qrtplib/rtpipv6destination.h deleted file mode 100644 index c04808a35..000000000 --- a/qrtplib/rtpipv6destination.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - - This file is a part of JRTPLIB - Copyright (c) 1999-2017 Jori Liesenborgs - - Contact: jori.liesenborgs@gmail.com - - This library was developed at the Expertise Centre for Digital Media - (http://www.edm.uhasselt.be), a research center of the Hasselt University - (http://www.uhasselt.be). The library is based upon work done for - my thesis at the School for Knowledge Technology (Belgium/The Netherlands). - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - IN THE SOFTWARE. - -*/ - -/** - * \file rtpipv6destination.h - */ - -#ifndef RTPIPV6DESTINATION_H - -#define RTPIPV6DESTINATION_H - -#include "rtpconfig.h" - -#ifdef RTP_SUPPORT_IPV6 - -#include "rtptypes.h" -#include -#include -#ifndef RTP_SOCKETTYPE_WINSOCK - #include - #include - #include -#endif // RTP_SOCKETTYPE_WINSOCK - -namespace qrtplib -{ - -class JRTPLIB_IMPORTEXPORT RTPIPv6Destination -{ -public: - RTPIPv6Destination(in6_addr ip,uint16_t portbase) - { - memset(&rtpaddr,0,sizeof(struct sockaddr_in6)); - memset(&rtcpaddr,0,sizeof(struct sockaddr_in6)); - rtpaddr.sin6_family = AF_INET6; - rtpaddr.sin6_port = htons(portbase); - rtpaddr.sin6_addr = ip; - rtcpaddr.sin6_family = AF_INET6; - rtcpaddr.sin6_port = htons(portbase+1); - rtcpaddr.sin6_addr = ip; - } - in6_addr GetIP() const { return rtpaddr.sin6_addr; } - bool operator==(const RTPIPv6Destination &src) const - { - if (rtpaddr.sin6_port == src.rtpaddr.sin6_port && (memcmp(&(src.rtpaddr.sin6_addr),&(rtpaddr.sin6_addr),sizeof(in6_addr)) == 0)) - return true; - return false; - } - const struct sockaddr_in6 *GetRTPSockAddr() const { return &rtpaddr; } - const struct sockaddr_in6 *GetRTCPSockAddr() const { return &rtcpaddr; } - std::string GetDestinationString() const; -private: - struct sockaddr_in6 rtpaddr; - struct sockaddr_in6 rtcpaddr; -}; - -} // end namespace - -#endif // RTP_SUPPORT_IPV6 - -#endif // RTPIPV6DESTINATION_H - diff --git a/qrtplib/rtppacket.cpp b/qrtplib/rtppacket.cpp index ed31a36ac..46eaabcc2 100644 --- a/qrtplib/rtppacket.cpp +++ b/qrtplib/rtppacket.cpp @@ -35,9 +35,6 @@ #include "rtpdefines.h" #include "rtperrors.h" #include "rtprawpacket.h" -#ifdef RTP_SUPPORT_NETINET_IN - #include -#endif // RTP_SUPPORT_NETINET_IN #include namespace qrtplib @@ -153,7 +150,7 @@ int RTPPacket::ParseRawPacket(RTPRawPacket &rawpack) rtpextheader = (RTPExtensionHeader *)(packetbytes+payloadoffset); payloadoffset += sizeof(RTPExtensionHeader); - uint16_t exthdrlen = ntohs(rtpextheader->length); + uint16_t exthdrlen = m_endian.qToHost(rtpextheader->length); payloadoffset += ((int)exthdrlen)*sizeof(uint32_t); } else @@ -171,8 +168,8 @@ int RTPPacket::ParseRawPacket(RTPRawPacket &rawpack) RTPPacket::hasextension = hasextension; if (hasextension) { - RTPPacket::extid = ntohs(rtpextheader->extid); - RTPPacket::extensionlength = ((int)ntohs(rtpextheader->length))*sizeof(uint32_t); + RTPPacket::extid = m_endian.qToHost(rtpextheader->extid); + RTPPacket::extensionlength = ((int)m_endian.qToHost(rtpextheader->length))*sizeof(uint32_t); RTPPacket::extension = ((uint8_t *)rtpextheader)+sizeof(RTPExtensionHeader); } @@ -183,10 +180,10 @@ int RTPPacket::ParseRawPacket(RTPRawPacket &rawpack) // Note: we don't fill in the EXTENDED sequence number here, since we // don't have information about the source here. We just fill in the low // 16 bits - RTPPacket::extseqnr = (uint32_t)ntohs(rtpheader->sequencenumber); + RTPPacket::extseqnr = (uint32_t)m_endian.qToHost(rtpheader->sequencenumber); - RTPPacket::timestamp = ntohl(rtpheader->timestamp); - RTPPacket::ssrc = ntohl(rtpheader->ssrc); + RTPPacket::timestamp = m_endian.qToHost(rtpheader->timestamp); + RTPPacket::ssrc = m_endian.qToHost(rtpheader->ssrc); RTPPacket::packet = packetbytes; RTPPacket::payload = packetbytes+payloadoffset; RTPPacket::packetlength = packetlen; @@ -209,7 +206,7 @@ uint32_t RTPPacket::GetCSRC(int num) const csrcpos = packet+sizeof(RTPHeader)+num*sizeof(uint32_t); csrcval_nbo = (uint32_t *)csrcpos; - csrcval_hbo = ntohl(*csrcval_nbo); + csrcval_hbo = m_endian.qToHost(*csrcval_nbo); return csrcval_hbo; } @@ -285,24 +282,24 @@ int RTPPacket::BuildPacket(uint8_t payloadtype,const void *payloaddata,size_t pa rtphdr->extension = 0; rtphdr->csrccount = numcsrcs; rtphdr->payloadtype = payloadtype&127; // make sure high bit isn't set - rtphdr->sequencenumber = htons(seqnr); - rtphdr->timestamp = htonl(timestamp); - rtphdr->ssrc = htonl(ssrc); + rtphdr->sequencenumber = qToBigEndian(seqnr); + rtphdr->timestamp = qToBigEndian(timestamp); + rtphdr->ssrc = qToBigEndian(ssrc); uint32_t *curcsrc; int i; curcsrc = (uint32_t *)(packet+sizeof(RTPHeader)); for (i = 0 ; i < numcsrcs ; i++,curcsrc++) - *curcsrc = htonl(csrcs[i]); + *curcsrc = qToBigEndian(csrcs[i]); payload = packet+sizeof(RTPHeader)+((size_t)numcsrcs)*sizeof(uint32_t); if (gotextension) { RTPExtensionHeader *rtpexthdr = (RTPExtensionHeader *)payload; - rtpexthdr->extid = htons(extensionid); - rtpexthdr->length = htons((uint16_t)extensionlen_numwords); + rtpexthdr->extid = qToBigEndian(extensionid); + rtpexthdr->length = qToBigEndian((uint16_t)extensionlen_numwords); payload += sizeof(RTPExtensionHeader); memcpy(payload,extensiondata,RTPPacket::extensionlength); diff --git a/qrtplib/rtppacket.h b/qrtplib/rtppacket.h index b620f0642..fa4dea018 100644 --- a/qrtplib/rtppacket.h +++ b/qrtplib/rtppacket.h @@ -42,6 +42,7 @@ #include "rtptypes.h" #include "rtptimeutilities.h" #include "rtpmemoryobject.h" +#include "rtpendian.h" namespace qrtplib { @@ -155,6 +156,7 @@ private: bool gotextension,uint16_t extensionid,uint16_t extensionlen_numwords,const void *extensiondata, void *buffer,size_t maxsize); + RTPEndian m_endian; int error; bool hasextension,hasmarker; diff --git a/qrtplib/rtpsession.cpp b/qrtplib/rtpsession.cpp index d5dabde2b..7b5f83d3c 100644 --- a/qrtplib/rtpsession.cpp +++ b/qrtplib/rtpsession.cpp @@ -33,7 +33,6 @@ #include "rtpsession.h" #include "rtperrors.h" #include "rtpudpv4transmitter.h" -#include "rtpudpv6transmitter.h" #include "rtptcptransmitter.h" #include "rtpexternaltransmitter.h" #include "rtpsessionparams.h" @@ -121,11 +120,6 @@ int RTPSession::Create(const RTPSessionParams &sessparams,const RTPTransmissionP case RTPTransmitter::IPv4UDPProto: rtptrans = RTPNew(GetMemoryManager(),RTPMEM_TYPE_CLASS_RTPTRANSMITTER) RTPUDPv4Transmitter(GetMemoryManager()); break; -#ifdef RTP_SUPPORT_IPV6 - case RTPTransmitter::IPv6UDPProto: - rtptrans = RTPNew(GetMemoryManager(),RTPMEM_TYPE_CLASS_RTPTRANSMITTER) RTPUDPv6Transmitter(GetMemoryManager()); - break; -#endif // RTP_SUPPORT_IPV6 case RTPTransmitter::ExternalProto: rtptrans = RTPNew(GetMemoryManager(),RTPMEM_TYPE_CLASS_RTPTRANSMITTER) RTPExternalTransmitter(GetMemoryManager()); break; diff --git a/qrtplib/rtpsourcedata.cpp b/qrtplib/rtpsourcedata.cpp index 8387b56d0..d02befacc 100644 --- a/qrtplib/rtpsourcedata.cpp +++ b/qrtplib/rtpsourcedata.cpp @@ -34,9 +34,6 @@ #include "rtpdefines.h" #include "rtpaddress.h" #include "rtpmemorymanager.h" -#ifdef RTP_SUPPORT_NETINET_IN - #include -#endif // RTP_SUPPORT_NETINET_IN #define ACCEPTPACKETCODE \ diff --git a/qrtplib/rtpudpv6transmitter.cpp b/qrtplib/rtpudpv6transmitter.cpp deleted file mode 100644 index 3caccfc3b..000000000 --- a/qrtplib/rtpudpv6transmitter.cpp +++ /dev/null @@ -1,1621 +0,0 @@ -/* - - This file is a part of JRTPLIB - Copyright (c) 1999-2017 Jori Liesenborgs - - Contact: jori.liesenborgs@gmail.com - - This library was developed at the Expertise Centre for Digital Media - (http://www.edm.uhasselt.be), a research center of the Hasselt University - (http://www.uhasselt.be). The library is based upon work done for - my thesis at the School for Knowledge Technology (Belgium/The Netherlands). - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - IN THE SOFTWARE. - -*/ - -// This is for getaddrinfo when using mingw -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0600 -#endif - -#include "rtpudpv6transmitter.h" - -#ifdef RTP_SUPPORT_IPV6 - -#include "rtprawpacket.h" -#include "rtpipv6address.h" -#include "rtptimeutilities.h" -#include "rtpdefines.h" -#include "rtpsocketutilinternal.h" -#include "rtpinternalutils.h" -#include "rtpselect.h" -#include - -#define RTPUDPV6TRANS_MAXPACKSIZE 65535 -#define RTPUDPV6TRANS_IFREQBUFSIZE 8192 - -#define RTPUDPV6TRANS_IS_MCASTADDR(x) (x.s6_addr[0] == 0xFF) - -#define RTPUDPV6TRANS_MCASTMEMBERSHIP(socket,type,mcastip,status) {\ - struct ipv6_mreq mreq;\ - \ - mreq.ipv6mr_multiaddr = mcastip;\ - mreq.ipv6mr_interface = mcastifidx;\ - status = setsockopt(socket,IPPROTO_IPV6,type,(const char *)&mreq,sizeof(struct ipv6_mreq));\ - } -#define MAINMUTEX_LOCK -#define MAINMUTEX_UNLOCK -#define WAITMUTEX_LOCK -#define WAITMUTEX_UNLOCK - -inline bool operator==(const in6_addr &ip1,const in6_addr &ip2) -{ - if (memcmp(&ip1,&ip2,sizeof(in6_addr)) == 0) - return true; - return false; -} - -namespace qrtplib -{ - -RTPUDPv6Transmitter::RTPUDPv6Transmitter(RTPMemoryManager *mgr) : RTPTransmitter(mgr), - destinations(GetMemoryManager(),RTPMEM_TYPE_CLASS_DESTINATIONLISTHASHELEMENT), - multicastgroups(GetMemoryManager(),RTPMEM_TYPE_CLASS_MULTICASTHASHELEMENT), - acceptignoreinfo(GetMemoryManager(),RTPMEM_TYPE_CLASS_ACCEPTIGNOREHASHELEMENT) -{ - created = false; - init = false; -} - -RTPUDPv6Transmitter::~RTPUDPv6Transmitter() -{ - Destroy(); -} - -int RTPUDPv6Transmitter::Init(bool tsafe) -{ - if (init) - return ERR_RTP_UDPV6TRANS_ALREADYINIT; - - if (tsafe) - return ERR_RTP_NOTHREADSUPPORT; - - init = true; - return 0; -} - -int RTPUDPv6Transmitter::Create(size_t maximumpacketsize,const RTPTransmissionParams *transparams) -{ - const RTPUDPv6TransmissionParams *params,defaultparams; - struct sockaddr_in6 addr; - RTPSOCKLENTYPE size; - int status; - - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - if (created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_ALREADYCREATED; - } - - // Obtain transmission parameters - - if (transparams == 0) - params = &defaultparams; - else - { - if (transparams->GetTransmissionProtocol() != RTPTransmitter::IPv6UDPProto) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_ILLEGALPARAMETERS; - } - params = (const RTPUDPv6TransmissionParams *)transparams; - } - - // Check if portbase is even - if (params->GetPortbase()%2 != 0) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_PORTBASENOTEVEN; - } - - // create sockets - - rtpsock = socket(PF_INET6,SOCK_DGRAM,0); - if (rtpsock == RTPSOCKERR) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_CANTCREATESOCKET; - } - rtcpsock = socket(PF_INET6,SOCK_DGRAM,0); - if (rtcpsock == RTPSOCKERR) - { - RTPCLOSE(rtpsock); - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_CANTCREATESOCKET; - } - - // set socket buffer sizes - - size = params->GetRTPReceiveBuffer(); - if (setsockopt(rtpsock,SOL_SOCKET,SO_RCVBUF,(const char *)&size,sizeof(int)) != 0) - { - RTPCLOSE(rtpsock); - RTPCLOSE(rtcpsock); - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_CANTSETRTPRECEIVEBUF; - } - size = params->GetRTPSendBuffer(); - if (setsockopt(rtpsock,SOL_SOCKET,SO_SNDBUF,(const char *)&size,sizeof(int)) != 0) - { - RTPCLOSE(rtpsock); - RTPCLOSE(rtcpsock); - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_CANTSETRTPTRANSMITBUF; - } - size = params->GetRTCPReceiveBuffer(); - if (setsockopt(rtcpsock,SOL_SOCKET,SO_RCVBUF,(const char *)&size,sizeof(int)) != 0) - { - RTPCLOSE(rtpsock); - RTPCLOSE(rtcpsock); - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_CANTSETRTCPRECEIVEBUF; - } - size = params->GetRTCPSendBuffer(); - if (setsockopt(rtcpsock,SOL_SOCKET,SO_SNDBUF,(const char *)&size,sizeof(int)) != 0) - { - RTPCLOSE(rtpsock); - RTPCLOSE(rtcpsock); - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_CANTSETRTCPTRANSMITBUF; - } - - // bind sockets - - bindIP = params->GetBindIP(); - mcastifidx = params->GetMulticastInterfaceIndex(); - - memset(&addr,0,sizeof(struct sockaddr_in6)); - addr.sin6_family = AF_INET6; - addr.sin6_port = htons(params->GetPortbase()); - addr.sin6_addr = bindIP; - if (bind(rtpsock,(struct sockaddr *)&addr,sizeof(struct sockaddr_in6)) != 0) - { - RTPCLOSE(rtpsock); - RTPCLOSE(rtcpsock); - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_CANTBINDRTPSOCKET; - } - memset(&addr,0,sizeof(struct sockaddr_in6)); - addr.sin6_family = AF_INET6; - addr.sin6_port = htons(params->GetPortbase()+1); - addr.sin6_addr = bindIP; - if (bind(rtcpsock,(struct sockaddr *)&addr,sizeof(struct sockaddr_in6)) != 0) - { - RTPCLOSE(rtpsock); - RTPCLOSE(rtcpsock); - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_CANTBINDRTCPSOCKET; - } - - // Try to obtain local IP addresses - - localIPs = params->GetLocalIPList(); - if (localIPs.empty()) // User did not provide list of local IP addresses, calculate them - { - int status; - - if ((status = CreateLocalIPList()) < 0) - { - RTPCLOSE(rtpsock); - RTPCLOSE(rtcpsock); - MAINMUTEX_UNLOCK - return status; - } - - } - -#ifdef RTP_SUPPORT_IPV6MULTICAST - if (SetMulticastTTL(params->GetMulticastTTL())) - supportsmulticasting = true; - else - supportsmulticasting = false; -#else // no multicast support enabled - supportsmulticasting = false; -#endif // RTP_SUPPORT_IPV6MULTICAST - - if (maximumpacketsize > RTPUDPV6TRANS_MAXPACKSIZE) - { - RTPCLOSE(rtpsock); - RTPCLOSE(rtcpsock); - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_SPECIFIEDSIZETOOBIG; - } - - if (!params->GetCreatedAbortDescriptors()) - { - if ((status = m_abortDesc.Init()) < 0) - { - RTPCLOSE(rtpsock); - RTPCLOSE(rtcpsock); - MAINMUTEX_UNLOCK - return status; - } - m_pAbortDesc = &m_abortDesc; - } - else - { - m_pAbortDesc = params->GetCreatedAbortDescriptors(); - if (!m_pAbortDesc->IsInitialized()) - { - RTPCLOSE(rtpsock); - RTPCLOSE(rtcpsock); - MAINMUTEX_UNLOCK - return ERR_RTP_ABORTDESC_NOTINIT; - } - } - - maxpacksize = maximumpacketsize; - portbase = params->GetPortbase(); - multicastTTL = params->GetMulticastTTL(); - receivemode = RTPTransmitter::AcceptAll; - - localhostname = 0; - localhostnamelength = 0; - - waitingfordata = false; - created = true; - MAINMUTEX_UNLOCK - return 0; -} - -void RTPUDPv6Transmitter::Destroy() -{ - if (!init) - return; - - MAINMUTEX_LOCK - if (!created) - { - MAINMUTEX_UNLOCK; - return; - } - - if (localhostname) - { - RTPDeleteByteArray(localhostname,GetMemoryManager()); - localhostname = 0; - localhostnamelength = 0; - } - - RTPCLOSE(rtpsock); - RTPCLOSE(rtcpsock); - destinations.Clear(); -#ifdef RTP_SUPPORT_IPV6MULTICAST - multicastgroups.Clear(); -#endif // RTP_SUPPORT_IPV6MULTICAST - FlushPackets(); - ClearAcceptIgnoreInfo(); - localIPs.clear(); - created = false; - - if (waitingfordata) - { - m_pAbortDesc->SendAbortSignal(); - m_abortDesc.Destroy(); // Doesn't do anything if not initialized - MAINMUTEX_UNLOCK - WAITMUTEX_LOCK // to make sure that the WaitForIncomingData function ended - WAITMUTEX_UNLOCK - } - else - m_abortDesc.Destroy(); // Doesn't do anything if not initialized - - MAINMUTEX_UNLOCK -} - -RTPTransmissionInfo *RTPUDPv6Transmitter::GetTransmissionInfo() -{ - if (!init) - return 0; - - MAINMUTEX_LOCK - RTPTransmissionInfo *tinf = RTPNew(GetMemoryManager(),RTPMEM_TYPE_CLASS_RTPTRANSMISSIONINFO) RTPUDPv6TransmissionInfo(localIPs,rtpsock,rtcpsock,portbase,portbase+1); - MAINMUTEX_UNLOCK - return tinf; -} - -void RTPUDPv6Transmitter::DeleteTransmissionInfo(RTPTransmissionInfo *i) -{ - if (!init) - return; - - RTPDelete(i, GetMemoryManager()); -} - -int RTPUDPv6Transmitter::GetLocalHostName(uint8_t *buffer,size_t *bufferlength) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - - if (localhostname == 0) - { - if (localIPs.empty()) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOLOCALIPS; - } - - std::list::const_iterator it; - std::list hostnames; - - for (it = localIPs.begin() ; it != localIPs.end() ; it++) - { - bool founddouble = false; - bool foundentry = true; - - while (!founddouble && foundentry) - { - struct hostent *he; - in6_addr ip = (*it); - - he = gethostbyaddr((char *)&ip,sizeof(in6_addr),AF_INET6); - if (he != 0) - { - std::string hname = std::string(he->h_name); - std::list::const_iterator it; - - for (it = hostnames.begin() ; !founddouble && it != hostnames.end() ; it++) - if ((*it) == hname) - founddouble = true; - - if (!founddouble) - hostnames.push_back(hname); - - int i = 0; - while (!founddouble && he->h_aliases[i] != 0) - { - std::string hname = std::string(he->h_aliases[i]); - - for (it = hostnames.begin() ; !founddouble && it != hostnames.end() ; it++) - if ((*it) == hname) - founddouble = true; - - if (!founddouble) - { - hostnames.push_back(hname); - i++; - } - } - } - else - foundentry = false; - } - } - - bool found = false; - - if (!hostnames.empty()) // try to select the most appropriate hostname - { - std::list::const_iterator it; - - hostnames.sort(); - for (it = hostnames.begin() ; !found && it != hostnames.end() ; it++) - { - if ((*it).find('.') != std::string::npos) - { - found = true; - localhostnamelength = (*it).length(); - localhostname = RTPNew(GetMemoryManager(),RTPMEM_TYPE_OTHER) uint8_t [localhostnamelength+1]; - if (localhostname == 0) - { - MAINMUTEX_UNLOCK - return ERR_RTP_OUTOFMEM; - } - memcpy(localhostname,(*it).c_str(),localhostnamelength); - localhostname[localhostnamelength] = 0; - } - } - } - - if (!found) // use an IP address - { - in6_addr ip; - int len; - char str[48]; - uint16_t ip16[8]; - int i,j; - - it = localIPs.begin(); - ip = (*it); - - for (i = 0,j = 0 ; j < 8 ; j++,i += 2) - { - ip16[j] = (((uint16_t)ip.s6_addr[i])<<8); - ip16[j] |= ((uint16_t)ip.s6_addr[i+1]); - } - - RTP_SNPRINTF(str,48,"%04X:%04X:%04X:%04X:%04X:%04X:%04X:%04X",(int)ip16[0],(int)ip16[1],(int)ip16[2],(int)ip16[3],(int)ip16[4],(int)ip16[5],(int)ip16[6],(int)ip16[7]); - len = strlen(str); - - localhostnamelength = len; - localhostname = RTPNew(GetMemoryManager(),RTPMEM_TYPE_OTHER) uint8_t [localhostnamelength+1]; - if (localhostname == 0) - { - MAINMUTEX_UNLOCK - return ERR_RTP_OUTOFMEM; - } - memcpy(localhostname,str,localhostnamelength); - localhostname[localhostnamelength] = 0; - } - } - - if ((*bufferlength) < localhostnamelength) - { - *bufferlength = localhostnamelength; // tell the application the required size of the buffer - MAINMUTEX_UNLOCK - return ERR_RTP_TRANS_BUFFERLENGTHTOOSMALL; - } - - memcpy(buffer,localhostname,localhostnamelength); - *bufferlength = localhostnamelength; - - MAINMUTEX_UNLOCK - return 0; -} - -bool RTPUDPv6Transmitter::ComesFromThisTransmitter(const RTPAddress *addr) -{ - if (!init) - return false; - - if (addr == 0) - return false; - - MAINMUTEX_LOCK - - bool v; - - if (created && addr->GetAddressType() == RTPAddress::IPv6Address) - { - const RTPIPv6Address *addr2 = (const RTPIPv6Address *)addr; - bool found = false; - std::list::const_iterator it; - - it = localIPs.begin(); - while (!found && it != localIPs.end()) - { - in6_addr itip = *it; - in6_addr addrip = addr2->GetIP(); - if (memcmp(&addrip,&itip,sizeof(in6_addr)) == 0) - found = true; - else - ++it; - } - - if (!found) - v = false; - else - { - if (addr2->GetPort() == portbase) // check for RTP port - v = true; - else if (addr2->GetPort() == (portbase+1)) // check for RTCP port - v = true; - else - v = false; - } - } - else - v = false; - - MAINMUTEX_UNLOCK - return v; -} - -int RTPUDPv6Transmitter::Poll() -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - int status; - - MAINMUTEX_LOCK - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - status = PollSocket(true); // poll RTP socket - if (status >= 0) - status = PollSocket(false); // poll RTCP socket - MAINMUTEX_UNLOCK - return status; -} - -int RTPUDPv6Transmitter::WaitForIncomingData(const RTPTime &delay,bool *dataavailable) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (waitingfordata) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_ALREADYWAITING; - } - - SocketType abortSocket = m_pAbortDesc->GetAbortSocket(); - SocketType socks[3] = { rtpsock, rtcpsock, abortSocket }; - int8_t readflags[3] = { 0, 0, 0 }; - const int idxRTP = 0; - const int idxRTCP = 1; - const int idxAbort = 2; - - waitingfordata = true; - - WAITMUTEX_LOCK - MAINMUTEX_UNLOCK - - int status = RTPSelect(socks, readflags, 3, delay); - if (status < 0) - { - MAINMUTEX_LOCK - waitingfordata = false; - MAINMUTEX_UNLOCK - WAITMUTEX_UNLOCK - return status; - } - - MAINMUTEX_LOCK - waitingfordata = false; - if (!created) // destroy called - { - MAINMUTEX_UNLOCK; - WAITMUTEX_UNLOCK - return 0; - } - - // if aborted, read from abort buffer - if (readflags[idxAbort]) - m_pAbortDesc->ReadSignallingByte(); - - if (dataavailable != 0) - { - if (readflags[idxRTP] || readflags[idxRTCP]) - *dataavailable = true; - else - *dataavailable = false; - } - - MAINMUTEX_UNLOCK - WAITMUTEX_UNLOCK - return 0; -} - -int RTPUDPv6Transmitter::AbortWait() -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (!waitingfordata) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTWAITING; - } - - m_pAbortDesc->SendAbortSignal(); - - MAINMUTEX_UNLOCK - return 0; -} - -int RTPUDPv6Transmitter::SendRTPData(const void *data,size_t len) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (len > maxpacksize) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_SPECIFIEDSIZETOOBIG; - } - - destinations.GotoFirstElement(); - while (destinations.HasCurrentElement()) - { - sendto(rtpsock,(const char *)data,len,0,(const struct sockaddr *)destinations.GetCurrentElement().GetRTPSockAddr(),sizeof(struct sockaddr_in6)); - destinations.GotoNextElement(); - } - - MAINMUTEX_UNLOCK - return 0; -} - -int RTPUDPv6Transmitter::SendRTCPData(const void *data,size_t len) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (len > maxpacksize) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_SPECIFIEDSIZETOOBIG; - } - - destinations.GotoFirstElement(); - while (destinations.HasCurrentElement()) - { - sendto(rtcpsock,(const char *)data,len,0,(const struct sockaddr *)destinations.GetCurrentElement().GetRTCPSockAddr(),sizeof(struct sockaddr_in6)); - destinations.GotoNextElement(); - } - - MAINMUTEX_UNLOCK - return 0; -} - -int RTPUDPv6Transmitter::AddDestination(const RTPAddress &addr) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (addr.GetAddressType() != RTPAddress::IPv6Address) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_INVALIDADDRESSTYPE; - } - - RTPIPv6Address &address = (RTPIPv6Address &)addr; - RTPIPv6Destination dest(address.GetIP(),address.GetPort()); - int status = destinations.AddElement(dest); - - MAINMUTEX_UNLOCK - return status; -} - -int RTPUDPv6Transmitter::DeleteDestination(const RTPAddress &addr) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (addr.GetAddressType() != RTPAddress::IPv6Address) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_INVALIDADDRESSTYPE; - } - - RTPIPv6Address &address = (RTPIPv6Address &)addr; - RTPIPv6Destination dest(address.GetIP(),address.GetPort()); - int status = destinations.DeleteElement(dest); - - MAINMUTEX_UNLOCK - return status; -} - -void RTPUDPv6Transmitter::ClearDestinations() -{ - if (!init) - return; - - MAINMUTEX_LOCK - if (created) - destinations.Clear(); - MAINMUTEX_UNLOCK -} - -bool RTPUDPv6Transmitter::SupportsMulticasting() -{ - if (!init) - return false; - - MAINMUTEX_LOCK - - bool v; - - if (!created) - v = false; - else - v = supportsmulticasting; - - MAINMUTEX_UNLOCK - return v; -} - -#ifdef RTP_SUPPORT_IPV6MULTICAST - -int RTPUDPv6Transmitter::JoinMulticastGroup(const RTPAddress &addr) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - int status; - - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (addr.GetAddressType() != RTPAddress::IPv6Address) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_INVALIDADDRESSTYPE; - } - - const RTPIPv6Address &address = (const RTPIPv6Address &)addr; - in6_addr mcastIP = address.GetIP(); - - if (!RTPUDPV6TRANS_IS_MCASTADDR(mcastIP)) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTAMULTICASTADDRESS; - } - - status = multicastgroups.AddElement(mcastIP); - if (status >= 0) - { - RTPUDPV6TRANS_MCASTMEMBERSHIP(rtpsock,IPV6_JOIN_GROUP,mcastIP,status); - if (status != 0) - { - multicastgroups.DeleteElement(mcastIP); - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_COULDNTJOINMULTICASTGROUP; - } - RTPUDPV6TRANS_MCASTMEMBERSHIP(rtcpsock,IPV6_JOIN_GROUP,mcastIP,status); - if (status != 0) - { - RTPUDPV6TRANS_MCASTMEMBERSHIP(rtpsock,IPV6_LEAVE_GROUP,mcastIP,status); - multicastgroups.DeleteElement(mcastIP); - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_COULDNTJOINMULTICASTGROUP; - } - } - MAINMUTEX_UNLOCK - return status; -} - -int RTPUDPv6Transmitter::LeaveMulticastGroup(const RTPAddress &addr) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - int status; - - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (addr.GetAddressType() != RTPAddress::IPv6Address) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_INVALIDADDRESSTYPE; - } - - const RTPIPv6Address &address = (const RTPIPv6Address &)addr; - in6_addr mcastIP = address.GetIP(); - - if (!RTPUDPV6TRANS_IS_MCASTADDR(mcastIP)) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTAMULTICASTADDRESS; - } - - status = multicastgroups.DeleteElement(mcastIP); - if (status >= 0) - { - RTPUDPV6TRANS_MCASTMEMBERSHIP(rtpsock,IPV6_LEAVE_GROUP,mcastIP,status); - RTPUDPV6TRANS_MCASTMEMBERSHIP(rtcpsock,IPV6_LEAVE_GROUP,mcastIP,status); - status = 0; - } - - MAINMUTEX_UNLOCK - return status; -} - -void RTPUDPv6Transmitter::LeaveAllMulticastGroups() -{ - if (!init) - return; - - MAINMUTEX_LOCK - if (created) - { - multicastgroups.GotoFirstElement(); - while (multicastgroups.HasCurrentElement()) - { - in6_addr mcastIP; - int status = 0; - - mcastIP = multicastgroups.GetCurrentElement(); - RTPUDPV6TRANS_MCASTMEMBERSHIP(rtpsock,IPV6_LEAVE_GROUP,mcastIP,status); - RTPUDPV6TRANS_MCASTMEMBERSHIP(rtcpsock,IPV6_LEAVE_GROUP,mcastIP,status); - multicastgroups.GotoNextElement(); - JRTPLIB_UNUSED(status); - } - multicastgroups.Clear(); - } - MAINMUTEX_UNLOCK -} - -#else // no multicast support - -int RTPUDPv6Transmitter::JoinMulticastGroup(const RTPAddress &addr) -{ - return ERR_RTP_UDPV6TRANS_NOMULTICASTSUPPORT; -} - -int RTPUDPv6Transmitter::LeaveMulticastGroup(const RTPAddress &addr) -{ - return ERR_RTP_UDPV6TRANS_NOMULTICASTSUPPORT; -} - -void RTPUDPv6Transmitter::LeaveAllMulticastGroups() -{ -} - -#endif // RTP_SUPPORT_IPV6MULTICAST - -int RTPUDPv6Transmitter::SetReceiveMode(RTPTransmitter::ReceiveMode m) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (m != receivemode) - { - receivemode = m; - acceptignoreinfo.Clear(); - } - MAINMUTEX_UNLOCK - return 0; -} - -int RTPUDPv6Transmitter::AddToIgnoreList(const RTPAddress &addr) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - int status; - - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (addr.GetAddressType() != RTPAddress::IPv6Address) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_INVALIDADDRESSTYPE; - } - if (receivemode != RTPTransmitter::IgnoreSome) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_DIFFERENTRECEIVEMODE; - } - - const RTPIPv6Address &address = (const RTPIPv6Address &)addr; - status = ProcessAddAcceptIgnoreEntry(address.GetIP(),address.GetPort()); - - MAINMUTEX_UNLOCK - return status; -} - -int RTPUDPv6Transmitter::DeleteFromIgnoreList(const RTPAddress &addr) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - int status; - - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (addr.GetAddressType() != RTPAddress::IPv6Address) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_INVALIDADDRESSTYPE; - } - if (receivemode != RTPTransmitter::IgnoreSome) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_DIFFERENTRECEIVEMODE; - } - - const RTPIPv6Address &address = (const RTPIPv6Address &)addr; - status = ProcessDeleteAcceptIgnoreEntry(address.GetIP(),address.GetPort()); - - MAINMUTEX_UNLOCK - return status; -} - -void RTPUDPv6Transmitter::ClearIgnoreList() -{ - if (!init) - return; - - MAINMUTEX_LOCK - if (created && receivemode == RTPTransmitter::IgnoreSome) - ClearAcceptIgnoreInfo(); - MAINMUTEX_UNLOCK -} - -int RTPUDPv6Transmitter::AddToAcceptList(const RTPAddress &addr) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - int status; - - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (addr.GetAddressType() != RTPAddress::IPv6Address) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_INVALIDADDRESSTYPE; - } - if (receivemode != RTPTransmitter::AcceptSome) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_DIFFERENTRECEIVEMODE; - } - - const RTPIPv6Address &address = (const RTPIPv6Address &)addr; - status = ProcessAddAcceptIgnoreEntry(address.GetIP(),address.GetPort()); - - MAINMUTEX_UNLOCK - return status; -} - -int RTPUDPv6Transmitter::DeleteFromAcceptList(const RTPAddress &addr) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - - int status; - - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (addr.GetAddressType() != RTPAddress::IPv6Address) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_INVALIDADDRESSTYPE; - } - if (receivemode != RTPTransmitter::AcceptSome) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_DIFFERENTRECEIVEMODE; - } - - const RTPIPv6Address &address = (const RTPIPv6Address &)addr; - status = ProcessDeleteAcceptIgnoreEntry(address.GetIP(),address.GetPort()); - - MAINMUTEX_UNLOCK - return status; -} - -void RTPUDPv6Transmitter::ClearAcceptList() -{ - if (!init) - return; - - MAINMUTEX_LOCK - if (created && receivemode == RTPTransmitter::AcceptSome) - ClearAcceptIgnoreInfo(); - MAINMUTEX_UNLOCK -} - -int RTPUDPv6Transmitter::SetMaximumPacketSize(size_t s) -{ - if (!init) - return ERR_RTP_UDPV6TRANS_NOTINIT; - - MAINMUTEX_LOCK - if (!created) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_NOTCREATED; - } - if (s > RTPUDPV6TRANS_MAXPACKSIZE) - { - MAINMUTEX_UNLOCK - return ERR_RTP_UDPV6TRANS_SPECIFIEDSIZETOOBIG; - } - maxpacksize = s; - MAINMUTEX_UNLOCK - return 0; -} - -bool RTPUDPv6Transmitter::NewDataAvailable() -{ - if (!init) - return false; - - MAINMUTEX_LOCK - - bool v; - - if (!created) - v = false; - else - { - if (rawpacketlist.empty()) - v = false; - else - v = true; - } - - MAINMUTEX_UNLOCK - return v; -} - -RTPRawPacket *RTPUDPv6Transmitter::GetNextPacket() -{ - if (!init) - return 0; - - MAINMUTEX_LOCK - - RTPRawPacket *p; - - if (!created) - { - MAINMUTEX_UNLOCK - return 0; - } - if (rawpacketlist.empty()) - { - MAINMUTEX_UNLOCK - return 0; - } - - p = *(rawpacketlist.begin()); - rawpacketlist.pop_front(); - - MAINMUTEX_UNLOCK - return p; -} - -// Here the private functions start... - - -#ifdef RTP_SUPPORT_IPV6MULTICAST -bool RTPUDPv6Transmitter::SetMulticastTTL(uint8_t ttl) -{ - int ttl2,status; - - ttl2 = (int)ttl; - status = setsockopt(rtpsock,IPPROTO_IPV6,IPV6_MULTICAST_HOPS,(const char *)&ttl2,sizeof(int)); - if (status != 0) - return false; - status = setsockopt(rtcpsock,IPPROTO_IPV6,IPV6_MULTICAST_HOPS,(const char *)&ttl2,sizeof(int)); - if (status != 0) - return false; - return true; -} -#endif // RTP_SUPPORT_IPV6MULTICAST - - -void RTPUDPv6Transmitter::FlushPackets() -{ - std::list::const_iterator it; - - for (it = rawpacketlist.begin() ; it != rawpacketlist.end() ; ++it) - RTPDelete(*it,GetMemoryManager()); - rawpacketlist.clear(); -} - -int RTPUDPv6Transmitter::PollSocket(bool rtp) -{ - RTPSOCKLENTYPE fromlen; - int recvlen; - char packetbuffer[RTPUDPV6TRANS_MAXPACKSIZE]; -#ifdef RTP_SOCKETTYPE_WINSOCK - SOCKET sock; - unsigned long len; -#else - size_t len; - int sock; -#endif // RTP_SOCKETTYPE_WINSOCK - struct sockaddr_in6 srcaddr; - bool dataavailable; - - if (rtp) - sock = rtpsock; - else - sock = rtcpsock; - - len = 0; - RTPIOCTL(sock,FIONREAD,&len); - - if (len <= 0) // make sure a packet of length zero is not queued - { - int8_t isset = 0; - int status = RTPSelect(&sock, &isset, 1, RTPTime(0)); - if (status < 0) - return status; - - if (isset) - dataavailable = true; - else - dataavailable = false; - } - else - dataavailable = true; - - while (dataavailable) - { - RTPTime curtime = RTPTime::CurrentTime(); - fromlen = sizeof(struct sockaddr_in6); - recvlen = recvfrom(sock,packetbuffer,RTPUDPV6TRANS_MAXPACKSIZE,0,(struct sockaddr *)&srcaddr,&fromlen); - if (recvlen > 0) - { - bool acceptdata; - - // got data, process it - if (receivemode == RTPTransmitter::AcceptAll) - acceptdata = true; - else - acceptdata = ShouldAcceptData(srcaddr.sin6_addr,ntohs(srcaddr.sin6_port)); - - if (acceptdata) - { - RTPRawPacket *pack; - RTPIPv6Address *addr; - uint8_t *datacopy; - - addr = RTPNew(GetMemoryManager(),RTPMEM_TYPE_CLASS_RTPADDRESS) RTPIPv6Address(srcaddr.sin6_addr,ntohs(srcaddr.sin6_port)); - if (addr == 0) - return ERR_RTP_OUTOFMEM; - datacopy = RTPNew(GetMemoryManager(),(rtp)?RTPMEM_TYPE_BUFFER_RECEIVEDRTPPACKET:RTPMEM_TYPE_BUFFER_RECEIVEDRTCPPACKET) uint8_t[recvlen]; - if (datacopy == 0) - { - RTPDelete(addr,GetMemoryManager()); - return ERR_RTP_OUTOFMEM; - } - memcpy(datacopy,packetbuffer,recvlen); - - pack = RTPNew(GetMemoryManager(),RTPMEM_TYPE_CLASS_RTPRAWPACKET) RTPRawPacket(datacopy,recvlen,addr,curtime,rtp,GetMemoryManager()); - if (pack == 0) - { - RTPDelete(addr,GetMemoryManager()); - RTPDeleteByteArray(datacopy,GetMemoryManager()); - return ERR_RTP_OUTOFMEM; - } - rawpacketlist.push_back(pack); - } - } - len = 0; - RTPIOCTL(sock,FIONREAD,&len); - - if (len <= 0) // make sure a packet of length zero is not queued - { - int8_t isset = 0; - int status = RTPSelect(&sock, &isset, 1, RTPTime(0)); - if (status < 0) - return status; - - if (isset) - dataavailable = true; - else - dataavailable = false; - } - else - dataavailable = true; - } - return 0; -} - -int RTPUDPv6Transmitter::ProcessAddAcceptIgnoreEntry(in6_addr ip,uint16_t port) -{ - acceptignoreinfo.GotoElement(ip); - if (acceptignoreinfo.HasCurrentElement()) // An entry for this IP address already exists - { - PortInfo *portinf = acceptignoreinfo.GetCurrentElement(); - - if (port == 0) // select all ports - { - portinf->all = true; - portinf->portlist.clear(); - } - else if (!portinf->all) - { - std::list::const_iterator it,begin,end; - - begin = portinf->portlist.begin(); - end = portinf->portlist.end(); - for (it = begin ; it != end ; it++) - { - if (*it == port) // already in list - return 0; - } - portinf->portlist.push_front(port); - } - } - else // got to create an entry for this IP address - { - PortInfo *portinf; - int status; - - portinf = RTPNew(GetMemoryManager(),RTPMEM_TYPE_CLASS_ACCEPTIGNOREPORTINFO) PortInfo(); - if (port == 0) // select all ports - portinf->all = true; - else - portinf->portlist.push_front(port); - - status = acceptignoreinfo.AddElement(ip,portinf); - if (status < 0) - { - RTPDelete(portinf,GetMemoryManager()); - return status; - } - } - return 0; -} - -void RTPUDPv6Transmitter::ClearAcceptIgnoreInfo() -{ - acceptignoreinfo.GotoFirstElement(); - while (acceptignoreinfo.HasCurrentElement()) - { - PortInfo *inf; - - inf = acceptignoreinfo.GetCurrentElement(); - RTPDelete(inf,GetMemoryManager()); - acceptignoreinfo.GotoNextElement(); - } - acceptignoreinfo.Clear(); -} - -int RTPUDPv6Transmitter::ProcessDeleteAcceptIgnoreEntry(in6_addr ip,uint16_t port) -{ - acceptignoreinfo.GotoElement(ip); - if (!acceptignoreinfo.HasCurrentElement()) - return ERR_RTP_UDPV6TRANS_NOSUCHENTRY; - - PortInfo *inf; - - inf = acceptignoreinfo.GetCurrentElement(); - if (port == 0) // delete all entries - { - inf->all = false; - inf->portlist.clear(); - } - else // a specific port was selected - { - if (inf->all) // currently, all ports are selected. Add the one to remove to the list - { - // we have to check if the list doesn't contain the port already - std::list::const_iterator it,begin,end; - - begin = inf->portlist.begin(); - end = inf->portlist.end(); - for (it = begin ; it != end ; it++) - { - if (*it == port) // already in list: this means we already deleted the entry - return ERR_RTP_UDPV6TRANS_NOSUCHENTRY; - } - inf->portlist.push_front(port); - } - else // check if we can find the port in the list - { - std::list::iterator it,begin,end; - - begin = inf->portlist.begin(); - end = inf->portlist.end(); - for (it = begin ; it != end ; ++it) - { - if (*it == port) // found it! - { - inf->portlist.erase(it); - return 0; - } - } - // didn't find it - return ERR_RTP_UDPV6TRANS_NOSUCHENTRY; - } - } - return 0; -} - -bool RTPUDPv6Transmitter::ShouldAcceptData(in6_addr srcip,uint16_t srcport) -{ - if (receivemode == RTPTransmitter::AcceptSome) - { - PortInfo *inf; - - acceptignoreinfo.GotoElement(srcip); - if (!acceptignoreinfo.HasCurrentElement()) - return false; - - inf = acceptignoreinfo.GetCurrentElement(); - if (!inf->all) // only accept the ones in the list - { - std::list::const_iterator it,begin,end; - - begin = inf->portlist.begin(); - end = inf->portlist.end(); - for (it = begin ; it != end ; it++) - { - if (*it == srcport) - return true; - } - return false; - } - else // accept all, except the ones in the list - { - std::list::const_iterator it,begin,end; - - begin = inf->portlist.begin(); - end = inf->portlist.end(); - for (it = begin ; it != end ; it++) - { - if (*it == srcport) - return false; - } - return true; - } - } - else // IgnoreSome - { - PortInfo *inf; - - acceptignoreinfo.GotoElement(srcip); - if (!acceptignoreinfo.HasCurrentElement()) - return true; - - inf = acceptignoreinfo.GetCurrentElement(); - if (!inf->all) // ignore the ports in the list - { - std::list::const_iterator it,begin,end; - - begin = inf->portlist.begin(); - end = inf->portlist.end(); - for (it = begin ; it != end ; it++) - { - if (*it == srcport) - return false; - } - return true; - } - else // ignore all, except the ones in the list - { - std::list::const_iterator it,begin,end; - - begin = inf->portlist.begin(); - end = inf->portlist.end(); - for (it = begin ; it != end ; it++) - { - if (*it == srcport) - return true; - } - return false; - } - } - return true; -} - -int RTPUDPv6Transmitter::CreateLocalIPList() -{ - // first try to obtain the list from the network interface info - - if (!GetLocalIPList_Interfaces()) - { - // If this fails, we'll have to depend on DNS info - GetLocalIPList_DNS(); - } - AddLoopbackAddress(); - return 0; -} - -#ifdef RTP_SOCKETTYPE_WINSOCK - -bool RTPUDPv6Transmitter::GetLocalIPList_Interfaces() -{ - unsigned char buffer[RTPUDPV6TRANS_IFREQBUFSIZE]; - DWORD outputsize; - DWORD numaddresses,i; - SOCKET_ADDRESS_LIST *addrlist; - - if (WSAIoctl(rtpsock,SIO_ADDRESS_LIST_QUERY,NULL,0,&buffer,RTPUDPV6TRANS_IFREQBUFSIZE,&outputsize,NULL,NULL)) - return false; - - addrlist = (SOCKET_ADDRESS_LIST *)buffer; - numaddresses = addrlist->iAddressCount; - for (i = 0 ; i < numaddresses ; i++) - { - SOCKET_ADDRESS *sockaddr = &(addrlist->Address[i]); - if (sockaddr->iSockaddrLength == sizeof(struct sockaddr_in6)) // IPv6 address - { - struct sockaddr_in6 *addr = (struct sockaddr_in6 *)sockaddr->lpSockaddr; - - localIPs.push_back(addr->sin6_addr); - } - } - - if (localIPs.empty()) - return false; - return true; -} - -#else - -#ifdef RTP_SUPPORT_IFADDRS - -bool RTPUDPv6Transmitter::GetLocalIPList_Interfaces() -{ - struct ifaddrs *addrs,*tmp; - - getifaddrs(&addrs); - tmp = addrs; - - while (tmp != 0) - { - if (tmp->ifa_addr != 0 && tmp->ifa_addr->sa_family == AF_INET6) - { - struct sockaddr_in6 *inaddr = (struct sockaddr_in6 *)tmp->ifa_addr; - localIPs.push_back(inaddr->sin6_addr); - } - tmp = tmp->ifa_next; - } - - freeifaddrs(addrs); - - if (localIPs.empty()) - return false; - return true; -} - -#else - -bool RTPUDPv6Transmitter::GetLocalIPList_Interfaces() -{ - return false; -} - -#endif // RTP_SUPPORT_IFADDRS - -#endif // RTP_SOCKETTYPE_WINSOCK - -void RTPUDPv6Transmitter::GetLocalIPList_DNS() -{ - int status; - char name[1024]; - - gethostname(name,1023); - name[1023] = 0; - - struct addrinfo hints; - struct addrinfo *res,*tmp; - - memset(&hints,0,sizeof(struct addrinfo)); - hints.ai_family = AF_INET6; - hints.ai_socktype = 0; - hints.ai_protocol = 0; - - if ((status = getaddrinfo(name,0,&hints,&res)) != 0) - return; - - tmp = res; - while (tmp != 0) - { - if (tmp->ai_family == AF_INET6) - { - struct sockaddr_in6 *addr = (struct sockaddr_in6 *)(tmp->ai_addr); - localIPs.push_back(addr->sin6_addr); - } - tmp = tmp->ai_next; - } - - freeaddrinfo(res); -} - -void RTPUDPv6Transmitter::AddLoopbackAddress() -{ - std::list::const_iterator it; - bool found = false; - - for (it = localIPs.begin() ; !found && it != localIPs.end() ; it++) - { - if ((*it) == in6addr_loopback) - found = true; - } - - if (!found) - localIPs.push_back(in6addr_loopback); -} - -} // end namespace - -#endif // RTP_SUPPORT_IPV6 - diff --git a/qrtplib/rtpudpv6transmitter.h b/qrtplib/rtpudpv6transmitter.h deleted file mode 100644 index 16fe6f9ef..000000000 --- a/qrtplib/rtpudpv6transmitter.h +++ /dev/null @@ -1,322 +0,0 @@ -/* - - This file is a part of JRTPLIB - Copyright (c) 1999-2017 Jori Liesenborgs - - Contact: jori.liesenborgs@gmail.com - - This library was developed at the Expertise Centre for Digital Media - (http://www.edm.uhasselt.be), a research center of the Hasselt University - (http://www.uhasselt.be). The library is based upon work done for - my thesis at the School for Knowledge Technology (Belgium/The Netherlands). - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included - in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - IN THE SOFTWARE. - -*/ - -/** - * \file rtpudpv6transmitter.h - */ - -#ifndef RTPUDPV6TRANSMITTER_H - -#define RTPUDPV6TRANSMITTER_H - -#include "rtpconfig.h" - -#ifdef RTP_SUPPORT_IPV6 - -#include "rtptransmitter.h" -#include "rtpipv6destination.h" -#include "rtphashtable.h" -#include "rtpkeyhashtable.h" -#include "rtpsocketutil.h" -#include "rtpabortdescriptors.h" -#include -#include - -#define RTPUDPV6TRANS_HASHSIZE 8317 -#define RTPUDPV6TRANS_DEFAULTPORTBASE 5000 - -#define RTPUDPV6TRANS_RTPRECEIVEBUFFER 32768 -#define RTPUDPV6TRANS_RTCPRECEIVEBUFFER 32768 -#define RTPUDPV6TRANS_RTPTRANSMITBUFFER 32768 -#define RTPUDPV6TRANS_RTCPTRANSMITBUFFER 32768 - -namespace qrtplib -{ - -/** Parameters for the UDP over IPv6 transmitter. */ -class JRTPLIB_IMPORTEXPORT RTPUDPv6TransmissionParams : public RTPTransmissionParams -{ -public: - RTPUDPv6TransmissionParams(); - - /** Sets the IP address which is used to bind the sockets to \c ip. */ - void SetBindIP(in6_addr ip) { bindIP = ip; } - - /** Sets the multicast interface index. */ - void SetMulticastInterfaceIndex(unsigned int idx) { mcastifidx = idx; } - - /** Sets the RTP portbase to \c pbase. This has to be an even number. */ - void SetPortbase(uint16_t pbase) { portbase = pbase; } - - /** Sets the multicast TTL to be used to \c mcastTTL. */ - void SetMulticastTTL(uint8_t mcastTTL) { multicastTTL = mcastTTL; } - - /** Passes a list of IP addresses which will be used as the local IP addresses. */ - void SetLocalIPList(std::list &iplist) { localIPs = iplist; } - - /** Clears the list of local IP addresses. - * Clears the list of local IP addresses. An empty list will make the transmission component - * itself determine the local IP addresses. - */ - void ClearLocalIPList() { localIPs.clear(); } - - /** Returns the IP address which will be used to bind the sockets. */ - in6_addr GetBindIP() const { return bindIP; } - - /** Returns the multicast interface index. */ - unsigned int GetMulticastInterfaceIndex() const { return mcastifidx; } - - /** Returns the RTP portbase which will be used (default is 5000). */ - uint16_t GetPortbase() const { return portbase; } - - /** Returns the multicast TTL which will be used (default is 1). */ - uint8_t GetMulticastTTL() const { return multicastTTL; } - - /** Returns the list of local IP addresses. */ - const std::list &GetLocalIPList() const { return localIPs; } - - /** Sets the RTP socket's send buffer size. */ - void SetRTPSendBuffer(int s) { rtpsendbuf = s; } - - /** Sets the RTP socket's receive buffer size. */ - void SetRTPReceiveBuffer(int s) { rtprecvbuf = s; } - - /** Sets the RTCP socket's send buffer size. */ - void SetRTCPSendBuffer(int s) { rtcpsendbuf = s; } - - /** Sets the RTCP socket's receive buffer size. */ - void SetRTCPReceiveBuffer(int s) { rtcprecvbuf = s; } - - /** If non null, the specified abort descriptors will be used to cancel - * the function that's waiting for packets to arrive; set to null (the default - * to let the transmitter create its own instance. */ - void SetCreatedAbortDescriptors(RTPAbortDescriptors *desc) { m_pAbortDesc = desc; } - - /** Returns the RTP socket's send buffer size. */ - int GetRTPSendBuffer() const { return rtpsendbuf; } - - /** Returns the RTP socket's receive buffer size. */ - int GetRTPReceiveBuffer() const { return rtprecvbuf; } - - /** Returns the RTCP socket's send buffer size. */ - int GetRTCPSendBuffer() const { return rtcpsendbuf; } - - /** Returns the RTCP socket's receive buffer size. */ - int GetRTCPReceiveBuffer() const { return rtcprecvbuf; } - - /** If non-null, this RTPAbortDescriptors instance will be used internally, - * which can be useful when creating your own poll thread for multiple - * sessions. */ - RTPAbortDescriptors *GetCreatedAbortDescriptors() const { return m_pAbortDesc; } -private: - uint16_t portbase; - in6_addr bindIP; - unsigned int mcastifidx; - std::list localIPs; - uint8_t multicastTTL; - int rtpsendbuf, rtprecvbuf; - int rtcpsendbuf, rtcprecvbuf; - - RTPAbortDescriptors *m_pAbortDesc; -}; - -inline RTPUDPv6TransmissionParams::RTPUDPv6TransmissionParams() - : RTPTransmissionParams(RTPTransmitter::IPv6UDPProto) -{ - portbase = RTPUDPV6TRANS_DEFAULTPORTBASE; - for (int i = 0 ; i < 16 ; i++) - bindIP.s6_addr[i] = 0; - - multicastTTL = 1; - mcastifidx = 0; - rtpsendbuf = RTPUDPV6TRANS_RTPTRANSMITBUFFER; - rtprecvbuf= RTPUDPV6TRANS_RTPRECEIVEBUFFER; - rtcpsendbuf = RTPUDPV6TRANS_RTCPTRANSMITBUFFER; - rtcprecvbuf = RTPUDPV6TRANS_RTCPRECEIVEBUFFER; - - m_pAbortDesc = 0; -} - -/** Additional information about the UDP over IPv6 transmitter. */ -class JRTPLIB_IMPORTEXPORT RTPUDPv6TransmissionInfo : public RTPTransmissionInfo -{ -public: - RTPUDPv6TransmissionInfo(std::list iplist, SocketType rtpsock, SocketType rtcpsock, - uint16_t rtpport, uint16_t rtcpport) : RTPTransmissionInfo(RTPTransmitter::IPv6UDPProto) - { localIPlist = iplist; rtpsocket = rtpsock; rtcpsocket = rtcpsock; m_rtpPort = rtpport; m_rtcpPort = rtcpport; } - - ~RTPUDPv6TransmissionInfo() { } - - /** Returns the list of IPv6 addresses the transmitter considers to be the local IP addresses. */ - std::list GetLocalIPList() const { return localIPlist; } - - /** Returns the socket descriptor used for receiving and transmitting RTP packets. */ - SocketType GetRTPSocket() const { return rtpsocket; } - - /** Returns the socket descriptor used for receiving and transmitting RTCP packets. */ - SocketType GetRTCPSocket() const { return rtcpsocket; } - - /** Returns the port number that the RTP socket receives packets on. */ - uint16_t GetRTPPort() const { return m_rtpPort; } - - /** Returns the port number that the RTCP socket receives packets on. */ - uint16_t GetRTCPPort() const { return m_rtcpPort; } -private: - std::list localIPlist; - SocketType rtpsocket,rtcpsocket; - uint16_t m_rtpPort, m_rtcpPort; -}; - -class JRTPLIB_IMPORTEXPORT RTPUDPv6Trans_GetHashIndex_IPv6Dest -{ -public: - static int GetIndex(const RTPIPv6Destination &d) { in6_addr ip = d.GetIP(); return ((((uint32_t)ip.s6_addr[12])<<24)|(((uint32_t)ip.s6_addr[13])<<16)|(((uint32_t)ip.s6_addr[14])<<8)|((uint32_t)ip.s6_addr[15]))%RTPUDPV6TRANS_HASHSIZE; } -}; - -class JRTPLIB_IMPORTEXPORT RTPUDPv6Trans_GetHashIndex_in6_addr -{ -public: - static int GetIndex(const in6_addr &ip) { return ((((uint32_t)ip.s6_addr[12])<<24)|(((uint32_t)ip.s6_addr[13])<<16)|(((uint32_t)ip.s6_addr[14])<<8)|((uint32_t)ip.s6_addr[15]))%RTPUDPV6TRANS_HASHSIZE; } -}; - -#define RTPUDPV6TRANS_HEADERSIZE (40+8) - -/** An UDP over IPv6 transmitter. - * This class inherits the RTPTransmitter interface and implements a transmission component - * which uses UDP over IPv6 to send and receive RTP and RTCP data. The component's parameters - * are described by the class RTPUDPv6TransmissionParams. The functions which have an RTPAddress - * argument require an argument of RTPIPv6Address. The GetTransmissionInfo member function - * returns an instance of type RTPUDPv6TransmissionInfo. - */ -class JRTPLIB_IMPORTEXPORT RTPUDPv6Transmitter : public RTPTransmitter -{ -public: - RTPUDPv6Transmitter(RTPMemoryManager *mgr); - ~RTPUDPv6Transmitter(); - - int Init(bool treadsafe); - int Create(size_t maxpacksize,const RTPTransmissionParams *transparams); - void Destroy(); - RTPTransmissionInfo *GetTransmissionInfo(); - void DeleteTransmissionInfo(RTPTransmissionInfo *inf); - - int GetLocalHostName(uint8_t *buffer,size_t *bufferlength); - bool ComesFromThisTransmitter(const RTPAddress *addr); - size_t GetHeaderOverhead() { return RTPUDPV6TRANS_HEADERSIZE; } - - int Poll(); - int WaitForIncomingData(const RTPTime &delay,bool *dataavailable = 0); - int AbortWait(); - - int SendRTPData(const void *data,size_t len); - int SendRTCPData(const void *data,size_t len); - - int AddDestination(const RTPAddress &addr); - int DeleteDestination(const RTPAddress &addr); - void ClearDestinations(); - - bool SupportsMulticasting(); - int JoinMulticastGroup(const RTPAddress &addr); - int LeaveMulticastGroup(const RTPAddress &addr); - void LeaveAllMulticastGroups(); - - int SetReceiveMode(RTPTransmitter::ReceiveMode m); - int AddToIgnoreList(const RTPAddress &addr); - int DeleteFromIgnoreList(const RTPAddress &addr); - void ClearIgnoreList(); - int AddToAcceptList(const RTPAddress &addr); - int DeleteFromAcceptList(const RTPAddress &addr); - void ClearAcceptList(); - int SetMaximumPacketSize(size_t s); - - bool NewDataAvailable(); - RTPRawPacket *GetNextPacket(); - -private: - int CreateLocalIPList(); - bool GetLocalIPList_Interfaces(); - void GetLocalIPList_DNS(); - void AddLoopbackAddress(); - void FlushPackets(); - int PollSocket(bool rtp); - int ProcessAddAcceptIgnoreEntry(in6_addr ip,uint16_t port); - int ProcessDeleteAcceptIgnoreEntry(in6_addr ip,uint16_t port); -#ifdef RTP_SUPPORT_IPV6MULTICAST - bool SetMulticastTTL(uint8_t ttl); -#endif // RTP_SUPPORT_IPV6MULTICAST - bool ShouldAcceptData(in6_addr srcip,uint16_t srcport); - void ClearAcceptIgnoreInfo(); - - bool init; - bool created; - bool waitingfordata; - SocketType rtpsock,rtcpsock; - in6_addr bindIP; - unsigned int mcastifidx; - std::list localIPs; - uint16_t portbase; - uint8_t multicastTTL; - RTPTransmitter::ReceiveMode receivemode; - - uint8_t *localhostname; - size_t localhostnamelength; - - RTPHashTable destinations; -#ifdef RTP_SUPPORT_IPV6MULTICAST - RTPHashTable multicastgroups; -#endif // RTP_SUPPORT_IPV6MULTICAST - std::list rawpacketlist; - - bool supportsmulticasting; - size_t maxpacksize; - - class PortInfo - { - public: - PortInfo() { all = false; } - - bool all; - std::list portlist; - }; - - RTPKeyHashTable acceptignoreinfo; - RTPAbortDescriptors m_abortDesc; - RTPAbortDescriptors *m_pAbortDesc; - -}; - -} // end namespace - -#endif // RTP_SUPPORT_IPV6 - -#endif // RTPUDPV6TRANSMITTER_H -