1af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org/* 2af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 3af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * 4af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * Use of this source code is governed by a BSD-style license 5af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * that can be found in the LICENSE file in the root of the source 6af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * tree. An additional intellectual property rights grant can be found 7af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * in the file PATENTS. All contributing project authors may 8af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org * be found in the AUTHORS file in the root of the source tree. 9af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org */ 10af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 11af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include "webrtc/test/channel_transport/udp_transport_impl.h" 12af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 13af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <stdio.h> 14af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <stdlib.h> 15af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <string.h> 16af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <time.h> 17af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 18af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#if defined(_WIN32) 19af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <winsock2.h> 20af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <ws2tcpip.h> 21af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) 22af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <arpa/inet.h> 23af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <ctype.h> 24af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <fcntl.h> 25af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <net/if.h> 2696001c8e03bf364c81f5f86a2fadb371934d0383pbos@webrtc.org#include <netdb.h> 27af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <netinet/in.h> 28af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <stdlib.h> 29af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <sys/ioctl.h> 30af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <sys/socket.h> 31af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <sys/time.h> 32af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <unistd.h> 33af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifndef WEBRTC_IOS 34af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <net/if_arp.h> 35af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 36af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif // defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) 37af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 38af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#if defined(WEBRTC_MAC) 39af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <ifaddrs.h> 40af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <machine/types.h> 41af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 42af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#if defined(WEBRTC_LINUX) 43af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <linux/netlink.h> 44af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include <linux/rtnetlink.h> 45af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 46af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 47af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include "webrtc/common_types.h" 48af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include "webrtc/system_wrappers/interface/critical_section_wrapper.h" 49af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" 50af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include "webrtc/system_wrappers/interface/trace.h" 51af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#include "webrtc/test/channel_transport/udp_socket_manager_wrapper.h" 5296001c8e03bf364c81f5f86a2fadb371934d0383pbos@webrtc.org#include "webrtc/typedefs.h" 53af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 54af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#if defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) 55af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#define GetLastError() errno 56af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 57af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#define IFRSIZE ((int)(size * sizeof (struct ifreq))) 58af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 59af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#define NLMSG_OK_NO_WARNING(nlh,len) \ 60af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ((len) >= (int)sizeof(struct nlmsghdr) && \ 61af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org (int)(nlh)->nlmsg_len >= (int)sizeof(struct nlmsghdr) && \ 62af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org (int)(nlh)->nlmsg_len <= (len)) 63af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 64af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif // defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) 65af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 66af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgnamespace webrtc { 67af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgnamespace test { 68af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 69af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgclass SocketFactory : public UdpTransportImpl::SocketFactoryInterface { 70af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org public: 7177c6d714d2f8f700170218784553df1a48f17885pbos@webrtc.org virtual UdpSocketWrapper* CreateSocket(const int32_t id, 72af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketManager* mgr, 73af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CallbackObj obj, 74af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IncomingSocketCallback cb, 75af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org bool ipV6Enable, 7677c6d714d2f8f700170218784553df1a48f17885pbos@webrtc.org bool disableGQOS) OVERRIDE { 77af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return UdpSocketWrapper::CreateSocket(id, mgr, obj, cb, ipV6Enable, 78af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org disableGQOS); 79af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 80af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org}; 81af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 82af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org// Creates an UdpTransport using the definition of SocketFactory above, 83af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org// and passes (creating if needed) a pointer to the static singleton 84af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org// UdpSocketManager. 8591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgUdpTransport* UdpTransport::Create(const int32_t id, 8691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint8_t& numSocketThreads) 87af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 88af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return new UdpTransportImpl(id, 89af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org new SocketFactory(), 90af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketManager::Create(id, numSocketThreads)); 91af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 92af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 93af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org// Deletes the UdpTransport and decrements the refcount of the 94af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org// static singleton UdpSocketManager, possibly destroying it. 95af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org// Should only be used on UdpTransports that are created using Create. 96af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid UdpTransport::Destroy(UdpTransport* module) 97af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 98af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(module) 99af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 100af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org delete module; 101af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketManager::Return(); 102af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 103af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 104af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 10591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgUdpTransportImpl::UdpTransportImpl(const int32_t id, 106af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketFactoryInterface* maker, 107af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketManager* socket_manager) 108af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org : _id(id), 109af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _socket_creator(maker), 110af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _crit(CriticalSectionWrapper::CreateCriticalSection()), 111af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _critFilter(CriticalSectionWrapper::CreateCriticalSection()), 112af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _critPacketCallback(CriticalSectionWrapper::CreateCriticalSection()), 113af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _mgr(socket_manager), 114af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError(kNoSocketError), 115af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPort(0), 116af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPortRTCP(0), 117af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localPort(0), 118af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localPortRTCP(0), 119af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _srcPort(0), 120af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _srcPortRTCP(0), 121af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _fromPort(0), 122af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _fromPortRTCP(0), 123af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _fromIP(), 124af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destIP(), 125af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localIP(), 126af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localMulticastIP(), 127af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket(NULL), 128af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtcpSocket(NULL), 129af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtpSocket(NULL), 130af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtcpSocket(NULL), 131af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr(), 132af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr(), 133af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr(), 134af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr(), 135af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _tos(0), 136af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _receiving(false), 137af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _useSetSockOpt(false), 138af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _qos(false), 139af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _pcp(0), 140af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ipV6Enabled(false), 141af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _serviceType(0), 142af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _overrideDSCP(0), 143af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _maxBitrate(0), 144af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _cachLock(RWLockWrapper::CreateRWLock()), 145af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _previousAddress(), 146af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _previousIP(), 147af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _previousIPSize(0), 148af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _previousSourcePort(0), 149af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _filterIPAddress(), 150af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _rtpFilterPort(0), 151af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _rtcpFilterPort(0), 152af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _packetCallback(0) 153af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 154af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(&_remoteRTPAddr, 0, sizeof(_remoteRTPAddr)); 155af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(&_remoteRTCPAddr, 0, sizeof(_remoteRTCPAddr)); 156af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(&_localRTPAddr, 0, sizeof(_localRTPAddr)); 157af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(&_localRTCPAddr, 0, sizeof(_localRTCPAddr)); 158af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 159af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(_fromIP, 0, sizeof(_fromIP)); 160af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(_destIP, 0, sizeof(_destIP)); 161af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(_localIP, 0, sizeof(_localIP)); 162af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(_localMulticastIP, 0, sizeof(_localMulticastIP)); 163af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 164af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(&_filterIPAddress, 0, sizeof(_filterIPAddress)); 165af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 166af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceMemory, kTraceTransport, id, "%s created", __FUNCTION__); 167af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 168af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 169af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgUdpTransportImpl::~UdpTransportImpl() 170af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 171af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CloseSendSockets(); 172af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CloseReceiveSockets(); 173af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org delete _crit; 174af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org delete _critFilter; 175af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org delete _critPacketCallback; 176af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org delete _cachLock; 177af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org delete _socket_creator; 178af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 179af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceMemory, kTraceTransport, _id, "%s deleted", 180af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org __FUNCTION__); 181af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 182af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 183af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgUdpTransport::ErrorCode UdpTransportImpl::LastError() const 184af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 185af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _lastError; 186af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 187af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 188af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgbool SameAddress(const SocketAddress& address1, const SocketAddress& address2) 189af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 190af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return (memcmp(&address1,&address2,sizeof(address1)) == 0); 191af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 192af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 193af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid UdpTransportImpl::GetCachedAddress(char* ip, 19491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t& ipSize, 19591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& sourcePort) 196af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 19791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const uint32_t originalIPSize = ipSize; 198af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // If the incoming string is too small, fill it as much as there is room 199af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // for. Make sure that there is room for the '\0' character. 200af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ipSize = (ipSize - 1 < _previousIPSize) ? ipSize - 1 : _previousIPSize; 20191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org memcpy(ip,_previousIP,sizeof(int8_t)*(ipSize + 1)); 202af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ip[originalIPSize - 1] = '\0'; 203af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org sourcePort = _previousSourcePort; 204af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 205af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 20691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::IPAddressCached(const SocketAddress& address, 20791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org char* ip, 20891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t& ipSize, 20991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& sourcePort) 210af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 211af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 212af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ReadLockScoped rl(*_cachLock); 213af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Check if the old address can be re-used (is the same). 214af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(SameAddress(address,_previousAddress)) 215af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 216af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org GetCachedAddress(ip,ipSize,sourcePort); 217af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 218af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 219af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 220af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Get the new address and store it. 221af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WriteLockScoped wl(*_cachLock); 222af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ipSize = kIpAddressVersion6Length; 223af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(IPAddress(address,_previousIP,ipSize,_previousSourcePort) != 0) 224af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 225af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 226af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 227af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _previousIPSize = ipSize; 228af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memcpy(&_previousAddress, &address, sizeof(address)); 229af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Address has been cached at this point. 230af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org GetCachedAddress(ip,ipSize,sourcePort); 231af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 232af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 233af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 23491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::InitializeReceiveSockets( 235af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpTransportData* const packetCallback, 23691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const uint16_t portnr, 237af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const char* ip, 238af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const char* multicastIpAddr, 23991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const uint16_t rtcpPort) 240af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 241af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 242af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_critPacketCallback); 243af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _packetCallback = packetCallback; 244af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 245af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(packetCallback == NULL) 246af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 247af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceStateInfo, kTraceTransport, _id, 248af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Closing down receive sockets"); 249af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 250af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 251af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 252af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 253af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 254af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CloseReceiveSockets(); 255af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 256af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(portnr == 0) 257af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 258af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // TODO (hellner): why not just fail here? 259af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_destPort == 0) 260af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 261af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 262af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "InitializeReceiveSockets port 0 not allowed"); 263af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kPortInvalid; 264af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 265af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 266af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localPort = _destPort; 267af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else { 268af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localPort = portnr; 269af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 270af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(rtcpPort) 271af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 272af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localPortRTCP = rtcpPort; 273af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else { 274af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localPortRTCP = _localPort + 1; 275af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 276af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceStateInfo, 277af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 278af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 279af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "InitializeReceiveSockets RTCP port not configured using RTP\ 280af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org port+1=%d", 281af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localPortRTCP); 282af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 283af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 284af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(ip) 285af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 286af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(IsIpAddressValid(ip,IpV6Enabled())) 287af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 288af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(_localIP, ip,kIpAddressVersion6Length); 289af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 290af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 291af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 292af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "InitializeReceiveSockets invalid IP address"); 293af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kIpAddressInvalid; 294af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 295af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 296af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 297af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 298af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Don't bind to a specific IP address. 299af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(! IpV6Enabled()) 300af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 301af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(_localIP, "0.0.0.0",16); 302af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 303af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 304af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(_localIP, "0000:0000:0000:0000:0000:0000:0000:0000", 305af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kIpAddressVersion6Length); 306af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 307af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 308af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(multicastIpAddr && !IpV6Enabled()) 309af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 310af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(IsIpAddressValid(multicastIpAddr,IpV6Enabled())) 311af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 312af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(_localMulticastIP, multicastIpAddr, 313af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kIpAddressVersion6Length); 314af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 315af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 316af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 317af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "InitializeReceiveSockets invalid IP address"); 318af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kIpAddressInvalid; 319af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 320af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 321af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 322af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_mgr == NULL) 323af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 324af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 325af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "InitializeReceiveSockets no socket manager"); 326af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 327af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 328af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 329af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _useSetSockOpt=false; 330af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _tos=0; 331af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _pcp=0; 332af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 333af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket = _socket_creator->CreateSocket(_id, _mgr, this, 334af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IncomingRTPCallback, 335af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IpV6Enabled(), false); 336af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 337af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtcpSocket = _socket_creator->CreateSocket(_id, _mgr, this, 338af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IncomingRTCPCallback, 339af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IpV6Enabled(), false); 340af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 341af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ErrorCode retVal = BindLocalRTPSocket(); 342af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(retVal != kNoSocketError) 343af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 344af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 345af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "InitializeReceiveSockets faild to bind RTP socket"); 346af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = retVal; 347af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CloseReceiveSockets(); 348af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 349af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 350af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org retVal = BindLocalRTCPSocket(); 351af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(retVal != kNoSocketError) 352af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 353af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = retVal; 354af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 355af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "InitializeReceiveSockets faild to bind RTCP socket"); 356af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CloseReceiveSockets(); 357af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 358af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 359af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 360af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 361af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 36291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::ReceiveSocketInformation( 363af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char ipAddr[kIpAddressVersion6Length], 36491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& rtpPort, 36591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& rtcpPort, 366af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char multicastIpAddr[kIpAddressVersion6Length]) const 367af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 368af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 369af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpPort = _localPort; 370af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpPort = _localPortRTCP; 371af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (ipAddr) 372af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 373af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(ipAddr, _localIP, IpV6Enabled() ? 374af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpTransport::kIpAddressVersion6Length : 375af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpTransport::kIpAddressVersion4Length); 376af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 377af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (multicastIpAddr) 378af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 379af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(multicastIpAddr, _localMulticastIP, IpV6Enabled() ? 380af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpTransport::kIpAddressVersion6Length : 381af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpTransport::kIpAddressVersion4Length); 382af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 383af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 384af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 385af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 38691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SendSocketInformation( 387af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char ipAddr[kIpAddressVersion6Length], 38891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& rtpPort, 38991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& rtcpPort) const 390af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 391af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 392af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpPort = _destPort; 393af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpPort = _destPortRTCP; 394af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(ipAddr, _destIP, IpV6Enabled() ? 395af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpTransport::kIpAddressVersion6Length : 396af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpTransport::kIpAddressVersion4Length); 397af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 398af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 399af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 40091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::RemoteSocketInformation( 401af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char ipAddr[kIpAddressVersion6Length], 40291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& rtpPort, 40391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& rtcpPort) const 404af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 405af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 406af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpPort = _fromPort; 407af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpPort = _fromPortRTCP; 408af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(ipAddr) 409af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 410af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(ipAddr, _fromIP, IpV6Enabled() ? 411af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kIpAddressVersion6Length : 412af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kIpAddressVersion4Length); 413af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 414af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 415af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 416af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 41791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::FilterPorts( 41891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& rtpFilterPort, 41991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& rtcpFilterPort) const 420af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 421af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_critFilter); 422af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpFilterPort = _rtpFilterPort; 423af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpFilterPort = _rtcpFilterPort; 424af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 425af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 426af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 42791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SetQoS(bool QoS, int32_t serviceType, 42891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t maxBitrate, 42991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t overrideDSCP, bool audio) 430af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 431af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(QoS) 432af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 433af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return EnableQoS(serviceType, audio, maxBitrate, overrideDSCP); 434af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 435af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 436af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return DisableQoS(); 437af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 438af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 439af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 44091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::EnableQoS(int32_t serviceType, 44191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org bool audio, uint32_t maxBitrate, 44291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t overrideDSCP) 443af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 444af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_ipV6Enabled) 445af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 446af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 447af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 448af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 449af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 450af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS is enabled but will be ignored since IPv6 is enabled"); 451af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 452af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 453af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 454af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_tos) 455af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 456af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 457af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 458af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 459af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 460af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "TOS already enabled, can't use TOS and QoS at the same time"); 461af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 462af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 463af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 464af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_pcp) 465af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 466af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 467af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 468af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 469af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 470af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "PCP already enabled, can't use PCP and QoS at the same time"); 471af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 472af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 473af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 474af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_destPort == 0) 475af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 476af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 477af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 478af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 479af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 480af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS is enabled but not started since we have not yet configured\ 481af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org the send destination"); 482af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 483af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 484af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_qos) 485af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 486af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_overrideDSCP == 0 && overrideDSCP != 0) 487af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 488af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 489af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 490af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 491af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 492af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS is already enabled and overrideDSCP differs, not allowed"); 493af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 494af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 495af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 496af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 497af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 498af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtpSock = _ptrSendRtpSocket ? 499af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtpSocket : 500af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket; 501af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtpSock || !rtpSock->ValidHandle()) 502af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 503af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 504af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 505af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 506af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 507af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS is enabled but not started since we have not yet created the\ 508af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org RTP socket"); 509af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 510af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 511af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtcpSock = _ptrSendRtcpSocket ? 512af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtcpSocket : 513af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtcpSocket; 514af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtcpSock || !rtcpSock->ValidHandle()) 515af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 516af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 517af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 518af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 519af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 520af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS is enabled but not started since we have not yet created the\ 521af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org RTCP socket"); 522af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 523af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 524af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 525af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Minimum packet size in bytes for which the requested quality of service 526af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // will be provided. The smallest RTP header is 12 byte. 52791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t min_policed_size = 12; 528af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Max SDU, maximum packet size permitted or used in the traffic flow, in 529af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // bytes. 53091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t max_sdu_size = 1500; 531af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 532af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Enable QoS for RTP sockets. 533af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(maxBitrate) 534af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 535af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Note: 1 kbit is 125 bytes. 536af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Token Rate is typically set to the average bit rate from peak to 537af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // peak. 538af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Bucket size is normally set to the largest average frame size. 539af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(audio) 540af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 541af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceStateInfo, 542af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 543af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 544af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Enable QOS for audio with max bitrate:%d", 545af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org maxBitrate); 546af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 54791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t token_rate = maxBitrate*125; 548af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // The largest audio packets are 60ms frames. This is a fraction 549af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // more than 16 packets/second. These 16 frames are sent, at max, 550af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // at a bitrate of maxBitrate*125 -> 1 frame is maxBitrate*125/16 ~ 551af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // maxBitrate * 8. 55291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t bucket_size = maxBitrate * 8; 55391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t peek_bandwith = maxBitrate * 125; 554af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtpSock->SetQos(serviceType, token_rate, bucket_size, 555af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org peek_bandwith, min_policed_size, 556af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org max_sdu_size, _remoteRTPAddr, overrideDSCP)) 557af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 558af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 559af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS failed on the RTP socket"); 560af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 561af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 562af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 563af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 564af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 565af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceStateInfo, kTraceTransport, _id, 566af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Enable QOS for video with max bitrate:%d", 567af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org maxBitrate); 568af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 569af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Allow for a token rate that is twice that of the maximum bitrate 570af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // (in bytes). 57191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t token_rate = maxBitrate*250; 572af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // largest average frame size (key frame size). Assuming that a 573af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // keyframe is 25% of the bitrate during the second its sent 574af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Assume that a key frame is 25% of the bitrate the second that it 575af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // is sent. The largest frame size is then maxBitrate* 125 * 0.25 ~ 576af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // 31. 57791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t bucket_size = maxBitrate*31; 57891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t peek_bandwith = maxBitrate*125; 579af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtpSock->SetQos(serviceType, token_rate, bucket_size, 580af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org peek_bandwith, min_policed_size, max_sdu_size, 581af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr, overrideDSCP)) 582af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 583af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 584af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS failed on the RTP socket"); 585af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 586af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 587af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 588af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 589af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(audio) 590af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 591af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // No max bitrate set. Audio. 592af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceStateInfo, kTraceTransport, _id, 593af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Enable QOS for audio with default max bitrate"); 594af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 595af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Let max bitrate be 240kbit/s. 59691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t token_rate = 30000; 59791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t bucket_size = 2000; 59891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t peek_bandwith = 30000; 599af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtpSock->SetQos(serviceType, token_rate, bucket_size, 600af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org peek_bandwith, min_policed_size, max_sdu_size, 601af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr, overrideDSCP)) 602af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 603af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 604af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS failed on the RTP socket"); 605af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 606af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 607af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 608af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 609af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 610af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // No max bitrate set. Video. 611af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceStateInfo, kTraceTransport, _id, 612af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Enable QOS for video with default max bitrate"); 613af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 614af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Let max bitrate be 10mbit/s. 61591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t token_rate = 128000*10; 61691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t bucket_size = 32000; 61791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t peek_bandwith = 256000; 618af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtpSock->SetQos(serviceType, token_rate, bucket_size, 619af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org peek_bandwith, min_policed_size, max_sdu_size, 620af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr, overrideDSCP)) 621af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 622af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 623af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS failed on the RTP socket"); 624af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 625af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 626af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 627af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 628af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 629af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Enable QoS for RTCP sockets. 630af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // TODO (hellner): shouldn't RTCP be based on 5% of the maximum bandwidth? 631af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(audio) 632af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 63391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t token_rate = 200; 63491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t bucket_size = 200; 63591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t peek_bandwith = 400; 636af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtcpSock->SetQos(serviceType, token_rate, bucket_size, 637af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org peek_bandwith, min_policed_size, max_sdu_size, 638af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr, overrideDSCP)) 639af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 640af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, _id, 641af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS failed on the RTCP socket"); 642af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 643af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 644af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 645af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 64691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t token_rate = 5000; 64791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t bucket_size = 100; 64891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t peek_bandwith = 10000; 649af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtcpSock->SetQos(serviceType, token_rate, bucket_size, 650af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org peek_bandwith, min_policed_size, max_sdu_size, 651af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr, _overrideDSCP)) 652af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 653af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, _id, 654af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS failed on the RTCP socket"); 655af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 656af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 657af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 658af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _qos = true; 659af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _serviceType = serviceType; 660af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _maxBitrate = maxBitrate; 661af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _overrideDSCP = overrideDSCP; 662af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 663af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 664af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 66591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::DisableQoS() 666af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 667af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_qos == false) 668af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 669af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 670af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 671af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 672af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 673af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtpSock = (_ptrSendRtpSocket ? 674af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtpSocket : _ptrRtpSocket); 675af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtpSock || !rtpSock->ValidHandle()) 676af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 677af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 678af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 679af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 680af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 681af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS is enabled but not started since we have not yet created the\ 682af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org RTP socket"); 683af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 684af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 685af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtcpSock = (_ptrSendRtcpSocket ? 686af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtcpSocket : _ptrRtcpSocket); 687af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtcpSock || !rtcpSock->ValidHandle()) 688af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 689af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 690af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 691af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 692af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 693af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS is enabled but not started since we have not yet created the\ 694af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org RTCP socket"); 695af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 696af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 697af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 69891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t service_type = 0; // = SERVICETYPE_NOTRAFFIC 69991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t not_specified = -1; 700af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtpSock->SetQos(service_type, not_specified, not_specified, 701af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org not_specified, not_specified, not_specified, 702af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr, _overrideDSCP)) 703af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 704af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 705af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 706af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 707af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtcpSock->SetQos(service_type, not_specified, not_specified, 708af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org not_specified, not_specified, not_specified, 709af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr,_overrideDSCP)) 710af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 711af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 712af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 713af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _qos = false; 714af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 715af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 716af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 71791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::QoS(bool& QoS, int32_t& serviceType, 71891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t& overrideDSCP) const 719af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 720af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 721af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org QoS = _qos; 722af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org serviceType = _serviceType; 723af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org overrideDSCP = _overrideDSCP; 724af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 725af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 726af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 72791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SetToS(int32_t DSCP, bool useSetSockOpt) 728af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 729af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_qos) 730af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 731af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "QoS already enabled"); 732af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 733af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 734af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 735af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (DSCP < 0 || DSCP > 63) 736af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 737af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "Invalid DSCP"); 738af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kTosInvalid; 739af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 740af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 741af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_tos) 742af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 743af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(useSetSockOpt != _useSetSockOpt) 744af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 745af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 746af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 747af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 748af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 749af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Can't switch SetSockOpt method without disabling TOS first"); 750af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kTosInvalid; 751af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 752af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 753af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 754af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 755af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtpSock = NULL; 756af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtcpSock = NULL; 757af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket) 758af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 759af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpSock = _ptrSendRtpSocket; 760af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 761af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 762af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpSock = _ptrRtpSocket; 763af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 764af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (rtpSock == NULL) 765af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 766af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kSocketInvalid; 767af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 768af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 769af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!rtpSock->ValidHandle()) 770af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 771af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kSocketInvalid; 772af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 773af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 774af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtcpSocket) 775af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 776af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpSock = _ptrSendRtcpSocket; 777af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 778af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 779af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpSock = _ptrRtcpSocket; 780af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 781af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (rtcpSock == NULL) 782af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 783af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kSocketInvalid; 784af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 785af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 786af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!rtcpSock->ValidHandle()) 787af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 788af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kSocketInvalid; 789af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 790af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 791af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 792af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (useSetSockOpt) 793af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 794af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef _WIN32 795af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org OSVERSIONINFO OsVersion; 796af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 797af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org GetVersionEx(&OsVersion); 798af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Disable QoS before setting ToS on Windows XP. This is done by closing 799af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // and re-opening the sockets. 800af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // TODO (hellner): why not just fail here and force the user to 801af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // re-initialize sockets? Doing this may trick the user 802af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // into thinking that the sockets are in a state which 803af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // they aren't. 804af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (OsVersion.dwMajorVersion == 5 && 805af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org OsVersion.dwMinorVersion == 1) 806af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 807af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!_useSetSockOpt) 808af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 809af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket) 810af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 811af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CloseSendSockets(); 812af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtpSocket = 813af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _socket_creator->CreateSocket(_id, _mgr, NULL, 814af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org NULL, IpV6Enabled(), 815af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org true); 816af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtcpSocket = 817af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _socket_creator->CreateSocket(_id, _mgr, NULL, 818af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org NULL, IpV6Enabled(), 819af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org true); 820af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpSock=_ptrSendRtpSocket; 821af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpSock=_ptrSendRtcpSocket; 822af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ErrorCode retVal = BindRTPSendSocket(); 823af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(retVal != kNoSocketError) 824af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 825af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = retVal; 826af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 827af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 828af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org retVal = BindRTCPSendSocket(); 829af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(retVal != kNoSocketError) 830af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 831af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = retVal; 832af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 833af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 834af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 835af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else 836af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 837af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org bool receiving=_receiving; 83891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t noOfReceiveBuffers = 0; 839af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(receiving) 840af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 841af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org noOfReceiveBuffers=_ptrRtpSocket->ReceiveBuffers(); 842af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(StopReceiving()!=0) 843af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 844af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 845af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 846af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 847af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CloseReceiveSockets(); 848af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket = _socket_creator->CreateSocket( 849af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, _mgr, this, IncomingRTPCallback, IpV6Enabled(), 850af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org true); 851af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtcpSocket = _socket_creator->CreateSocket( 852af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, _mgr, this, IncomingRTCPCallback, IpV6Enabled(), 853af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org true); 854af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpSock=_ptrRtpSocket; 855af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpSock=_ptrRtcpSocket; 856af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ErrorCode retVal = BindLocalRTPSocket(); 857af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(retVal != kNoSocketError) 858af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 859af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = retVal; 860af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 861af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 862af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org retVal = BindLocalRTCPSocket(); 863af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(retVal != kNoSocketError) 864af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 865af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = retVal; 866af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 867af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 868af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(receiving) 869af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 870af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(StartReceiving(noOfReceiveBuffers) != 871af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kNoSocketError) 872af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 873af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 874af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 875af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 876af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 877af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 878af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 879af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif // #ifdef _WIN32 880af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, 881af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Setting TOS using SetSockopt"); 88291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t TOSShifted = DSCP << 2; 883af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtpSock->SetSockopt(IPPROTO_IP, IP_TOS, 88491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org (int8_t*) &TOSShifted, 4)) 885af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 886af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 887af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Could not SetSockopt tos value on RTP socket"); 888af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kTosInvalid; 889af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 890af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 891af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtcpSock->SetSockopt(IPPROTO_IP, IP_TOS, 89291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org (int8_t*) &TOSShifted, 4)) 893af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 894af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 895af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Could not sSetSockopt tos value on RTCP socket"); 896af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kTosInvalid; 897af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 898af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 899af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 900af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 901af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, 902af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Setting TOS NOT using SetSockopt"); 903af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (rtpSock->SetTOS(DSCP) != 0) 904af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 905af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 906af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Could not set tos value on RTP socket"); 907af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kTosError; 908af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 909af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 910af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (rtcpSock->SetTOS(DSCP) != 0) 911af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 912af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 913af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Could not set tos value on RTCP socket"); 914af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kTosError; 915af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 916af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 917af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 918af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _useSetSockOpt = useSetSockOpt; 919af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _tos = DSCP; 920af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 921af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 922af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 92391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::ToS(int32_t& DSCP, 92491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org bool& useSetSockOpt) const 925af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 926af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 927af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org DSCP = _tos; 928af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org useSetSockOpt = _useSetSockOpt; 929af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 930af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 931af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 93291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SetPCP(int32_t PCP) 933af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 934af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 935af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_qos) 936af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 937af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "QoS already enabled"); 938af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kQosError; 939af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 940af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 941af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if ((PCP < 0) || (PCP > 7)) 942af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 943af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "Invalid PCP"); 944af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kPcpError; 945af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 946af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 947af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 948af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 949af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtpSock = NULL; 950af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtcpSock = NULL; 951af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket) 952af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 953af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpSock = _ptrSendRtpSocket; 954af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 955af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 956af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpSock = _ptrRtpSocket; 957af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 958af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (rtpSock == NULL) 959af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 960af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kSocketInvalid; 961af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 962af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 963af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!rtpSock->ValidHandle()) 964af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 965af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kSocketInvalid; 966af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 967af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 968af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtcpSocket) 969af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 970af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpSock = _ptrSendRtcpSocket; 971af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 972af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 973af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpSock = _ptrRtcpSocket; 974af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 975af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (rtcpSock == NULL) 976af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 977af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kSocketInvalid; 978af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 979af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 980af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!rtcpSock->ValidHandle()) 981af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 982af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kSocketInvalid; 983af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 984af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 985af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 986af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#if defined(_WIN32) 987af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (rtpSock->SetPCP(PCP) != 0) 988af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 989af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 990af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Could not set PCP value on RTP socket"); 991af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kPcpError; 992af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 993af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 994af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (rtcpSock->SetPCP(PCP) != 0) 995af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 996af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 997af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Could not set PCP value on RTCP socket"); 998af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kPcpError; 999af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1000af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1001af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1002af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#elif defined(WEBRTC_LINUX) 100391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org if (!rtpSock->SetSockopt(SOL_SOCKET, SO_PRIORITY, (int8_t*) &PCP, 1004af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org sizeof(PCP))) 1005af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1006af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1007af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Could not SetSockopt PCP value on RTP socket"); 1008af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kPcpError; 1009af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1010af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 101191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org if (!rtcpSock->SetSockopt(SOL_SOCKET, SO_PRIORITY, (int8_t*) &PCP, 1012af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org sizeof(PCP))) 1013af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1014af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1015af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Could not SetSockopt PCP value on RTCP socket"); 1016af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kPcpError; 1017af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1018af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1019af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1020af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Not supported on other platforms (WEBRTC_MAC) 1021af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kPcpError; 1022af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1023af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1024af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _pcp = PCP; 1025af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1026af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1027af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 102891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::PCP(int32_t& PCP) const 1029af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1030af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1031af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org PCP = _pcp; 1032af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1033af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1034af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1035af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgbool UdpTransportImpl::SetSockOptUsed() 1036af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1037af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _useSetSockOpt; 1038af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1039af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 104091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::EnableIpV6() { 1041af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1042af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1043af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const bool initialized = (_ptrSendRtpSocket || _ptrRtpSocket); 1044af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1045af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_ipV6Enabled) { 1046af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1047af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1048af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (initialized) { 1049af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kIpVersion6Error; 1050af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1051af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1052af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ipV6Enabled = true; 1053af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1054af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1055af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 105691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::FilterIP( 1057af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char filterIPAddress[kIpAddressVersion6Length]) const 1058af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1059af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1060af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(filterIPAddress == NULL) 1061af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1062af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1063af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "FilterIP: Invalid argument"); 1064af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1065af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1066af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_filterIPAddress._sockaddr_storage.sin_family == 0) 1067af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1068af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "No Filter configured"); 1069af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1070af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1071af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_critFilter); 107291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t ipSize = kIpAddressVersion6Length; 107391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t sourcePort; 1074af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return IPAddress(_filterIPAddress, filterIPAddress, ipSize, sourcePort); 1075af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1076af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 107791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SetFilterIP( 1078af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const char filterIPAddress[kIpAddressVersion6Length]) 1079af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1080af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(filterIPAddress == NULL) 1081af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1082af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(&_filterIPAddress, 0, sizeof(_filterIPAddress)); 1083af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, "Filter IP reset"); 1084af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1085af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1086af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_critFilter); 1087af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_ipV6Enabled) 1088af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1089af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _filterIPAddress._sockaddr_storage.sin_family = AF_INET6; 1090af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1091af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (InetPresentationToNumeric( 1092af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org AF_INET6, 1093af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org filterIPAddress, 1094af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org &_filterIPAddress._sockaddr_in6.sin6_addr) < 0) 1095af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1096af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "Failed to set\ 1097af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org filter IP for IPv6"); 1098af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = FILTER_ERROR; 1099af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1100af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1101af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1102af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else 1103af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1104af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _filterIPAddress._sockaddr_storage.sin_family = AF_INET; 1105af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1106af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(InetPresentationToNumeric( 1107af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org AF_INET, 1108af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org filterIPAddress, 1109af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org &_filterIPAddress._sockaddr_in.sin_addr) < 0) 1110af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1111af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1112af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to set filter IP for IPv4"); 1113af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = FILTER_ERROR; 1114af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1115af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1116af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1117af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, "Filter IP set"); 1118af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1119af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1120af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 112191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SetFilterPorts(uint16_t rtpFilterPort, 112291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t rtcpFilterPort) 1123af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1124af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_critFilter); 1125af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _rtpFilterPort = rtpFilterPort; 1126af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _rtcpFilterPort = rtcpFilterPort; 1127af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1128af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1129af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1130af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgbool UdpTransportImpl::SendSocketsInitialized() const 1131af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1132af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1133af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket) 1134af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1135af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return true; 1136af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1137af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_destPort !=0) 1138af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1139af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return true; 1140af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1141af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 1142af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1143af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1144af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgbool UdpTransportImpl::ReceiveSocketsInitialized() const 1145af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1146af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrRtpSocket) 1147af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1148af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return true; 1149af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1150af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 1151af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1152af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1153af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgbool UdpTransportImpl::SourcePortsInitialized() const 1154af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1155af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket) 1156af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1157af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return true; 1158af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1159af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 1160af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1161af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1162af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgbool UdpTransportImpl::IpV6Enabled() const 1163af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1164af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceStream, kTraceTransport, _id, "%s", __FUNCTION__); 1165af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _ipV6Enabled; 1166af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1167af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1168af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid UdpTransportImpl::BuildRemoteRTPAddr() 1169af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1170af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ipV6Enabled) 1171af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1172af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1173af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr.sin_length = 0; 1174af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr.sin_family = PF_INET6; 1175af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1176af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr._sockaddr_storage.sin_family = PF_INET6; 1177af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1178af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1179af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr._sockaddr_in6.sin6_flowinfo=0; 1180af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr._sockaddr_in6.sin6_scope_id=0; 1181af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr._sockaddr_in6.sin6_port = Htons(_destPort); 1182af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org InetPresentationToNumeric(AF_INET6,_destIP, 1183af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org &_remoteRTPAddr._sockaddr_in6.sin6_addr); 1184af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1185af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1186af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1187af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr.sin_length = 0; 1188af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr.sin_family = PF_INET; 1189af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1190af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr._sockaddr_storage.sin_family = PF_INET; 1191af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1192af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr._sockaddr_in.sin_port = Htons(_destPort); 1193af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr._sockaddr_in.sin_addr = InetAddrIPV4(_destIP); 1194af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1195af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1196af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1197af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid UdpTransportImpl::BuildRemoteRTCPAddr() 1198af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1199af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ipV6Enabled) 1200af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1201af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1202af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr.sin_length = 0; 1203af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr.sin_family = PF_INET6; 1204af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1205af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr._sockaddr_storage.sin_family = PF_INET6; 1206af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1207af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1208af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr._sockaddr_in6.sin6_flowinfo=0; 1209af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr._sockaddr_in6.sin6_scope_id=0; 1210af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr._sockaddr_in6.sin6_port = Htons(_destPortRTCP); 1211af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org InetPresentationToNumeric(AF_INET6,_destIP, 1212af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org &_remoteRTCPAddr._sockaddr_in6.sin6_addr); 1213af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1214af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1215af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1216af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1217af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr.sin_length = 0; 1218af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr.sin_family = PF_INET; 1219af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1220af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr._sockaddr_storage.sin_family = PF_INET; 1221af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1222af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr._sockaddr_in.sin_port = Htons(_destPortRTCP); 1223af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr._sockaddr_in.sin_addr= InetAddrIPV4(_destIP); 1224af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1225af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1226af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1227af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgUdpTransportImpl::ErrorCode UdpTransportImpl::BindRTPSendSocket() 1228af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1229af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!_ptrSendRtpSocket) 1230af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1231af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kSocketInvalid; 1232af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1233af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!_ptrSendRtpSocket->ValidHandle()) 1234af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1235af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kIpAddressInvalid; 1236af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1237af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ipV6Enabled) 1238af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1239af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1240af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr.sin_length = 0; 1241af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr.sin_family = PF_INET6; 1242af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1243af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr._sockaddr_storage.sin_family = PF_INET6; 1244af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1245af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr._sockaddr_in6.sin6_flowinfo=0; 1246af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr._sockaddr_in6.sin6_scope_id=0; 1247af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr._sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u32[0] = 1248af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 0; // = INADDR_ANY 1249af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr._sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u32[1] = 1250af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 0; 1251af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr._sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u32[2] = 1252af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 0; 1253af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr._sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u32[3] = 1254af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 0; 1255af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr._sockaddr_in6.sin6_port = Htons(_srcPort); 1256af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket->Bind(_localRTPAddr) == false) 1257af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1258af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, _id, 1259af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to bind to port:%d ", _srcPort); 1260af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kFailedToBindPort; 1261af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1262af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1263af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else { 1264af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1265af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr.sin_length = 0; 1266af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr.sin_family = PF_INET; 1267af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1268af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr._sockaddr_storage.sin_family = PF_INET; 1269af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1270af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr._sockaddr_in.sin_addr = 0; 1271af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTPAddr._sockaddr_in.sin_port = Htons(_srcPort); 1272af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket->Bind(_localRTPAddr) == false) 1273af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1274af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, _id, 1275af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to bind to port:%d ", _srcPort); 1276af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kFailedToBindPort; 1277af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1278af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1279af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kNoSocketError; 1280af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1281af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1282af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgUdpTransportImpl::ErrorCode UdpTransportImpl::BindRTCPSendSocket() 1283af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1284af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!_ptrSendRtcpSocket) 1285af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1286af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kSocketInvalid; 1287af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1288af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1289af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ipV6Enabled) 1290af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1291af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1292af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr.sin_length = 0; 1293af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr.sin_family = PF_INET6; 1294af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1295af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr._sockaddr_storage.sin_family = PF_INET6; 1296af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1297af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr._sockaddr_in6.sin6_flowinfo=0; 1298af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr._sockaddr_in6.sin6_scope_id=0; 1299af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr._sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u32[0] = 1300af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 0; // = INADDR_ANY 1301af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr._sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u32[1] = 1302af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 0; 1303af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr._sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u32[2] = 1304af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 0; 1305af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr._sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u32[3] = 1306af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 0; 1307af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr._sockaddr_in6.sin6_port = Htons(_srcPortRTCP); 1308af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtcpSocket->Bind(_localRTCPAddr) == false) 1309af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1310af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, _id, 1311af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to bind to port:%d ", _srcPortRTCP); 1312af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kFailedToBindPort; 1313af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1314af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else { 1315af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1316af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr.sin_length = 0; 1317af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr.sin_family = PF_INET; 1318af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1319af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr._sockaddr_storage.sin_family = PF_INET; 1320af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1321af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr._sockaddr_in.sin_addr= 0; 1322af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localRTCPAddr._sockaddr_in.sin_port = Htons(_srcPortRTCP); 1323af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtcpSocket->Bind(_localRTCPAddr) == false) 1324af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1325af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, _id, 1326af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to bind to port:%d ", _srcPortRTCP); 1327af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kFailedToBindPort; 1328af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1329af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1330af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kNoSocketError; 1331af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1332af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1333af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgUdpTransportImpl::ErrorCode UdpTransportImpl::BindLocalRTPSocket() 1334af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1335af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!_ptrRtpSocket) 1336af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1337af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kSocketInvalid; 1338af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1339af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!IpV6Enabled()) 1340af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1341af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress recAddr; 1342af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(&recAddr, 0, sizeof(SocketAddress)); 1343af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org recAddr._sockaddr_storage.sin_family = AF_INET; 1344af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1345af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org recAddr.sin_length = 0; 1346af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org recAddr.sin_family = PF_INET; 1347af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1348af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org recAddr._sockaddr_storage.sin_family = PF_INET; 1349af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1350af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org recAddr._sockaddr_in.sin_addr = InetAddrIPV4(_localIP); 1351af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org recAddr._sockaddr_in.sin_port = Htons(_localPort); 1352af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1353af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!_ptrRtpSocket->Bind(recAddr)) 1354af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1355af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, _id, 1356af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to bind to port:%d ", _localPort); 1357af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kFailedToBindPort; 1358af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1359af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1360af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else 1361af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1362af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress stLclName; 1363af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1364af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName.sin_lenght = 0; 1365af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName.sin_family = PF_INET6; 1366af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1367af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName._sockaddr_storage.sin_family = PF_INET6; 1368af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1369af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org InetPresentationToNumeric(AF_INET6,_localIP, 1370af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org &stLclName._sockaddr_in6.sin6_addr); 1371af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName._sockaddr_in6.sin6_port = Htons(_localPort); 1372af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName._sockaddr_in6.sin6_flowinfo = 0; 1373af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName._sockaddr_in6.sin6_scope_id = 0; 1374af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1375af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!_ptrRtpSocket->Bind(stLclName)) 1376af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1377af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, _id, 1378af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to bind to port:%d ", _localPort); 1379af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kFailedToBindPort; 1380af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1381af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1382af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1383af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_localMulticastIP[0] != 0) 1384af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1385af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Join the multicast group from which to receive datagrams. 1386af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct ip_mreq mreq; 1387af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org mreq.imr_multiaddr.s_addr = InetAddrIPV4(_localMulticastIP); 1388af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org mreq.imr_interface.s_addr = INADDR_ANY; 1389af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1390af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!_ptrRtpSocket->SetSockopt(IPPROTO_IP,IP_ADD_MEMBERSHIP, 139191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org (int8_t*)&mreq,sizeof (mreq))) 1392af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1393af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 1394af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 1395af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 1396af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 1397af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "setsockopt() for multicast failed, not closing socket"); 1398af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 1399af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1400af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceInfo, kTraceTransport, _id, 1401af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "multicast group successfully joined"); 1402af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1403af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1404af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kNoSocketError; 1405af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1406af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1407af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgUdpTransportImpl::ErrorCode UdpTransportImpl::BindLocalRTCPSocket() 1408af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1409af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!_ptrRtcpSocket) 1410af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1411af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kSocketInvalid; 1412af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1413af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(! IpV6Enabled()) 1414af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1415af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress recAddr; 1416af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(&recAddr, 0, sizeof(SocketAddress)); 1417af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1418af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org recAddr.sin_length = 0; 1419af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org recAddr.sin_family = AF_INET; 1420af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1421af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org recAddr._sockaddr_storage.sin_family = AF_INET; 1422af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1423af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org recAddr._sockaddr_in.sin_addr = InetAddrIPV4(_localIP); 1424af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org recAddr._sockaddr_in.sin_port = Htons(_localPortRTCP); 1425af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1426af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!_ptrRtcpSocket->Bind(recAddr)) 1427af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1428af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, _id, 1429af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to bind to port:%d ", _localPortRTCP); 1430af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kFailedToBindPort; 1431af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1432af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1433af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else 1434af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1435af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress stLclName; 1436af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1437af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName.sin_length = 0; 1438af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName.sin_family = PF_INET6; 1439af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1440af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName._sockaddr_storage.sin_family = PF_INET6; 1441af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1442af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName._sockaddr_in6.sin6_flowinfo = 0; 1443af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName._sockaddr_in6.sin6_scope_id = 0; 1444af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org stLclName._sockaddr_in6.sin6_port = Htons(_localPortRTCP); 1445af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1446af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org InetPresentationToNumeric(AF_INET6,_localIP, 1447af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org &stLclName._sockaddr_in6.sin6_addr); 1448af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!_ptrRtcpSocket->Bind(stLclName)) 1449af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1450af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, _id, 1451af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to bind to port:%d ", _localPortRTCP); 1452af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kFailedToBindPort; 1453af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1454af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1455af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_localMulticastIP[0] != 0) 1456af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1457af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Join the multicast group from which to receive datagrams. 1458af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct ip_mreq mreq; 1459af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org mreq.imr_multiaddr.s_addr = InetAddrIPV4(_localMulticastIP); 1460af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org mreq.imr_interface.s_addr = INADDR_ANY; 1461af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1462af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!_ptrRtcpSocket->SetSockopt(IPPROTO_IP,IP_ADD_MEMBERSHIP, 146391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org (int8_t*)&mreq,sizeof (mreq))) 1464af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1465af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 1466af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 1467af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 1468af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 1469af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "setsockopt() for multicast failed, not closing socket"); 1470af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 1471af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1472af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceInfo, kTraceTransport, _id, 1473af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "multicast group successfully joined"); 1474af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1475af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1476af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kNoSocketError; 1477af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1478af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 147991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::InitializeSourcePorts(uint16_t rtpPort, 148091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t rtcpPort) 1481af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1482af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1483af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(rtpPort == 0) 1484af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1485af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1486af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "InitializeSourcePorts port 0 not allowed"); 1487af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kPortInvalid; 1488af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1489af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1490af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1491af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1492af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1493af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CloseSendSockets(); 1494af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1495af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_mgr == NULL) 1496af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1497af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1498af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1499af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1500af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _srcPort = rtpPort; 1501af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(rtcpPort == 0) 1502af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1503af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _srcPortRTCP = rtpPort+1; 1504af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1505af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1506af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _srcPortRTCP = rtcpPort; 1507af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1508af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _useSetSockOpt =false; 1509af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _tos=0; 1510af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _pcp=0; 1511af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1512af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtpSocket = _socket_creator->CreateSocket(_id, _mgr, NULL, NULL, 1513af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IpV6Enabled(), false); 1514af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtcpSocket = _socket_creator->CreateSocket(_id, _mgr, NULL, NULL, 1515af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IpV6Enabled(), false); 1516af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1517af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ErrorCode retVal = BindRTPSendSocket(); 1518af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(retVal != kNoSocketError) 1519af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1520af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = retVal; 1521af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1522af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1523af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org retVal = BindRTCPSendSocket(); 1524af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(retVal != kNoSocketError) 1525af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1526af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = retVal; 1527af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1528af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1529af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1530af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1531af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 153291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SourcePorts(uint16_t& rtpPort, 153391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& rtcpPort) const 1534af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1535af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1536af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1537af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpPort = (_srcPort != 0) ? _srcPort : _localPort; 1538af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpPort = (_srcPortRTCP != 0) ? _srcPortRTCP : _localPortRTCP; 1539af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1540af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1541af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1542af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1543af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef _WIN32 154491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::StartReceiving(uint32_t numberOfSocketBuffers) 1545af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 154691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::StartReceiving(uint32_t /*numberOfSocketBuffers*/) 1547af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1548af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1549af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1550af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_receiving) 1551af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1552af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1553af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1554af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrRtpSocket) 1555af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1556af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef _WIN32 1557af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!_ptrRtpSocket->StartReceiving(numberOfSocketBuffers)) 1558af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1559af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!_ptrRtpSocket->StartReceiving()) 1560af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1561af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1562af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1563af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to start receive on RTP socket"); 1564af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kStartReceiveError; 1565af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1566af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1567af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1568af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrRtcpSocket) 1569af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1570af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!_ptrRtcpSocket->StartReceiving()) 1571af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1572af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1573af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to start receive on RTCP socket"); 1574af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kStartReceiveError; 1575af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1576af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1577af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1578af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if( _ptrRtpSocket == NULL && 1579af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtcpSocket == NULL) 1580af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1581af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1582af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to StartReceiving, no socket initialized"); 1583af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kStartReceiveError; 1584af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1585af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1586af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _receiving = true; 1587af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1588af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1589af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1590af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgbool UdpTransportImpl::Receiving() const 1591af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1592af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _receiving; 1593af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1594af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 159591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::StopReceiving() 1596af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1597af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1598af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1599af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1600af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _receiving = false; 1601af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1602af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_ptrRtpSocket) 1603af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1604af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!_ptrRtpSocket->StopReceiving()) 1605af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1606af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1607af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to stop receiving on RTP socket"); 1608af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kStopReceiveError; 1609af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1610af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1611af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1612af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_ptrRtcpSocket) 1613af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1614af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!_ptrRtcpSocket->StopReceiving()) 1615af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1616af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1617af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Failed to stop receiving on RTCP socket"); 1618af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kStopReceiveError; 1619af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1620af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1621af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1622af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1623af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1624af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 162591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::InitializeSendSockets( 1626af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const char* ipaddr, 162791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const uint16_t rtpPort, 162891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const uint16_t rtcpPort) 1629af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1630af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1631af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1632af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPort = rtpPort; 1633af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(rtcpPort == 0) 1634af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1635af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPortRTCP = _destPort+1; 1636af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1637af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1638af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPortRTCP = rtcpPort; 1639af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1640af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1641af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(ipaddr == NULL) 1642af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1643af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!IsIpAddressValid(_destIP, IpV6Enabled())) 1644af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1645af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPort = 0; 1646af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPortRTCP = 0; 1647af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kIpAddressInvalid; 1648af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1649af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1650af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1651af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1652af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (IsIpAddressValid(ipaddr, IpV6Enabled())) 1653af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1654af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy( 1655af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destIP, 1656af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ipaddr, 1657af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IpV6Enabled() ? kIpAddressVersion6Length : 1658af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kIpAddressVersion4Length); 1659af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else { 1660af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPort = 0; 1661af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPortRTCP = 0; 1662af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kIpAddressInvalid; 1663af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1664af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1665af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1666af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildRemoteRTPAddr(); 1667af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildRemoteRTCPAddr(); 1668af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1669af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1670af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_ipV6Enabled) 1671af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1672af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_qos) 1673af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1674af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 1675af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceWarning, 1676af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 1677af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 1678af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "QOS is enabled but will be ignored since IPv6 is enabled"); 1679af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1680af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 1681af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1682af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // TODO (grunell): Multicast support is experimantal. 1683af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1684af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Put the first digit of the remote address in val. 168591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t val = ntohl(_remoteRTPAddr._sockaddr_in.sin_addr)>> 24; 1686af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1687af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if((val > 223) && (val < 240)) 1688af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1689af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Multicast address. 1690af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1691af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1692af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtpSock = (_ptrSendRtpSocket ? 1693af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtpSocket : _ptrRtpSocket); 1694af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtpSock || !rtpSock->ValidHandle()) 1695af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1696af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kSocketInvalid; 1697af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1698af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1699af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtcpSock = (_ptrSendRtcpSocket ? 1700af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtcpSocket : _ptrRtcpSocket); 1701af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtcpSock || !rtcpSock->ValidHandle()) 1702af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1703af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kSocketInvalid; 1704af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1705af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1706af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1707af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Set Time To Live to same region 170891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t iOptVal = 64; 1709af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtpSock->SetSockopt(IPPROTO_IP, IP_MULTICAST_TTL, 171091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org (int8_t*)&iOptVal, 171191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org sizeof (int32_t))) 1712af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1713af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1714af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "setsockopt for multicast error on RTP socket"); 1715af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket->CloseBlocking(); 1716af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket = NULL; 1717af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kMulticastAddressInvalid; 1718af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1719af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1720af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!rtcpSock->SetSockopt(IPPROTO_IP, IP_MULTICAST_TTL, 172191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org (int8_t*)&iOptVal, 172291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org sizeof (int32_t))) 1723af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1724af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1725af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "setsockopt for multicast error on RTCP socket"); 1726af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket->CloseBlocking(); 1727af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket = NULL; 1728af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = kMulticastAddressInvalid; 1729af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1730af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1731af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1732af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1733af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 1734af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1735af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 173691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgvoid UdpTransportImpl::BuildSockaddrIn(uint16_t portnr, 1737af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const char* ip, 1738af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress& remoteAddr) const 1739af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1740af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ipV6Enabled) 1741af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1742af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1743af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org remoteAddr.sin_length = 0; 1744af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org remoteAddr.sin_family = PF_INET6; 1745af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1746af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org remoteAddr._sockaddr_storage.sin_family = PF_INET6; 1747af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1748af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org remoteAddr._sockaddr_in6.sin6_port = Htons(portnr); 1749af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org InetPresentationToNumeric(AF_INET6, ip, 1750af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org &remoteAddr._sockaddr_in6.sin6_addr); 1751af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org remoteAddr._sockaddr_in6.sin6_flowinfo=0; 1752af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org remoteAddr._sockaddr_in6.sin6_scope_id=0; 1753af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1754af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1755af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN 1756af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org remoteAddr.sin_length = 0; 1757af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org remoteAddr.sin_family = PF_INET; 1758af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 1759af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org remoteAddr._sockaddr_storage.sin_family = PF_INET; 1760af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 1761af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org remoteAddr._sockaddr_in.sin_port = Htons(portnr); 1762af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org remoteAddr._sockaddr_in.sin_addr= InetAddrIPV4( 1763af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const_cast<char*>(ip)); 1764af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1765af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1766af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 176791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SendRaw(const int8_t *data, 176891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t length, 176991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t isRTCP, 177091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t portnr, 177191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const char* ip) 1772af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1773af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1774af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(isRTCP) 1775af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1776af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtcpSock = NULL; 1777af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtcpSocket) 1778af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1779af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpSock = _ptrSendRtcpSocket; 1780af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(_ptrRtcpSocket) 1781af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1782af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtcpSock = _ptrRtcpSocket; 1783af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1784af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1785af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1786af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1787af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(portnr == 0 && ip == NULL) 1788af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1789af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return rtcpSock->SendTo(data,length,_remoteRTCPAddr); 1790af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1791af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(portnr != 0 && ip != NULL) 1792af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1793af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress remoteAddr; 1794af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildSockaddrIn(portnr, ip, remoteAddr); 1795af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return rtcpSock->SendTo(data,length,remoteAddr); 1796af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(ip != NULL) 1797af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1798af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress remoteAddr; 1799af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildSockaddrIn(_destPortRTCP, ip, remoteAddr); 1800af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return rtcpSock->SendTo(data,length,remoteAddr); 1801af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1802af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1803af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress remoteAddr; 1804af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildSockaddrIn(portnr, _destIP, remoteAddr); 1805af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return rtcpSock->SendTo(data,length,remoteAddr); 1806af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1807af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else { 1808af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpSocketWrapper* rtpSock = NULL; 1809af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket) 1810af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1811af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpSock = _ptrSendRtpSocket; 1812af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1813af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(_ptrRtpSocket) 1814af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1815af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtpSock = _ptrRtpSocket; 1816af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1817af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1818af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1819af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1820af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(portnr == 0 && ip == NULL) 1821af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1822af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return rtpSock->SendTo(data,length,_remoteRTPAddr); 1823af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1824af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(portnr != 0 && ip != NULL) 1825af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1826af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress remoteAddr; 1827af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildSockaddrIn(portnr, ip, remoteAddr); 1828af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return rtpSock->SendTo(data,length,remoteAddr); 1829af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(ip != NULL) 1830af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1831af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress remoteAddr; 1832af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildSockaddrIn(_destPort, ip, remoteAddr); 1833af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return rtpSock->SendTo(data,length,remoteAddr); 1834af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1835af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1836af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress remoteAddr; 1837af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildSockaddrIn(portnr, _destIP, remoteAddr); 1838af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return rtpSock->SendTo(data,length,remoteAddr); 1839af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1840af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1841af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1842af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 184391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SendRTPPacketTo(const int8_t* data, 184491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t length, 184591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const SocketAddress& to) 1846af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1847af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1848af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket) 1849af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1850af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _ptrSendRtpSocket->SendTo(data,length,to); 1851af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1852af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(_ptrRtpSocket) 1853af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1854af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _ptrRtpSocket->SendTo(data,length,to); 1855af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1856af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1857af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1858af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 185991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SendRTCPPacketTo(const int8_t* data, 186091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t length, 186191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const SocketAddress& to) 1862af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1863af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1864af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1865af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1866af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtcpSocket) 1867af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1868af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _ptrSendRtcpSocket->SendTo(data,length,to); 1869af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1870af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(_ptrRtcpSocket) 1871af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1872af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _ptrRtcpSocket->SendTo(data,length,to); 1873af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1874af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1875af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1876af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 187791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SendRTPPacketTo(const int8_t* data, 187891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t length, 187991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const uint16_t rtpPort) 1880af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1881af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1882af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Use the current SocketAdress but update it with rtpPort. 1883af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress to; 1884af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memcpy(&to, &_remoteRTPAddr, sizeof(SocketAddress)); 1885af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1886af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ipV6Enabled) 1887af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1888af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org to._sockaddr_in6.sin6_port = Htons(rtpPort); 1889af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1890af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1891af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org to._sockaddr_in.sin_port = Htons(rtpPort); 1892af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1893af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1894af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket) 1895af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1896af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _ptrSendRtpSocket->SendTo(data,length,to); 1897af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1898af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(_ptrRtpSocket) 1899af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1900af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _ptrRtpSocket->SendTo(data,length,to); 1901af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1902af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1903af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1904af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 190591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SendRTCPPacketTo(const int8_t* data, 190691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t length, 190791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const uint16_t rtcpPort) 1908af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1909af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1910af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1911af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Use the current SocketAdress but update it with rtcpPort. 1912af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress to; 1913af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memcpy(&to, &_remoteRTCPAddr, sizeof(SocketAddress)); 1914af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1915af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ipV6Enabled) 1916af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1917af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org to._sockaddr_in6.sin6_port = Htons(rtcpPort); 1918af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1919af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1920af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org to._sockaddr_in.sin_port = Htons(rtcpPort); 1921af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1922af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1923af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtcpSocket) 1924af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1925af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _ptrSendRtcpSocket->SendTo(data,length,to); 1926af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1927af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(_ptrRtcpSocket) 1928af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1929af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return _ptrRtcpSocket->SendTo(data,length,to); 1930af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1931af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1932af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 1933af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1934af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgint UdpTransportImpl::SendPacket(int /*channel*/, const void* data, int length) 1935af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 1936af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceStream, kTraceTransport, _id, "%s", __FUNCTION__); 1937af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1938af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 1939af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1940af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_destIP[0] == 0) 1941af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1942af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1943af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1944af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_destPort == 0) 1945af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1946af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1947af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1948af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1949af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Create socket if it hasn't been set up already. 1950af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // TODO (hellner): why not fail here instead. Sockets not being initialized 1951af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // indicates that there is a problem somewhere. 1952af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if( _ptrSendRtpSocket == NULL && 1953af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket == NULL) 1954af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1955af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 1956af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceStateInfo, 1957af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 1958af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 1959af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Creating RTP socket since no receive or source socket is\ 1960af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org configured"); 1961af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1962af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket = _socket_creator->CreateSocket(_id, _mgr, this, 1963af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IncomingRTPCallback, 1964af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IpV6Enabled(), false); 1965af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1966af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Don't bind to a specific IP address. 1967af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(! IpV6Enabled()) 1968af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1969af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(_localIP, "0.0.0.0",16); 1970af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 1971af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1972af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(_localIP, "0000:0000:0000:0000:0000:0000:0000:0000", 1973af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kIpAddressVersion6Length); 1974af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1975af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localPort = _destPort; 1976af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1977af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ErrorCode retVal = BindLocalRTPSocket(); 1978af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(retVal != kNoSocketError) 1979af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 1980af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 1981af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "SendPacket() failed to bind RTP socket"); 1982af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = retVal; 1983af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CloseReceiveSockets(); 1984af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1985af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1986af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1987af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1988af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket) 1989af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 199091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org return _ptrSendRtpSocket->SendTo((const int8_t*)data, length, 1991af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr); 1992af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 1993af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(_ptrRtpSocket) 1994af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 199591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org return _ptrRtpSocket->SendTo((const int8_t*)data, length, 1996af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTPAddr); 1997af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 1998af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 1999af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2000af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2001af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgint UdpTransportImpl::SendRTCPPacket(int /*channel*/, const void* data, 2002af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org int length) 2003af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2004af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2005af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 2006af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_destIP[0] == 0) 2007af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2008af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2009af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2010af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_destPortRTCP == 0) 2011af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2012af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2013af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2014af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2015af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Create socket if it hasn't been set up already. 2016af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // TODO (hellner): why not fail here instead. Sockets not being initialized 2017af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // indicates that there is a problem somewhere. 2018af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if( _ptrSendRtcpSocket == NULL && 2019af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtcpSocket == NULL) 2020af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2021af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 2022af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceStateInfo, 2023af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 2024af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 2025af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Creating RTCP socket since no receive or source socket is\ 2026af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org configured"); 2027af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2028af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtcpSocket = _socket_creator->CreateSocket(_id, _mgr, this, 2029af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IncomingRTCPCallback, 2030af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IpV6Enabled(), false); 2031af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2032af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Don't bind to a specific IP address. 2033af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(! IpV6Enabled()) 2034af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2035af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(_localIP, "0.0.0.0",16); 2036af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 2037af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2038af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(_localIP, "0000:0000:0000:0000:0000:0000:0000:0000", 2039af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kIpAddressVersion6Length); 2040af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2041af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _localPortRTCP = _destPortRTCP; 2042af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2043af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ErrorCode retVal = BindLocalRTCPSocket(); 2044af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(retVal != kNoSocketError) 2045af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2046af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _lastError = retVal; 2047af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceError, kTraceTransport, _id, 2048af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "SendRTCPPacket() failed to bind RTCP socket"); 2049af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CloseReceiveSockets(); 2050af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2051af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2052af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2053af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2054af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtcpSocket) 2055af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 205691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org return _ptrSendRtcpSocket->SendTo((const int8_t*)data, length, 2057af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr); 2058af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else if(_ptrRtcpSocket) 2059af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 206091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org return _ptrRtcpSocket->SendTo((const int8_t*)data, length, 2061af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _remoteRTCPAddr); 2062af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2063af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2064af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2065af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 206691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SetSendIP(const char* ipaddr) 2067af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2068af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!IsIpAddressValid(ipaddr,IpV6Enabled())) 2069af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2070af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return kIpAddressInvalid; 2071af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2072af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 2073af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(_destIP, ipaddr,kIpAddressVersion6Length); 2074af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildRemoteRTPAddr(); 2075af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildRemoteRTCPAddr(); 2076af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2077af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2078af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 207991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransportImpl::SetSendPorts(uint16_t rtpPort, uint16_t rtcpPort) 2080af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2081af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_crit); 2082af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPort = rtpPort; 2083af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(rtcpPort == 0) 2084af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2085af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPortRTCP = _destPort+1; 2086af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 2087af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2088af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _destPortRTCP = rtcpPort; 2089af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2090af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildRemoteRTPAddr(); 2091af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org BuildRemoteRTCPAddr(); 2092af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2093af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2094af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2095af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid UdpTransportImpl::IncomingRTPCallback(CallbackObj obj, 209691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int8_t* rtpPacket, 209791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t rtpPacketLength, 2098af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const SocketAddress* from) 2099af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2100af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (rtpPacket && rtpPacketLength > 0) 2101af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2102af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpTransportImpl* socketTransport = (UdpTransportImpl*) obj; 2103af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org socketTransport->IncomingRTPFunction(rtpPacket, rtpPacketLength, from); 2104af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2105af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2106af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2107af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid UdpTransportImpl::IncomingRTCPCallback(CallbackObj obj, 210891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int8_t* rtcpPacket, 210991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t rtcpPacketLength, 2110af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const SocketAddress* from) 2111af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2112af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (rtcpPacket && rtcpPacketLength > 0) 2113af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2114af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org UdpTransportImpl* socketTransport = (UdpTransportImpl*) obj; 2115af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org socketTransport->IncomingRTCPFunction(rtcpPacket, rtcpPacketLength, 2116af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org from); 2117af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2118af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2119af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 212091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgvoid UdpTransportImpl::IncomingRTPFunction(const int8_t* rtpPacket, 212191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t rtpPacketLength, 2122af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const SocketAddress* fromSocket) 2123af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2124af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char ipAddress[kIpAddressVersion6Length]; 212591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t ipAddressLength = kIpAddressVersion6Length; 212691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t portNr = 0; 2127af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2128af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2129af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_critFilter); 2130af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (FilterIPAddress(fromSocket) == false) 2131af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2132af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Packet should be filtered out. Drop it. 2133af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceStream, kTraceTransport, _id, 2134af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Incoming RTP packet blocked by IP filter"); 2135af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return; 2136af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2137af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2138af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (IPAddressCached(*fromSocket, ipAddress, ipAddressLength, portNr) < 2139af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 0) 2140af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2141af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 2142af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 2143af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 2144af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 2145af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "UdpTransportImpl::IncomingRTPFunction - Cannot get sender\ 2146af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org information"); 2147af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 2148af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2149af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Make sure ipAddress is null terminated. 2150af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ipAddress[kIpAddressVersion6Length - 1] = 0; 2151af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(_fromIP, ipAddress, kIpAddressVersion6Length - 1); 2152af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2153af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2154af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Filter based on port. 2155af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_rtpFilterPort != 0 && 2156af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _rtpFilterPort != portNr) 2157af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2158af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Drop packet. 2159af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(_fromIP, 0, sizeof(_fromIP)); 2160af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 2161af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceStream, 2162af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 2163af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 2164af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Incoming RTP packet blocked by filter incoming from port:%d\ 2165af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org allowed port:%d", 2166af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org portNr, 2167af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _rtpFilterPort); 2168af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return; 2169af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2170af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _fromPort = portNr; 2171af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2172af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2173af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_critPacketCallback); 2174af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_packetCallback) 2175af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2176af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceStream, kTraceTransport, _id, 2177af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Incoming RTP packet from ip:%s port:%d", ipAddress, portNr); 2178af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _packetCallback->IncomingRTPPacket(rtpPacket, rtpPacketLength, 2179af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ipAddress, portNr); 2180af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2181af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2182af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 218391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgvoid UdpTransportImpl::IncomingRTCPFunction(const int8_t* rtcpPacket, 218491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t rtcpPacketLength, 2185af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const SocketAddress* fromSocket) 2186af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2187af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char ipAddress[kIpAddressVersion6Length]; 218891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t ipAddressLength = kIpAddressVersion6Length; 218991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t portNr = 0; 2190af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2191af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2192af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_critFilter); 2193af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (FilterIPAddress(fromSocket) == false) 2194af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2195af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Packet should be filtered out. Drop it. 2196af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceStream, kTraceTransport, _id, 2197af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Incoming RTCP packet blocked by IP filter"); 2198af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return; 2199af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2200af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (IPAddress(*fromSocket, ipAddress, ipAddressLength, portNr) < 0) 2201af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2202af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 2203af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 2204af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 2205af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 2206af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "UdpTransportImpl::IncomingRTCPFunction - Cannot get sender\ 2207af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org information"); 2208af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else { 2209af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Make sure ipAddress is null terminated. 2210af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ipAddress[kIpAddressVersion6Length - 1] = 0; 2211af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(_fromIP, ipAddress, kIpAddressVersion6Length - 1); 2212af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2213af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2214af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Filter based on port. 2215af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_rtcpFilterPort != 0 && 2216af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _rtcpFilterPort != portNr) 2217af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2218af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Drop packet. 2219af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 2220af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceStream, 2221af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 2222af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 2223af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Incoming RTCP packet blocked by filter incoming from port:%d\ 2224af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org allowed port:%d", 2225af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org portNr, 2226af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _rtpFilterPort); 2227af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return; 2228af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2229af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _fromPortRTCP = portNr; 2230af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2231af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2232af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org CriticalSectionScoped cs(_critPacketCallback); 2233af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_packetCallback) 2234af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2235af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceStream, kTraceTransport, _id, 2236af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "Incoming RTCP packet from ip:%s port:%d", ipAddress, 2237af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org portNr); 2238af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _packetCallback->IncomingRTCPPacket(rtcpPacket, rtcpPacketLength, 2239af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ipAddress, portNr); 2240af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2241af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2242af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2243af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgbool UdpTransportImpl::FilterIPAddress(const SocketAddress* fromAddress) 2244af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2245af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(fromAddress->_sockaddr_storage.sin_family == AF_INET) 2246af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2247af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_filterIPAddress._sockaddr_storage.sin_family == AF_INET) 2248af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2249af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // IP is stored in sin_addr. 2250af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_filterIPAddress._sockaddr_in.sin_addr != 0 && 2251af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org (_filterIPAddress._sockaddr_in.sin_addr != 2252af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org fromAddress->_sockaddr_in.sin_addr)) 2253af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2254af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2255af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2256af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2257af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2258af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else if(fromAddress->_sockaddr_storage.sin_family == AF_INET6) 2259af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2260af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_filterIPAddress._sockaddr_storage.sin_family == AF_INET6) 2261af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2262af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // IP is stored in sin_6addr. 226391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org for (int32_t i = 0; i < 4; i++) 2264af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2265af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (_filterIPAddress._sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u32[i] != 0 && 2266af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _filterIPAddress._sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u32[i] != fromAddress->_sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u32[i]) 2267af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2268af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2269af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2270af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2271af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2272af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2273af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else 2274af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2275af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 2276af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 2277af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 2278af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _id, 2279af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "UdpTransportImpl::FilterIPAddress() unknown address family"); 2280af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2281af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2282af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return true; 2283af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2284af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2285af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid UdpTransportImpl::CloseReceiveSockets() 2286af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2287af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrRtpSocket) 2288af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2289af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket->CloseBlocking(); 2290af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtpSocket = NULL; 2291af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2292af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrRtcpSocket) 2293af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2294af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtcpSocket->CloseBlocking(); 2295af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrRtcpSocket = NULL; 2296af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2297af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _receiving = false; 2298af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2299af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2300af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgvoid UdpTransportImpl::CloseSendSockets() 2301af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2302af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtpSocket) 2303af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2304af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtpSocket->CloseBlocking(); 2305af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtpSocket = 0; 2306af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2307af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(_ptrSendRtcpSocket) 2308af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2309af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtcpSocket->CloseBlocking(); 2310af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _ptrSendRtcpSocket = 0; 2311af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2312af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2313af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 231491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orguint16_t UdpTransport::Htons(const uint16_t port) 2315af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2316af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return htons(port); 2317af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2318af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 231991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orguint32_t UdpTransport::Htonl(const uint32_t a) 2320af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2321af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return htonl(a); 2322af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2323af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 232491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orguint32_t UdpTransport::InetAddrIPV4(const char* ip) 2325af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2326af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return ::inet_addr(ip); 2327af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2328af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 232991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransport::InetPresentationToNumeric(int32_t af, 233091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const char* src, 233191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org void* dst) 2332af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2333af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#if defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) 233491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org const int32_t result = inet_pton(af, src, dst); 2335af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return result > 0 ? 0 : -1; 2336af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2337af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#elif defined(_WIN32) 2338af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress temp; 2339af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org int length=sizeof(SocketAddress); 2340af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2341af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(af == AF_INET) 2342af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 234391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t result = WSAStringToAddressA( 2344af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org (const LPSTR)src, 2345af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org af, 2346af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 0, 2347af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org reinterpret_cast<struct sockaddr*>(&temp), 2348af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org &length); 2349af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(result != 0) 2350af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2351af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2352af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2353af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memcpy(dst,&(temp._sockaddr_in.sin_addr), 2354af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org sizeof(temp._sockaddr_in.sin_addr)); 2355af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2356af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2357af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else if(af == AF_INET6) 2358af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 235991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t result = WSAStringToAddressA( 2360af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org (const LPSTR)src, 2361af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org af, 2362af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 0, 2363af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org reinterpret_cast<struct sockaddr*>(&temp), 2364af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org &length); 2365af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(result !=0) 2366af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2367af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2368af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2369af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memcpy(dst,&(temp._sockaddr_in6.sin6_addr), 2370af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org sizeof(temp._sockaddr_in6.sin6_addr)); 2371af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2372af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2373af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 2374af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2375af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2376af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2377af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else 2378af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2379af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 2380af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2381af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 238291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransport::LocalHostAddressIPV6(char n_localIP[16]) 2383af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2384af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2385af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#if defined(_WIN32) 2386af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct addrinfo *result = NULL; 2387af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct addrinfo *ptr = NULL; 2388af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct addrinfo hints; 2389af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2390af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ZeroMemory(&hints, sizeof(hints)); 2391af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org hints.ai_family = AF_INET6; 2392af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2393af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char szHostName[256] = ""; 2394af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(::gethostname(szHostName, sizeof(szHostName) - 1)) 2395af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2396af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, -1, "gethostname failed"); 2397af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2398af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2399af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2400af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org DWORD dwRetval = getaddrinfo(szHostName, NULL, &hints, &result); 2401af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if ( dwRetval != 0 ) 2402af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2403af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, -1, 2404af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "getaddrinfo failed, error:%d", dwRetval); 2405af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2406af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2407af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org for(ptr=result; ptr != NULL ;ptr=ptr->ai_next) 2408af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2409af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org switch (ptr->ai_family) 2410af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2411af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org case AF_INET6: 2412af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2413af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org for(int i = 0; i< 16; i++) 2414af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2415af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org n_localIP[i] = (*(SocketAddress*)ptr->ai_addr). 2416af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org _sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u8[i]; 2417af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2418af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org bool islocalIP = true; 2419af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2420af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org for(int n = 0; n< 15; n++) 2421af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2422af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(n_localIP[n] != 0) 2423af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2424af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org islocalIP = false; 2425af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2426af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2427af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2428af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2429af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(islocalIP && n_localIP[15] != 1) 2430af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2431af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org islocalIP = false; 2432af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2433af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2434af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(islocalIP && ptr->ai_next) 2435af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2436af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org continue; 2437af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2438af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(n_localIP[0] == 0xfe && 2439af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org n_localIP[1] == 0x80 && ptr->ai_next) 2440af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2441af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org continue; 2442af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2443af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org freeaddrinfo(result); 2444af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2445af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2446af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org default: 2447af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2448af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }; 2449af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2450af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org freeaddrinfo(result); 2451af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, -1, 2452af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "getaddrinfo failed to find address"); 2453af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2454af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2455af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#elif defined(WEBRTC_MAC) 2456af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct ifaddrs* ptrIfAddrs = NULL; 2457af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct ifaddrs* ptrIfAddrsStart = NULL; 2458af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2459af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org getifaddrs(&ptrIfAddrsStart); 2460af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ptrIfAddrs = ptrIfAddrsStart; 2461af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org while(ptrIfAddrs) 2462af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2463af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(ptrIfAddrs->ifa_addr->sa_family == AF_INET6) 2464af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2465af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const struct sockaddr_in6* sock_in6 = 2466af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org reinterpret_cast<struct sockaddr_in6*>(ptrIfAddrs->ifa_addr); 2467af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const struct in6_addr* sin6_addr = &sock_in6->sin6_addr; 2468af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2469af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (IN6_IS_ADDR_LOOPBACK(sin6_addr) || 2470af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org IN6_IS_ADDR_LINKLOCAL(sin6_addr)) { 2471af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ptrIfAddrs = ptrIfAddrs->ifa_next; 2472af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org continue; 2473af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2474af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memcpy(n_localIP, sin6_addr->s6_addr, sizeof(sin6_addr->s6_addr)); 2475af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org freeifaddrs(ptrIfAddrsStart); 2476af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2477af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2478af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ptrIfAddrs = ptrIfAddrs->ifa_next; 2479af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2480af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org freeifaddrs(ptrIfAddrsStart); 2481af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2482af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#elif defined(WEBRTC_ANDROID) 2483af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2484af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else // WEBRTC_LINUX 2485af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct 2486af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2487af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct nlmsghdr n; 2488af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct ifaddrmsg r; 2489af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } req; 2490af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2491af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct rtattr* rta = NULL; 2492af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org int status; 2493af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char buf[16384]; // = 16 * 1024 (16 kB) 2494af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct nlmsghdr* nlmp; 2495af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct ifaddrmsg* rtmp; 2496af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct rtattr* rtatp; 2497af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org int rtattrlen; 2498af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct in6_addr* in6p; 2499af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2500af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org int fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); 2501af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (fd == -1) 2502af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2503af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2504af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2505af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2506af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // RTM_GETADDR is used to fetch the ip address from the kernel interface 2507af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // table. Populate the msg structure (req) the size of the message buffer 2508af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // is specified to netlinkmessage header, and flags values are set as 2509af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // NLM_F_ROOT | NLM_F_REQUEST. 2510af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // The request flag must be set for all messages requesting the data from 2511af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // kernel. The root flag is used to notify the kernel to return the full 2512af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // tabel. Another flag (not used) is NLM_F_MATCH. This is used to get only 2513af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // specified entries in the table. At the time of writing this program this 2514af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // flag is not implemented in kernel 2515af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2516af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(&req, 0, sizeof(req)); 2517af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); 2518af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org req.n.nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT; 2519af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org req.n.nlmsg_type = RTM_GETADDR; 2520af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org req.r.ifa_family = AF_INET6; 2521af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2522af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Fill up all the attributes for the rtnetlink header. 2523af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // The lenght is very important. 16 signifies the ipv6 address. 2524af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rta = (struct rtattr*)(((char*)&req) + NLMSG_ALIGN(req.n.nlmsg_len)); 2525af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rta->rta_len = RTA_LENGTH(16); 2526af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2527af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org status = send(fd, &req, req.n.nlmsg_len, 0); 2528af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (status < 0) 2529af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2530af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org close(fd); 2531af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2532af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2533af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org status = recv(fd, buf, sizeof(buf), 0); 2534af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (status < 0) 2535af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2536af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org close(fd); 2537af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2538af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2539af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(status == 0) 2540af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2541af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org close(fd); 2542af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2543af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2544af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org close(fd); 2545af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2546af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // The message is stored in buff. Parse the message to get the requested 2547af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // data. 2548af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2549af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org nlmp = (struct nlmsghdr*)buf; 2550af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org int len = nlmp->nlmsg_len; 2551af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org int req_len = len - sizeof(*nlmp); 2552af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2553af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (req_len < 0 || len > status) 2554af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2555af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2556af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2557af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (!NLMSG_OK_NO_WARNING(nlmp, status)) 2558af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2559af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2560af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2561af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtmp = (struct ifaddrmsg*)NLMSG_DATA(nlmp); 2562af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtatp = (struct rtattr*)IFA_RTA(rtmp); 2563af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2564af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org rtattrlen = IFA_PAYLOAD(nlmp); 2565af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2566af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org for (; RTA_OK(rtatp, rtattrlen); rtatp = RTA_NEXT(rtatp, rtattrlen)) 2567af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2568af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2569af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Here we hit the fist chunk of the message. Time to validate the 2570af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // type. For more info on the different types see 2571af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // "man(7) rtnetlink" The table below is taken from man pages. 2572af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Attributes 2573af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // rta_type value type description 2574af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // ------------------------------------------------------------- 2575af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // IFA_UNSPEC - unspecified. 2576af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // IFA_ADDRESS raw protocol address interface address 2577af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // IFA_LOCAL raw protocol address local address 2578af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // IFA_LABEL asciiz string name of the interface 2579af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // IFA_BROADCAST raw protocol address broadcast address. 2580af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // IFA_ANYCAST raw protocol address anycast address 2581af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // IFA_CACHEINFO struct ifa_cacheinfo Address information. 2582af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2583af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(rtatp->rta_type == IFA_ADDRESS) 2584af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2585af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org bool islocalIP = true; 2586af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org in6p = (struct in6_addr*)RTA_DATA(rtatp); 2587af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org for(int n = 0; n< 15; n++) 2588af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2589af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(in6p->s6_addr[n] != 0) 2590af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2591af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org islocalIP = false; 2592af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2593af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2594af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2595af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(islocalIP && in6p->s6_addr[15] != 1) 2596af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2597af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org islocalIP = false; 2598af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2599af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!islocalIP) 2600af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2601af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org for(int i = 0; i< 16; i++) 2602af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2603af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org n_localIP[i] = in6p->s6_addr[i]; 2604af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2605af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(n_localIP[0] == static_cast<char> (0xfe) 2606af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org && n_localIP[1] == static_cast<char>(0x80) ) 2607af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2608af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Auto configured IP. 2609af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org continue; 2610af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2611af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2612af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2613af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2614af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2615af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2616af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2617af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 2618af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2619af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 262091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransport::LocalHostAddress(uint32_t& localIP) 2621af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2622af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org #if defined(_WIN32) 2623af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org hostent* localHost; 2624af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org localHost = gethostbyname( "" ); 2625af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(localHost) 2626af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2627af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(localHost->h_addrtype != AF_INET) 2628af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2629af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 2630af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 2631af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 2632af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org -1, 2633af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "LocalHostAddress can only get local IP for IP Version 4"); 2634af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2635af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2636af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org localIP= Htonl( 2637af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org (*(struct in_addr *)localHost->h_addr_list[0]).S_un.S_addr); 2638af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2639af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2640af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else 2641af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 264291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t error = WSAGetLastError(); 2643af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, -1, 2644af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "gethostbyname failed, error:%d", error); 2645af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2646af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2647af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#elif (defined(WEBRTC_MAC)) 2648af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char localname[255]; 2649af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (gethostname(localname, 255) != -1) 2650af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2651af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org hostent* localHost; 2652af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org localHost = gethostbyname(localname); 2653af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(localHost) 2654af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2655af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(localHost->h_addrtype != AF_INET) 2656af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2657af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE( 2658af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceError, 2659af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org kTraceTransport, 2660af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org -1, 2661af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org "LocalHostAddress can only get local IP for IP Version 4"); 2662af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2663af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2664af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org localIP = Htonl((*(struct in_addr*)*localHost->h_addr_list).s_addr); 2665af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2666af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2667af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2668af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org WEBRTC_TRACE(kTraceWarning, kTraceTransport, -1, "gethostname failed"); 2669af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2670af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#else // WEBRTC_LINUX 2671af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org int sockfd, size = 1; 2672af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct ifreq* ifr; 2673af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct ifconf ifc; 2674af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2675af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) 2676af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2677af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2678af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2679af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ifc.ifc_len = IFRSIZE; 2680af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ifc.ifc_req = NULL; 2681af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org do 2682af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2683af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ++size; 2684af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Buffer size needed is unknown. Try increasing it until no overflow 2685af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // occurs. 2686af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (NULL == (ifc.ifc_req = (ifreq*)realloc(ifc.ifc_req, IFRSIZE))) { 2687af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org fprintf(stderr, "Out of memory.\n"); 2688af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org exit(EXIT_FAILURE); 2689af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2690af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ifc.ifc_len = IFRSIZE; 2691af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (ioctl(sockfd, SIOCGIFCONF, &ifc)) 2692af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2693af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org free(ifc.ifc_req); 2694af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org close(sockfd); 2695af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2696af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2697af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } while (IFRSIZE <= ifc.ifc_len); 2698af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2699af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ifr = ifc.ifc_req; 2700af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org for (;(char *) ifr < (char *) ifc.ifc_req + ifc.ifc_len; ++ifr) 2701af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2702af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (ifr->ifr_addr.sa_data == (ifr+1)->ifr_addr.sa_data) 2703af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2704af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org continue; // duplicate, skip it 2705af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2706af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (ioctl(sockfd, SIOCGIFFLAGS, ifr)) 2707af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2708af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org continue; // failed to get flags, skip it 2709af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2710af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(strncmp(ifr->ifr_name, "lo",3) == 0) 2711af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2712af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org continue; 2713af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org }else 2714af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2715af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org struct sockaddr* saddr = &(ifr->ifr_addr); 2716af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org SocketAddress* socket_addess = reinterpret_cast<SocketAddress*>( 2717af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org saddr); 2718af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org localIP = Htonl(socket_addess->_sockaddr_in.sin_addr); 2719af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org close(sockfd); 2720af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org free(ifc.ifc_req); 2721af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2722af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2723af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2724af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org free(ifc.ifc_req); 2725af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org close(sockfd); 2726af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2727af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org#endif 2728af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2729af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 273091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.orgint32_t UdpTransport::IPAddress(const SocketAddress& address, 273191cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org char* ip, 273291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint32_t& ipSize, 273391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t& sourcePort) 2734af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2735af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org #if defined(_WIN32) 2736af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org DWORD dwIPSize = ipSize; 273791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t returnvalue = WSAAddressToStringA((LPSOCKADDR)(&address), 2738af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org sizeof(SocketAddress), 2739af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org NULL, 2740af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ip, 2741af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org &dwIPSize); 2742af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(returnvalue == -1) 2743af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2744af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2745af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2746af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 274791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t source_port = 0; 2748af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(address._sockaddr_storage.sin_family == AF_INET) 2749af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2750af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Parse IP assuming format "a.b.c.d:port". 2751af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char* ipEnd = strchr(ip,':'); 2752af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(ipEnd != NULL) 2753af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2754af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org *ipEnd = '\0'; 2755af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 275691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org ipSize = (int32_t)strlen(ip); 2757af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(ipSize == 0) 2758af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2759af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2760af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2761af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org source_port = address._sockaddr_in.sin_port; 2762af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2763af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else 2764af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2765af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Parse IP assuming format "[address]:port". 2766af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char* ipEnd = strchr(ip,']'); 2767af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(ipEnd != NULL) 2768af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2769af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Calculate length 277091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t adrSize = int32_t(ipEnd - ip) - 1; 2771af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memmove(ip, &ip[1], adrSize); // Remove '[' 2772af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org *(ipEnd - 1) = '\0'; 2773af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 277491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org ipSize = (int32_t)strlen(ip); 2775af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(ipSize == 0) 2776af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2777af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2778af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2779af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2780af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org source_port = address._sockaddr_in6.sin6_port; 2781af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2782af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Convert port number to network byte order. 2783af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org sourcePort = htons(source_port); 2784af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2785af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2786af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) 278791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t ipFamily = address._sockaddr_storage.sin_family; 2788af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org const void* ptrNumericIP = NULL; 2789af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2790af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(ipFamily == AF_INET) 2791af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2792af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ptrNumericIP = &(address._sockaddr_in.sin_addr); 2793af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2794af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else if(ipFamily == AF_INET6) 2795af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2796af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ptrNumericIP = &(address._sockaddr_in6.sin6_addr); 2797af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2798af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else 2799af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2800af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2801af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2802af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(inet_ntop(ipFamily, ptrNumericIP, ip, ipSize) == NULL) 2803af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2804af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2805af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 280691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org uint16_t source_port; 2807af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(ipFamily == AF_INET) 2808af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2809af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org source_port = address._sockaddr_in.sin_port; 2810af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 2811af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2812af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org source_port = address._sockaddr_in6.sin6_port; 2813af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2814af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Convert port number to network byte order. 2815af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org sourcePort = htons(source_port); 2816af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return 0; 2817af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org #else 2818af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return -1; 2819af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org #endif 2820af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2821af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2822af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.orgbool UdpTransport::IsIpAddressValid(const char* ipadr, const bool ipV6) 2823af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org{ 2824af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(ipV6) 2825af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 282691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t len = (int32_t)strlen(ipadr); 2827af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if( len>39 || len == 0) 2828af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2829af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2830af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2831af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 283291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t i; 283391cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t colonPos[7] = {0,0,0,0,0,0,0}; 283491cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t lastColonPos = -2; 283591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t nColons = 0; 283691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t nDubbleColons = 0; 283791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t nDots = 0; 283891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t error = 0; 2839af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char c; 2840af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org for(i = 0; i < len ; i++) 2841af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2842af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org c=ipadr[i]; 2843af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(isxdigit(c)) 2844af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org ; 2845af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else if(c == ':') 2846af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2847af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(nColons < 7) 2848af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org colonPos[nColons] = i; 2849af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if((i-lastColonPos)==1) 2850af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org nDubbleColons++; 2851af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org lastColonPos=i; 2852af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(nDots != 0) 2853af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2854af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org error = 1; 2855af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2856af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org nColons++; 2857af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2858af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else if(c == '.') 2859af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2860af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org nDots++; 2861af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2862af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else 2863af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2864af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org error = 1; 2865af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2866af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2867af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2868af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(error) 2869af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2870af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2871af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2872af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(nDubbleColons > 1) 2873af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2874af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2875af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2876af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(nColons > 7 || nColons < 2) 2877af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2878af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2879af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2880af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(!(nDots == 3 || nDots == 0)) 2881af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2882af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2883af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2884af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org lastColonPos = -1; 288591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t charsBeforeColon = 0; 2886af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org for(i = 0; i < nColons; i++) 2887af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2888af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org charsBeforeColon=colonPos[i]-lastColonPos-1; 2889af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(charsBeforeColon > 4) 2890af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2891af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2892af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2893af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org lastColonPos=colonPos[i]; 2894af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 289591cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t lengthAfterLastColon = len - lastColonPos - 1; 2896af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(nDots == 0) 2897af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2898af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(lengthAfterLastColon > 4) 2899af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2900af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2901af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if(nDots == 3 && lengthAfterLastColon > 0) 2902af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2903af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return IsIpAddressValid((ipadr+lastColonPos+1),false); 2904af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2905af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2906af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2907af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else 2908af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 290991cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t len = (int32_t)strlen(ipadr); 2910af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if((len>15)||(len==0)) 2911af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2912af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2913af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2914af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2915af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // IPv4 should be [0-255].[0-255].[0-255].[0-255] 291691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t i; 291791cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t nDots = 0; 291891cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t iDotPos[4] = {0,0,0,0}; 2919af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2920af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org for (i = 0; (i < len) && (nDots < 4); i++) 2921af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2922af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (ipadr[i] == (char)'.') 2923af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2924af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Store index of dots and count number of dots. 2925af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org iDotPos[nDots++] = i; 2926af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2927af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2928af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2929af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org bool allUnder256 = false; 2930af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // TODO (hellner): while loop seems to be abused here to get 2931af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // label like functionality. Fix later to avoid introducing bugs now. 2932af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2933af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org // Check that all numbers are smaller than 256. 2934af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org do 2935af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2936af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (nDots != 3 ) 2937af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2938af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2939af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2940af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2941af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (iDotPos[0] <= 3) 2942af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2943af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char nr[4]; 2944af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(nr,0,4); 2945af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(nr,&ipadr[0],iDotPos[0]); 294691cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t num = atoi(nr); 2947af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (num > 255) 2948af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2949af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2950af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2951af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else { 2952af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2953af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2954af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2955af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (iDotPos[1] - iDotPos[0] <= 4) 2956af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2957af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char nr[4]; 2958af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(nr,0,4); 2959af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(nr,&ipadr[iDotPos[0]+1], iDotPos[1] - iDotPos[0] - 1); 296091cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t num = atoi(nr); 2961af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (num > 255) 2962af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2963af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else { 2964af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2965af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2966af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2967af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (iDotPos[2] - iDotPos[1] <= 4) 2968af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2969af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org char nr[4]; 2970af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(nr,0,4); 2971af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(nr,&ipadr[iDotPos[1]+1], iDotPos[1] - iDotPos[0] - 1); 297291cab7186d535be98c837285ce24918188e9c8c3pbos@webrtc.org int32_t num = atoi(nr); 2973af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (num > 255) 2974af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2975af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2976af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org memset(nr,0,4); 2977af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org strncpy(nr,&ipadr[iDotPos[2]+1], len - iDotPos[2] -1); 2978af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org num = atoi(nr); 2979af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (num > 255) 2980af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2981af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org else 2982af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org allUnder256 = true; 2983af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } else 2984af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org break; 2985af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } while(false); 2986af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2987af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org if (nDots != 3 || !allUnder256) 2988af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org { 2989af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return false; 2990af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2991af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org } 2992af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org return true; 2993af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} 2994af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org 2995af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} // namespace test 2996af6aa7b49ba5fbfd09f901ae15b5278121d10f6fpwestin@webrtc.org} // namespace webrtc 2997