OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 _localPort(0), | 117 _localPort(0), |
118 _localPortRTCP(0), | 118 _localPortRTCP(0), |
119 _srcPort(0), | 119 _srcPort(0), |
120 _srcPortRTCP(0), | 120 _srcPortRTCP(0), |
121 _fromPort(0), | 121 _fromPort(0), |
122 _fromPortRTCP(0), | 122 _fromPortRTCP(0), |
123 _fromIP(), | 123 _fromIP(), |
124 _destIP(), | 124 _destIP(), |
125 _localIP(), | 125 _localIP(), |
126 _localMulticastIP(), | 126 _localMulticastIP(), |
127 _ptrRtpSocket(NULL), | 127 _ptrRtpSocket(nullptr), |
128 _ptrRtcpSocket(NULL), | 128 _ptrRtcpSocket(nullptr), |
129 _ptrSendRtpSocket(NULL), | 129 _ptrSendRtpSocket(nullptr), |
130 _ptrSendRtcpSocket(NULL), | 130 _ptrSendRtcpSocket(nullptr), |
131 _remoteRTPAddr(), | 131 _remoteRTPAddr(), |
132 _remoteRTCPAddr(), | 132 _remoteRTCPAddr(), |
133 _localRTPAddr(), | 133 _localRTPAddr(), |
134 _localRTCPAddr(), | 134 _localRTCPAddr(), |
135 _tos(0), | 135 _tos(0), |
136 _receiving(false), | 136 _receiving(false), |
137 _useSetSockOpt(false), | 137 _useSetSockOpt(false), |
138 _qos(false), | 138 _qos(false), |
139 _pcp(0), | 139 _pcp(0), |
140 _ipV6Enabled(false), | 140 _ipV6Enabled(false), |
141 _serviceType(0), | 141 _serviceType(0), |
142 _overrideDSCP(0), | 142 _overrideDSCP(0), |
143 _maxBitrate(0), | 143 _maxBitrate(0), |
144 _cachLock(RWLockWrapper::CreateRWLock()), | 144 _cachLock(RWLockWrapper::CreateRWLock()), |
145 _previousAddress(), | 145 _previousAddress(), |
146 _previousIP(), | 146 _previousIP(), |
147 _previousIPSize(0), | 147 _previousIPSize(0), |
148 _previousSourcePort(0), | 148 _previousSourcePort(0), |
149 _filterIPAddress(), | 149 _filterIPAddress(), |
150 _rtpFilterPort(0), | 150 _rtpFilterPort(0), |
151 _rtcpFilterPort(0), | 151 _rtcpFilterPort(0), |
152 _packetCallback(0) | 152 _packetCallback(0) { |
153 { | 153 memset(&_remoteRTPAddr, 0, sizeof(_remoteRTPAddr)); |
154 memset(&_remoteRTPAddr, 0, sizeof(_remoteRTPAddr)); | 154 memset(&_remoteRTCPAddr, 0, sizeof(_remoteRTCPAddr)); |
155 memset(&_remoteRTCPAddr, 0, sizeof(_remoteRTCPAddr)); | 155 memset(&_localRTPAddr, 0, sizeof(_localRTPAddr)); |
156 memset(&_localRTPAddr, 0, sizeof(_localRTPAddr)); | 156 memset(&_localRTCPAddr, 0, sizeof(_localRTCPAddr)); |
157 memset(&_localRTCPAddr, 0, sizeof(_localRTCPAddr)); | |
158 | 157 |
159 memset(_fromIP, 0, sizeof(_fromIP)); | 158 memset(_fromIP, 0, sizeof(_fromIP)); |
160 memset(_destIP, 0, sizeof(_destIP)); | 159 memset(_destIP, 0, sizeof(_destIP)); |
161 memset(_localIP, 0, sizeof(_localIP)); | 160 memset(_localIP, 0, sizeof(_localIP)); |
162 memset(_localMulticastIP, 0, sizeof(_localMulticastIP)); | 161 memset(_localMulticastIP, 0, sizeof(_localMulticastIP)); |
163 | 162 |
164 memset(&_filterIPAddress, 0, sizeof(_filterIPAddress)); | 163 memset(&_filterIPAddress, 0, sizeof(_filterIPAddress)); |
165 | 164 |
166 WEBRTC_TRACE(kTraceMemory, kTraceTransport, id, "%s created", __FUNCTION__); | 165 WEBRTC_TRACE(kTraceMemory, kTraceTransport, id, "%s created", __FUNCTION__); |
167 } | 166 } |
168 | 167 |
169 UdpTransportImpl::~UdpTransportImpl() | 168 UdpTransportImpl::~UdpTransportImpl() |
170 { | 169 { |
171 CloseSendSockets(); | 170 CloseSendSockets(); |
172 CloseReceiveSockets(); | 171 CloseReceiveSockets(); |
173 delete _crit; | 172 delete _crit; |
174 delete _critFilter; | 173 delete _critFilter; |
175 delete _critPacketCallback; | 174 delete _critPacketCallback; |
176 delete _cachLock; | 175 delete _cachLock; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 UdpTransportData* const packetCallback, | 234 UdpTransportData* const packetCallback, |
236 const uint16_t portnr, | 235 const uint16_t portnr, |
237 const char* ip, | 236 const char* ip, |
238 const char* multicastIpAddr, | 237 const char* multicastIpAddr, |
239 const uint16_t rtcpPort) | 238 const uint16_t rtcpPort) |
240 { | 239 { |
241 { | 240 { |
242 CriticalSectionScoped cs(_critPacketCallback); | 241 CriticalSectionScoped cs(_critPacketCallback); |
243 _packetCallback = packetCallback; | 242 _packetCallback = packetCallback; |
244 | 243 |
245 if(packetCallback == NULL) | 244 if (packetCallback == nullptr) { |
246 { | 245 WEBRTC_TRACE(kTraceStateInfo, kTraceTransport, _id, |
247 WEBRTC_TRACE(kTraceStateInfo, kTraceTransport, _id, | 246 "Closing down receive sockets"); |
248 "Closing down receive sockets"); | 247 return 0; |
249 return 0; | |
250 } | 248 } |
251 } | 249 } |
252 | 250 |
253 CriticalSectionScoped cs(_crit); | 251 CriticalSectionScoped cs(_crit); |
254 CloseReceiveSockets(); | 252 CloseReceiveSockets(); |
255 | 253 |
256 if(portnr == 0) | 254 if(portnr == 0) |
257 { | 255 { |
258 // TODO (hellner): why not just fail here? | 256 // TODO (hellner): why not just fail here? |
259 if(_destPort == 0) | 257 if(_destPort == 0) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 strncpy(_localMulticastIP, multicastIpAddr, | 310 strncpy(_localMulticastIP, multicastIpAddr, |
313 kIpAddressVersion6Length); | 311 kIpAddressVersion6Length); |
314 } else | 312 } else |
315 { | 313 { |
316 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 314 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
317 "InitializeReceiveSockets invalid IP address"); | 315 "InitializeReceiveSockets invalid IP address"); |
318 _lastError = kIpAddressInvalid; | 316 _lastError = kIpAddressInvalid; |
319 return -1; | 317 return -1; |
320 } | 318 } |
321 } | 319 } |
322 if(_mgr == NULL) | 320 if (_mgr == nullptr) { |
323 { | 321 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
324 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 322 "InitializeReceiveSockets no socket manager"); |
325 "InitializeReceiveSockets no socket manager"); | 323 return -1; |
326 return -1; | |
327 } | 324 } |
328 | 325 |
329 _useSetSockOpt=false; | 326 _useSetSockOpt=false; |
330 _tos=0; | 327 _tos=0; |
331 _pcp=0; | 328 _pcp=0; |
332 | 329 |
333 _ptrRtpSocket = _socket_creator->CreateSocket(_id, _mgr, this, | 330 _ptrRtpSocket = _socket_creator->CreateSocket(_id, _mgr, this, |
334 IncomingRTPCallback, | 331 IncomingRTPCallback, |
335 IpV6Enabled(), false); | 332 IpV6Enabled(), false); |
336 | 333 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 WEBRTC_TRACE( | 742 WEBRTC_TRACE( |
746 kTraceError, | 743 kTraceError, |
747 kTraceTransport, | 744 kTraceTransport, |
748 _id, | 745 _id, |
749 "Can't switch SetSockOpt method without disabling TOS first"); | 746 "Can't switch SetSockOpt method without disabling TOS first"); |
750 _lastError = kTosInvalid; | 747 _lastError = kTosInvalid; |
751 return -1; | 748 return -1; |
752 } | 749 } |
753 } | 750 } |
754 CriticalSectionScoped cs(_crit); | 751 CriticalSectionScoped cs(_crit); |
755 UdpSocketWrapper* rtpSock = NULL; | 752 UdpSocketWrapper* rtpSock = nullptr; |
756 UdpSocketWrapper* rtcpSock = NULL; | 753 UdpSocketWrapper* rtcpSock = nullptr; |
757 if(_ptrSendRtpSocket) | 754 if(_ptrSendRtpSocket) |
758 { | 755 { |
759 rtpSock = _ptrSendRtpSocket; | 756 rtpSock = _ptrSendRtpSocket; |
760 }else | 757 }else |
761 { | 758 { |
762 rtpSock = _ptrRtpSocket; | 759 rtpSock = _ptrRtpSocket; |
763 } | 760 } |
764 if (rtpSock == NULL) | 761 if (rtpSock == nullptr) { |
765 { | 762 _lastError = kSocketInvalid; |
766 _lastError = kSocketInvalid; | 763 return -1; |
767 return -1; | |
768 } | 764 } |
769 if(!rtpSock->ValidHandle()) | 765 if(!rtpSock->ValidHandle()) |
770 { | 766 { |
771 _lastError = kSocketInvalid; | 767 _lastError = kSocketInvalid; |
772 return -1; | 768 return -1; |
773 } | 769 } |
774 if(_ptrSendRtcpSocket) | 770 if(_ptrSendRtcpSocket) |
775 { | 771 { |
776 rtcpSock = _ptrSendRtcpSocket; | 772 rtcpSock = _ptrSendRtcpSocket; |
777 }else | 773 }else |
778 { | 774 { |
779 rtcpSock = _ptrRtcpSocket; | 775 rtcpSock = _ptrRtcpSocket; |
780 } | 776 } |
781 if (rtcpSock == NULL) | 777 if (rtcpSock == nullptr) { |
782 { | 778 _lastError = kSocketInvalid; |
783 _lastError = kSocketInvalid; | 779 return -1; |
784 return -1; | |
785 } | 780 } |
786 if(!rtcpSock->ValidHandle()) | 781 if(!rtcpSock->ValidHandle()) |
787 { | 782 { |
788 _lastError = kSocketInvalid; | 783 _lastError = kSocketInvalid; |
789 return -1; | 784 return -1; |
790 } | 785 } |
791 | 786 |
792 if (useSetSockOpt) | 787 if (useSetSockOpt) |
793 { | 788 { |
794 #ifdef _WIN32 | 789 #ifdef _WIN32 |
795 OSVERSIONINFO OsVersion; | 790 OSVERSIONINFO OsVersion; |
796 OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | 791 OsVersion.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
797 GetVersionEx(&OsVersion); | 792 GetVersionEx(&OsVersion); |
798 // Disable QoS before setting ToS on Windows XP. This is done by closing | 793 // Disable QoS before setting ToS on Windows XP. This is done by closing |
799 // and re-opening the sockets. | 794 // and re-opening the sockets. |
800 // TODO (hellner): why not just fail here and force the user to | 795 // TODO (hellner): why not just fail here and force the user to |
801 // re-initialize sockets? Doing this may trick the user | 796 // re-initialize sockets? Doing this may trick the user |
802 // into thinking that the sockets are in a state which | 797 // into thinking that the sockets are in a state which |
803 // they aren't. | 798 // they aren't. |
804 if (OsVersion.dwMajorVersion == 5 && | 799 if (OsVersion.dwMajorVersion == 5 && |
805 OsVersion.dwMinorVersion == 1) | 800 OsVersion.dwMinorVersion == 1) |
806 { | 801 { |
807 if(!_useSetSockOpt) | 802 if(!_useSetSockOpt) |
808 { | 803 { |
809 if(_ptrSendRtpSocket) | 804 if(_ptrSendRtpSocket) |
810 { | 805 { |
811 CloseSendSockets(); | 806 CloseSendSockets(); |
812 _ptrSendRtpSocket = | 807 _ptrSendRtpSocket = _socket_creator->CreateSocket( |
813 _socket_creator->CreateSocket(_id, _mgr, NULL, | 808 _id, _mgr, nullptr, nullptr, IpV6Enabled(), true); |
814 NULL, IpV6Enabled(), | 809 _ptrSendRtcpSocket = _socket_creator->CreateSocket( |
815 true); | 810 _id, _mgr, nullptr, nullptr, IpV6Enabled(), true); |
816 _ptrSendRtcpSocket = | |
817 _socket_creator->CreateSocket(_id, _mgr, NULL, | |
818 NULL, IpV6Enabled(), | |
819 true); | |
820 rtpSock=_ptrSendRtpSocket; | 811 rtpSock=_ptrSendRtpSocket; |
821 rtcpSock=_ptrSendRtcpSocket; | 812 rtcpSock=_ptrSendRtcpSocket; |
822 ErrorCode retVal = BindRTPSendSocket(); | 813 ErrorCode retVal = BindRTPSendSocket(); |
823 if(retVal != kNoSocketError) | 814 if(retVal != kNoSocketError) |
824 { | 815 { |
825 _lastError = retVal; | 816 _lastError = retVal; |
826 return -1; | 817 return -1; |
827 } | 818 } |
828 retVal = BindRTCPSendSocket(); | 819 retVal = BindRTCPSendSocket(); |
829 if(retVal != kNoSocketError) | 820 if(retVal != kNoSocketError) |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
939 return -1; | 930 return -1; |
940 } | 931 } |
941 if ((PCP < 0) || (PCP > 7)) | 932 if ((PCP < 0) || (PCP > 7)) |
942 { | 933 { |
943 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "Invalid PCP"); | 934 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "Invalid PCP"); |
944 _lastError = kPcpError; | 935 _lastError = kPcpError; |
945 return -1; | 936 return -1; |
946 } | 937 } |
947 | 938 |
948 CriticalSectionScoped cs(_crit); | 939 CriticalSectionScoped cs(_crit); |
949 UdpSocketWrapper* rtpSock = NULL; | 940 UdpSocketWrapper* rtpSock = nullptr; |
950 UdpSocketWrapper* rtcpSock = NULL; | 941 UdpSocketWrapper* rtcpSock = nullptr; |
951 if(_ptrSendRtpSocket) | 942 if(_ptrSendRtpSocket) |
952 { | 943 { |
953 rtpSock = _ptrSendRtpSocket; | 944 rtpSock = _ptrSendRtpSocket; |
954 }else | 945 }else |
955 { | 946 { |
956 rtpSock = _ptrRtpSocket; | 947 rtpSock = _ptrRtpSocket; |
957 } | 948 } |
958 if (rtpSock == NULL) | 949 if (rtpSock == nullptr) { |
959 { | 950 _lastError = kSocketInvalid; |
960 _lastError = kSocketInvalid; | 951 return -1; |
961 return -1; | |
962 } | 952 } |
963 if(!rtpSock->ValidHandle()) | 953 if(!rtpSock->ValidHandle()) |
964 { | 954 { |
965 _lastError = kSocketInvalid; | 955 _lastError = kSocketInvalid; |
966 return -1; | 956 return -1; |
967 } | 957 } |
968 if(_ptrSendRtcpSocket) | 958 if(_ptrSendRtcpSocket) |
969 { | 959 { |
970 rtcpSock = _ptrSendRtcpSocket; | 960 rtcpSock = _ptrSendRtcpSocket; |
971 }else | 961 }else |
972 { | 962 { |
973 rtcpSock = _ptrRtcpSocket; | 963 rtcpSock = _ptrRtcpSocket; |
974 } | 964 } |
975 if (rtcpSock == NULL) | 965 if (rtcpSock == nullptr) { |
976 { | 966 _lastError = kSocketInvalid; |
977 _lastError = kSocketInvalid; | 967 return -1; |
978 return -1; | |
979 } | 968 } |
980 if(!rtcpSock->ValidHandle()) | 969 if(!rtcpSock->ValidHandle()) |
981 { | 970 { |
982 _lastError = kSocketInvalid; | 971 _lastError = kSocketInvalid; |
983 return -1; | 972 return -1; |
984 } | 973 } |
985 | 974 |
986 #if defined(_WIN32) | 975 #if defined(_WIN32) |
987 if (rtpSock->SetPCP(PCP) != 0) | 976 if (rtpSock->SetPCP(PCP) != 0) |
988 { | 977 { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 _lastError = kIpVersion6Error; | 1038 _lastError = kIpVersion6Error; |
1050 return -1; | 1039 return -1; |
1051 } | 1040 } |
1052 _ipV6Enabled = true; | 1041 _ipV6Enabled = true; |
1053 return 0; | 1042 return 0; |
1054 } | 1043 } |
1055 | 1044 |
1056 int32_t UdpTransportImpl::FilterIP( | 1045 int32_t UdpTransportImpl::FilterIP( |
1057 char filterIPAddress[kIpAddressVersion6Length]) const | 1046 char filterIPAddress[kIpAddressVersion6Length]) const |
1058 { | 1047 { |
1059 | 1048 if (filterIPAddress == nullptr) { |
1060 if(filterIPAddress == NULL) | 1049 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
1061 { | 1050 "FilterIP: Invalid argument"); |
1062 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 1051 return -1; |
1063 "FilterIP: Invalid argument"); | |
1064 return -1; | |
1065 } | 1052 } |
1066 if(_filterIPAddress._sockaddr_storage.sin_family == 0) | 1053 if(_filterIPAddress._sockaddr_storage.sin_family == 0) |
1067 { | 1054 { |
1068 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "No Filter configured"); | 1055 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, "No Filter configured"); |
1069 return -1; | 1056 return -1; |
1070 } | 1057 } |
1071 CriticalSectionScoped cs(_critFilter); | 1058 CriticalSectionScoped cs(_critFilter); |
1072 uint32_t ipSize = kIpAddressVersion6Length; | 1059 uint32_t ipSize = kIpAddressVersion6Length; |
1073 uint16_t sourcePort; | 1060 uint16_t sourcePort; |
1074 return IPAddress(_filterIPAddress, filterIPAddress, ipSize, sourcePort); | 1061 return IPAddress(_filterIPAddress, filterIPAddress, ipSize, sourcePort); |
1075 } | 1062 } |
1076 | 1063 |
1077 int32_t UdpTransportImpl::SetFilterIP( | 1064 int32_t UdpTransportImpl::SetFilterIP( |
1078 const char filterIPAddress[kIpAddressVersion6Length]) | 1065 const char filterIPAddress[kIpAddressVersion6Length]) |
1079 { | 1066 { |
1080 if(filterIPAddress == NULL) | 1067 if (filterIPAddress == nullptr) { |
1081 { | 1068 memset(&_filterIPAddress, 0, sizeof(_filterIPAddress)); |
1082 memset(&_filterIPAddress, 0, sizeof(_filterIPAddress)); | 1069 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, "Filter IP reset"); |
1083 WEBRTC_TRACE(kTraceDebug, kTraceTransport, _id, "Filter IP reset"); | 1070 return 0; |
1084 return 0; | |
1085 } | 1071 } |
1086 CriticalSectionScoped cs(_critFilter); | 1072 CriticalSectionScoped cs(_critFilter); |
1087 if (_ipV6Enabled) | 1073 if (_ipV6Enabled) |
1088 { | 1074 { |
1089 _filterIPAddress._sockaddr_storage.sin_family = AF_INET6; | 1075 _filterIPAddress._sockaddr_storage.sin_family = AF_INET6; |
1090 | 1076 |
1091 if (InetPresentationToNumeric( | 1077 if (InetPresentationToNumeric( |
1092 AF_INET6, | 1078 AF_INET6, |
1093 filterIPAddress, | 1079 filterIPAddress, |
1094 &_filterIPAddress._sockaddr_in6.sin6_addr) < 0) | 1080 &_filterIPAddress._sockaddr_in6.sin6_addr) < 0) |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 1471 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
1486 "InitializeSourcePorts port 0 not allowed"); | 1472 "InitializeSourcePorts port 0 not allowed"); |
1487 _lastError = kPortInvalid; | 1473 _lastError = kPortInvalid; |
1488 return -1; | 1474 return -1; |
1489 } | 1475 } |
1490 | 1476 |
1491 CriticalSectionScoped cs(_crit); | 1477 CriticalSectionScoped cs(_crit); |
1492 | 1478 |
1493 CloseSendSockets(); | 1479 CloseSendSockets(); |
1494 | 1480 |
1495 if(_mgr == NULL) | 1481 if (_mgr == nullptr) { |
1496 { | 1482 return -1; |
1497 return -1; | |
1498 } | 1483 } |
1499 | 1484 |
1500 _srcPort = rtpPort; | 1485 _srcPort = rtpPort; |
1501 if(rtcpPort == 0) | 1486 if(rtcpPort == 0) |
1502 { | 1487 { |
1503 _srcPortRTCP = rtpPort+1; | 1488 _srcPortRTCP = rtpPort+1; |
1504 } else | 1489 } else |
1505 { | 1490 { |
1506 _srcPortRTCP = rtcpPort; | 1491 _srcPortRTCP = rtcpPort; |
1507 } | 1492 } |
1508 _useSetSockOpt =false; | 1493 _useSetSockOpt =false; |
1509 _tos=0; | 1494 _tos=0; |
1510 _pcp=0; | 1495 _pcp=0; |
1511 | 1496 |
1512 _ptrSendRtpSocket = _socket_creator->CreateSocket(_id, _mgr, NULL, NULL, | 1497 _ptrSendRtpSocket = _socket_creator->CreateSocket( |
1513 IpV6Enabled(), false); | 1498 _id, _mgr, nullptr, nullptr, IpV6Enabled(), false); |
1514 _ptrSendRtcpSocket = _socket_creator->CreateSocket(_id, _mgr, NULL, NULL, | 1499 _ptrSendRtcpSocket = _socket_creator->CreateSocket( |
1515 IpV6Enabled(), false); | 1500 _id, _mgr, nullptr, nullptr, IpV6Enabled(), false); |
1516 | 1501 |
1517 ErrorCode retVal = BindRTPSendSocket(); | 1502 ErrorCode retVal = BindRTPSendSocket(); |
1518 if(retVal != kNoSocketError) | 1503 if(retVal != kNoSocketError) |
1519 { | 1504 { |
1520 _lastError = retVal; | 1505 _lastError = retVal; |
1521 return -1; | 1506 return -1; |
1522 } | 1507 } |
1523 retVal = BindRTCPSendSocket(); | 1508 retVal = BindRTCPSendSocket(); |
1524 if(retVal != kNoSocketError) | 1509 if(retVal != kNoSocketError) |
1525 { | 1510 { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 if(_ptrRtcpSocket) | 1553 if(_ptrRtcpSocket) |
1569 { | 1554 { |
1570 if(!_ptrRtcpSocket->StartReceiving()) | 1555 if(!_ptrRtcpSocket->StartReceiving()) |
1571 { | 1556 { |
1572 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 1557 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
1573 "Failed to start receive on RTCP socket"); | 1558 "Failed to start receive on RTCP socket"); |
1574 _lastError = kStartReceiveError; | 1559 _lastError = kStartReceiveError; |
1575 return -1; | 1560 return -1; |
1576 } | 1561 } |
1577 } | 1562 } |
1578 if( _ptrRtpSocket == NULL && | 1563 if (_ptrRtpSocket == nullptr && _ptrRtcpSocket == nullptr) { |
1579 _ptrRtcpSocket == NULL) | 1564 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
1580 { | 1565 "Failed to StartReceiving, no socket initialized"); |
1581 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 1566 _lastError = kStartReceiveError; |
1582 "Failed to StartReceiving, no socket initialized"); | 1567 return -1; |
1583 _lastError = kStartReceiveError; | |
1584 return -1; | |
1585 } | 1568 } |
1586 _receiving = true; | 1569 _receiving = true; |
1587 return 0; | 1570 return 0; |
1588 } | 1571 } |
1589 | 1572 |
1590 bool UdpTransportImpl::Receiving() const | 1573 bool UdpTransportImpl::Receiving() const |
1591 { | 1574 { |
1592 return _receiving; | 1575 return _receiving; |
1593 } | 1576 } |
1594 | 1577 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 CriticalSectionScoped cs(_crit); | 1614 CriticalSectionScoped cs(_crit); |
1632 _destPort = rtpPort; | 1615 _destPort = rtpPort; |
1633 if(rtcpPort == 0) | 1616 if(rtcpPort == 0) |
1634 { | 1617 { |
1635 _destPortRTCP = _destPort+1; | 1618 _destPortRTCP = _destPort+1; |
1636 } else | 1619 } else |
1637 { | 1620 { |
1638 _destPortRTCP = rtcpPort; | 1621 _destPortRTCP = rtcpPort; |
1639 } | 1622 } |
1640 | 1623 |
1641 if(ipaddr == NULL) | 1624 if (ipaddr == nullptr) { |
1642 { | 1625 if (!IsIpAddressValid(_destIP, IpV6Enabled())) { |
1643 if (!IsIpAddressValid(_destIP, IpV6Enabled())) | 1626 _destPort = 0; |
1644 { | 1627 _destPortRTCP = 0; |
1645 _destPort = 0; | 1628 _lastError = kIpAddressInvalid; |
1646 _destPortRTCP = 0; | 1629 return -1; |
1647 _lastError = kIpAddressInvalid; | 1630 } |
1648 return -1; | |
1649 } | |
1650 } else | 1631 } else |
1651 { | 1632 { |
1652 if (IsIpAddressValid(ipaddr, IpV6Enabled())) | 1633 if (IsIpAddressValid(ipaddr, IpV6Enabled())) |
1653 { | 1634 { |
1654 strncpy( | 1635 strncpy( |
1655 _destIP, | 1636 _destIP, |
1656 ipaddr, | 1637 ipaddr, |
1657 IpV6Enabled() ? kIpAddressVersion6Length : | 1638 IpV6Enabled() ? kIpAddressVersion6Length : |
1658 kIpAddressVersion4Length); | 1639 kIpAddressVersion4Length); |
1659 } else { | 1640 } else { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1706 | 1687 |
1707 // Set Time To Live to same region | 1688 // Set Time To Live to same region |
1708 int32_t iOptVal = 64; | 1689 int32_t iOptVal = 64; |
1709 if (!rtpSock->SetSockopt(IPPROTO_IP, IP_MULTICAST_TTL, | 1690 if (!rtpSock->SetSockopt(IPPROTO_IP, IP_MULTICAST_TTL, |
1710 (int8_t*)&iOptVal, | 1691 (int8_t*)&iOptVal, |
1711 sizeof (int32_t))) | 1692 sizeof (int32_t))) |
1712 { | 1693 { |
1713 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 1694 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
1714 "setsockopt for multicast error on RTP socket"); | 1695 "setsockopt for multicast error on RTP socket"); |
1715 _ptrRtpSocket->CloseBlocking(); | 1696 _ptrRtpSocket->CloseBlocking(); |
1716 _ptrRtpSocket = NULL; | 1697 _ptrRtpSocket = nullptr; |
1717 _lastError = kMulticastAddressInvalid; | 1698 _lastError = kMulticastAddressInvalid; |
1718 return -1; | 1699 return -1; |
1719 } | 1700 } |
1720 if (!rtcpSock->SetSockopt(IPPROTO_IP, IP_MULTICAST_TTL, | 1701 if (!rtcpSock->SetSockopt(IPPROTO_IP, IP_MULTICAST_TTL, |
1721 (int8_t*)&iOptVal, | 1702 (int8_t*)&iOptVal, |
1722 sizeof (int32_t))) | 1703 sizeof (int32_t))) |
1723 { | 1704 { |
1724 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 1705 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
1725 "setsockopt for multicast error on RTCP socket"); | 1706 "setsockopt for multicast error on RTCP socket"); |
1726 _ptrRtpSocket->CloseBlocking(); | 1707 _ptrRtpSocket->CloseBlocking(); |
1727 _ptrRtpSocket = NULL; | 1708 _ptrRtpSocket = nullptr; |
1728 _lastError = kMulticastAddressInvalid; | 1709 _lastError = kMulticastAddressInvalid; |
1729 return -1; | 1710 return -1; |
1730 } | 1711 } |
1731 } | 1712 } |
1732 } | 1713 } |
1733 return 0; | 1714 return 0; |
1734 } | 1715 } |
1735 | 1716 |
1736 void UdpTransportImpl::BuildSockaddrIn(uint16_t portnr, | 1717 void UdpTransportImpl::BuildSockaddrIn(uint16_t portnr, |
1737 const char* ip, | 1718 const char* ip, |
(...skipping 28 matching lines...) Expand all Loading... |
1766 | 1747 |
1767 int32_t UdpTransportImpl::SendRaw(const int8_t *data, | 1748 int32_t UdpTransportImpl::SendRaw(const int8_t *data, |
1768 size_t length, | 1749 size_t length, |
1769 int32_t isRTCP, | 1750 int32_t isRTCP, |
1770 uint16_t portnr, | 1751 uint16_t portnr, |
1771 const char* ip) | 1752 const char* ip) |
1772 { | 1753 { |
1773 CriticalSectionScoped cs(_crit); | 1754 CriticalSectionScoped cs(_crit); |
1774 if(isRTCP) | 1755 if(isRTCP) |
1775 { | 1756 { |
1776 UdpSocketWrapper* rtcpSock = NULL; | 1757 UdpSocketWrapper* rtcpSock = nullptr; |
1777 if(_ptrSendRtcpSocket) | 1758 if (_ptrSendRtcpSocket) { |
1778 { | 1759 rtcpSock = _ptrSendRtcpSocket; |
1779 rtcpSock = _ptrSendRtcpSocket; | |
1780 } else if(_ptrRtcpSocket) | 1760 } else if(_ptrRtcpSocket) |
1781 { | 1761 { |
1782 rtcpSock = _ptrRtcpSocket; | 1762 rtcpSock = _ptrRtcpSocket; |
1783 } else | 1763 } else |
1784 { | 1764 { |
1785 return -1; | 1765 return -1; |
1786 } | 1766 } |
1787 if(portnr == 0 && ip == NULL) | 1767 if (portnr == 0 && ip == nullptr) { |
1788 { | 1768 return rtcpSock->SendTo(data, length, _remoteRTCPAddr); |
1789 return rtcpSock->SendTo(data,length,_remoteRTCPAddr); | |
1790 | 1769 |
1791 } else if(portnr != 0 && ip != NULL) | 1770 } else if (portnr != 0 && ip != nullptr) { |
1792 { | 1771 SocketAddress remoteAddr; |
1793 SocketAddress remoteAddr; | 1772 BuildSockaddrIn(portnr, ip, remoteAddr); |
1794 BuildSockaddrIn(portnr, ip, remoteAddr); | 1773 return rtcpSock->SendTo(data, length, remoteAddr); |
1795 return rtcpSock->SendTo(data,length,remoteAddr); | 1774 } else if (ip != nullptr) { |
1796 } else if(ip != NULL) | 1775 SocketAddress remoteAddr; |
1797 { | 1776 BuildSockaddrIn(_destPortRTCP, ip, remoteAddr); |
1798 SocketAddress remoteAddr; | 1777 return rtcpSock->SendTo(data, length, remoteAddr); |
1799 BuildSockaddrIn(_destPortRTCP, ip, remoteAddr); | |
1800 return rtcpSock->SendTo(data,length,remoteAddr); | |
1801 } else | 1778 } else |
1802 { | 1779 { |
1803 SocketAddress remoteAddr; | 1780 SocketAddress remoteAddr; |
1804 BuildSockaddrIn(portnr, _destIP, remoteAddr); | 1781 BuildSockaddrIn(portnr, _destIP, remoteAddr); |
1805 return rtcpSock->SendTo(data,length,remoteAddr); | 1782 return rtcpSock->SendTo(data,length,remoteAddr); |
1806 } | 1783 } |
1807 } else { | 1784 } else { |
1808 UdpSocketWrapper* rtpSock = NULL; | 1785 UdpSocketWrapper* rtpSock = nullptr; |
1809 if(_ptrSendRtpSocket) | 1786 if (_ptrSendRtpSocket) { |
1810 { | 1787 rtpSock = _ptrSendRtpSocket; |
1811 rtpSock = _ptrSendRtpSocket; | |
1812 | 1788 |
1813 } else if(_ptrRtpSocket) | 1789 } else if(_ptrRtpSocket) |
1814 { | 1790 { |
1815 rtpSock = _ptrRtpSocket; | 1791 rtpSock = _ptrRtpSocket; |
1816 } else | 1792 } else |
1817 { | 1793 { |
1818 return -1; | 1794 return -1; |
1819 } | 1795 } |
1820 if(portnr == 0 && ip == NULL) | 1796 if (portnr == 0 && ip == nullptr) { |
1821 { | 1797 return rtpSock->SendTo(data, length, _remoteRTPAddr); |
1822 return rtpSock->SendTo(data,length,_remoteRTPAddr); | |
1823 | 1798 |
1824 } else if(portnr != 0 && ip != NULL) | 1799 } else if (portnr != 0 && ip != nullptr) { |
1825 { | 1800 SocketAddress remoteAddr; |
1826 SocketAddress remoteAddr; | 1801 BuildSockaddrIn(portnr, ip, remoteAddr); |
1827 BuildSockaddrIn(portnr, ip, remoteAddr); | 1802 return rtpSock->SendTo(data, length, remoteAddr); |
1828 return rtpSock->SendTo(data,length,remoteAddr); | 1803 } else if (ip != nullptr) { |
1829 } else if(ip != NULL) | 1804 SocketAddress remoteAddr; |
1830 { | 1805 BuildSockaddrIn(_destPort, ip, remoteAddr); |
1831 SocketAddress remoteAddr; | 1806 return rtpSock->SendTo(data, length, remoteAddr); |
1832 BuildSockaddrIn(_destPort, ip, remoteAddr); | |
1833 return rtpSock->SendTo(data,length,remoteAddr); | |
1834 } else | 1807 } else |
1835 { | 1808 { |
1836 SocketAddress remoteAddr; | 1809 SocketAddress remoteAddr; |
1837 BuildSockaddrIn(portnr, _destIP, remoteAddr); | 1810 BuildSockaddrIn(portnr, _destIP, remoteAddr); |
1838 return rtpSock->SendTo(data,length,remoteAddr); | 1811 return rtpSock->SendTo(data,length,remoteAddr); |
1839 } | 1812 } |
1840 } | 1813 } |
1841 } | 1814 } |
1842 | 1815 |
1843 int32_t UdpTransportImpl::SendRTPPacketTo(const int8_t* data, | 1816 int32_t UdpTransportImpl::SendRTPPacketTo(const int8_t* data, |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1943 return false; | 1916 return false; |
1944 } | 1917 } |
1945 if(_destPort == 0) | 1918 if(_destPort == 0) |
1946 { | 1919 { |
1947 return false; | 1920 return false; |
1948 } | 1921 } |
1949 | 1922 |
1950 // Create socket if it hasn't been set up already. | 1923 // Create socket if it hasn't been set up already. |
1951 // TODO (hellner): why not fail here instead. Sockets not being initialized | 1924 // TODO (hellner): why not fail here instead. Sockets not being initialized |
1952 // indicates that there is a problem somewhere. | 1925 // indicates that there is a problem somewhere. |
1953 if( _ptrSendRtpSocket == NULL && | 1926 if (_ptrSendRtpSocket == nullptr && _ptrRtpSocket == nullptr) { |
1954 _ptrRtpSocket == NULL) | 1927 WEBRTC_TRACE(kTraceStateInfo, kTraceTransport, _id, |
1955 { | 1928 "Creating RTP socket since no receive or source socket is\ |
1956 WEBRTC_TRACE( | |
1957 kTraceStateInfo, | |
1958 kTraceTransport, | |
1959 _id, | |
1960 "Creating RTP socket since no receive or source socket is\ | |
1961 configured"); | 1929 configured"); |
1962 | 1930 |
1963 _ptrRtpSocket = _socket_creator->CreateSocket(_id, _mgr, this, | 1931 _ptrRtpSocket = _socket_creator->CreateSocket( |
1964 IncomingRTPCallback, | 1932 _id, _mgr, this, IncomingRTPCallback, IpV6Enabled(), false); |
1965 IpV6Enabled(), false); | |
1966 | 1933 |
1967 // Don't bind to a specific IP address. | 1934 // Don't bind to a specific IP address. |
1968 if(! IpV6Enabled()) | 1935 if (!IpV6Enabled()) { |
1969 { | 1936 strncpy(_localIP, "0.0.0.0", 16); |
1970 strncpy(_localIP, "0.0.0.0",16); | 1937 } else { |
1971 } else | 1938 strncpy(_localIP, "0000:0000:0000:0000:0000:0000:0000:0000", |
1972 { | 1939 kIpAddressVersion6Length); |
1973 strncpy(_localIP, "0000:0000:0000:0000:0000:0000:0000:0000", | 1940 } |
1974 kIpAddressVersion6Length); | 1941 _localPort = _destPort; |
1975 } | |
1976 _localPort = _destPort; | |
1977 | 1942 |
1978 ErrorCode retVal = BindLocalRTPSocket(); | 1943 ErrorCode retVal = BindLocalRTPSocket(); |
1979 if(retVal != kNoSocketError) | 1944 if (retVal != kNoSocketError) { |
1980 { | 1945 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
1981 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 1946 "SendPacket() failed to bind RTP socket"); |
1982 "SendPacket() failed to bind RTP socket"); | 1947 _lastError = retVal; |
1983 _lastError = retVal; | 1948 CloseReceiveSockets(); |
1984 CloseReceiveSockets(); | 1949 return false; |
1985 return false; | 1950 } |
1986 } | |
1987 } | 1951 } |
1988 | 1952 |
1989 if(_ptrSendRtpSocket) | 1953 if(_ptrSendRtpSocket) |
1990 { | 1954 { |
1991 return _ptrSendRtpSocket->SendTo((const int8_t*)data, length, | 1955 return _ptrSendRtpSocket->SendTo((const int8_t*)data, length, |
1992 _remoteRTPAddr) >= 0; | 1956 _remoteRTPAddr) >= 0; |
1993 | 1957 |
1994 } else if(_ptrRtpSocket) | 1958 } else if(_ptrRtpSocket) |
1995 { | 1959 { |
1996 return _ptrRtpSocket->SendTo((const int8_t*)data, length, | 1960 return _ptrRtpSocket->SendTo((const int8_t*)data, length, |
1997 _remoteRTPAddr) >= 0; | 1961 _remoteRTPAddr) >= 0; |
1998 } | 1962 } |
1999 return false; | 1963 return false; |
2000 } | 1964 } |
2001 | 1965 |
2002 bool UdpTransportImpl::SendRtcp(const uint8_t* data, size_t length) { | 1966 bool UdpTransportImpl::SendRtcp(const uint8_t* data, size_t length) { |
2003 CriticalSectionScoped cs(_crit); | 1967 CriticalSectionScoped cs(_crit); |
2004 if(_destIP[0] == 0) | 1968 if(_destIP[0] == 0) |
2005 { | 1969 { |
2006 return false; | 1970 return false; |
2007 } | 1971 } |
2008 if(_destPortRTCP == 0) | 1972 if(_destPortRTCP == 0) |
2009 { | 1973 { |
2010 return false; | 1974 return false; |
2011 } | 1975 } |
2012 | 1976 |
2013 // Create socket if it hasn't been set up already. | 1977 // Create socket if it hasn't been set up already. |
2014 // TODO (hellner): why not fail here instead. Sockets not being initialized | 1978 // TODO (hellner): why not fail here instead. Sockets not being initialized |
2015 // indicates that there is a problem somewhere. | 1979 // indicates that there is a problem somewhere. |
2016 if( _ptrSendRtcpSocket == NULL && | 1980 if (_ptrSendRtcpSocket == nullptr && _ptrRtcpSocket == nullptr) { |
2017 _ptrRtcpSocket == NULL) | 1981 WEBRTC_TRACE(kTraceStateInfo, kTraceTransport, _id, |
2018 { | 1982 "Creating RTCP socket since no receive or source socket is\ |
2019 WEBRTC_TRACE( | |
2020 kTraceStateInfo, | |
2021 kTraceTransport, | |
2022 _id, | |
2023 "Creating RTCP socket since no receive or source socket is\ | |
2024 configured"); | 1983 configured"); |
2025 | 1984 |
2026 _ptrRtcpSocket = _socket_creator->CreateSocket(_id, _mgr, this, | 1985 _ptrRtcpSocket = _socket_creator->CreateSocket( |
2027 IncomingRTCPCallback, | 1986 _id, _mgr, this, IncomingRTCPCallback, IpV6Enabled(), false); |
2028 IpV6Enabled(), false); | |
2029 | 1987 |
2030 // Don't bind to a specific IP address. | 1988 // Don't bind to a specific IP address. |
2031 if(! IpV6Enabled()) | 1989 if (!IpV6Enabled()) { |
2032 { | 1990 strncpy(_localIP, "0.0.0.0", 16); |
2033 strncpy(_localIP, "0.0.0.0",16); | 1991 } else { |
2034 } else | 1992 strncpy(_localIP, "0000:0000:0000:0000:0000:0000:0000:0000", |
2035 { | 1993 kIpAddressVersion6Length); |
2036 strncpy(_localIP, "0000:0000:0000:0000:0000:0000:0000:0000", | 1994 } |
2037 kIpAddressVersion6Length); | 1995 _localPortRTCP = _destPortRTCP; |
2038 } | |
2039 _localPortRTCP = _destPortRTCP; | |
2040 | 1996 |
2041 ErrorCode retVal = BindLocalRTCPSocket(); | 1997 ErrorCode retVal = BindLocalRTCPSocket(); |
2042 if(retVal != kNoSocketError) | 1998 if (retVal != kNoSocketError) { |
2043 { | 1999 _lastError = retVal; |
2044 _lastError = retVal; | 2000 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, |
2045 WEBRTC_TRACE(kTraceError, kTraceTransport, _id, | 2001 "SendRtcp() failed to bind RTCP socket"); |
2046 "SendRtcp() failed to bind RTCP socket"); | 2002 CloseReceiveSockets(); |
2047 CloseReceiveSockets(); | 2003 return false; |
2048 return false; | 2004 } |
2049 } | |
2050 } | 2005 } |
2051 | 2006 |
2052 if(_ptrSendRtcpSocket) | 2007 if(_ptrSendRtcpSocket) |
2053 { | 2008 { |
2054 return _ptrSendRtcpSocket->SendTo((const int8_t*)data, length, | 2009 return _ptrSendRtcpSocket->SendTo((const int8_t*)data, length, |
2055 _remoteRTCPAddr) >= 0; | 2010 _remoteRTCPAddr) >= 0; |
2056 } else if(_ptrRtcpSocket) | 2011 } else if(_ptrRtcpSocket) |
2057 { | 2012 { |
2058 return _ptrRtcpSocket->SendTo((const int8_t*)data, length, | 2013 return _ptrRtcpSocket->SendTo((const int8_t*)data, length, |
2059 _remoteRTCPAddr) >= 0; | 2014 _remoteRTCPAddr) >= 0; |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2278 return false; | 2233 return false; |
2279 } | 2234 } |
2280 return true; | 2235 return true; |
2281 } | 2236 } |
2282 | 2237 |
2283 void UdpTransportImpl::CloseReceiveSockets() | 2238 void UdpTransportImpl::CloseReceiveSockets() |
2284 { | 2239 { |
2285 if(_ptrRtpSocket) | 2240 if(_ptrRtpSocket) |
2286 { | 2241 { |
2287 _ptrRtpSocket->CloseBlocking(); | 2242 _ptrRtpSocket->CloseBlocking(); |
2288 _ptrRtpSocket = NULL; | 2243 _ptrRtpSocket = nullptr; |
2289 } | 2244 } |
2290 if(_ptrRtcpSocket) | 2245 if(_ptrRtcpSocket) |
2291 { | 2246 { |
2292 _ptrRtcpSocket->CloseBlocking(); | 2247 _ptrRtcpSocket->CloseBlocking(); |
2293 _ptrRtcpSocket = NULL; | 2248 _ptrRtcpSocket = nullptr; |
2294 } | 2249 } |
2295 _receiving = false; | 2250 _receiving = false; |
2296 } | 2251 } |
2297 | 2252 |
2298 void UdpTransportImpl::CloseSendSockets() | 2253 void UdpTransportImpl::CloseSendSockets() |
2299 { | 2254 { |
2300 if(_ptrSendRtpSocket) | 2255 if(_ptrSendRtpSocket) |
2301 { | 2256 { |
2302 _ptrSendRtpSocket->CloseBlocking(); | 2257 _ptrSendRtpSocket->CloseBlocking(); |
2303 _ptrSendRtpSocket = 0; | 2258 _ptrSendRtpSocket = 0; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2374 } | 2329 } |
2375 #else | 2330 #else |
2376 return -1; | 2331 return -1; |
2377 #endif | 2332 #endif |
2378 } | 2333 } |
2379 | 2334 |
2380 int32_t UdpTransport::LocalHostAddressIPV6(char n_localIP[16]) | 2335 int32_t UdpTransport::LocalHostAddressIPV6(char n_localIP[16]) |
2381 { | 2336 { |
2382 | 2337 |
2383 #if defined(_WIN32) | 2338 #if defined(_WIN32) |
2384 struct addrinfo *result = NULL; | 2339 struct addrinfo* result = nullptr; |
2385 struct addrinfo *ptr = NULL; | 2340 struct addrinfo* ptr = nullptr; |
2386 struct addrinfo hints; | 2341 struct addrinfo hints; |
2387 | 2342 |
2388 ZeroMemory(&hints, sizeof(hints)); | 2343 ZeroMemory(&hints, sizeof(hints)); |
2389 hints.ai_family = AF_INET6; | 2344 hints.ai_family = AF_INET6; |
2390 | 2345 |
2391 char szHostName[256] = ""; | 2346 char szHostName[256] = ""; |
2392 if(::gethostname(szHostName, sizeof(szHostName) - 1)) | 2347 if (::gethostname(szHostName, sizeof(szHostName) - 1)) { |
2393 { | 2348 WEBRTC_TRACE(kTraceWarning, kTraceTransport, -1, "gethostname failed"); |
2394 WEBRTC_TRACE(kTraceWarning, kTraceTransport, -1, "gethostname failed"); | 2349 return -1; |
2395 return -1; | |
2396 } | 2350 } |
2397 | 2351 |
2398 DWORD dwRetval = getaddrinfo(szHostName, NULL, &hints, &result); | 2352 DWORD dwRetval = getaddrinfo(szHostName, nullptr, &hints, &result); |
2399 if ( dwRetval != 0 ) | 2353 if ( dwRetval != 0 ) |
2400 { | 2354 { |
2401 WEBRTC_TRACE(kTraceWarning, kTraceTransport, -1, | 2355 WEBRTC_TRACE(kTraceWarning, kTraceTransport, -1, |
2402 "getaddrinfo failed, error:%d", dwRetval); | 2356 "getaddrinfo failed, error:%d", dwRetval); |
2403 return -1; | 2357 return -1; |
2404 } | 2358 } |
2405 for(ptr=result; ptr != NULL ;ptr=ptr->ai_next) | 2359 for (ptr = result; ptr != nullptr; ptr = ptr->ai_next) { |
2406 { | 2360 switch (ptr->ai_family) { |
2407 switch (ptr->ai_family) | 2361 case AF_INET6: { |
2408 { | 2362 for (int i = 0; i < 16; i++) { |
2409 case AF_INET6: | 2363 n_localIP[i] = |
2410 { | 2364 (*(SocketAddress*)ptr->ai_addr) |
2411 for(int i = 0; i< 16; i++) | 2365 ._sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u8[i]; |
2412 { | 2366 } |
2413 n_localIP[i] = (*(SocketAddress*)ptr->ai_addr). | 2367 bool islocalIP = true; |
2414 _sockaddr_in6.sin6_addr.Version6AddressUnion._s6_u8[
i]; | |
2415 } | |
2416 bool islocalIP = true; | |
2417 | 2368 |
2418 for(int n = 0; n< 15; n++) | 2369 for (int n = 0; n < 15; n++) { |
2419 { | 2370 if (n_localIP[n] != 0) { |
2420 if(n_localIP[n] != 0) | 2371 islocalIP = false; |
2421 { | 2372 break; |
2422 islocalIP = false; | 2373 } |
2423 break; | 2374 } |
2424 } | |
2425 } | |
2426 | 2375 |
2427 if(islocalIP && n_localIP[15] != 1) | 2376 if (islocalIP && n_localIP[15] != 1) { |
2428 { | 2377 islocalIP = false; |
2429 islocalIP = false; | 2378 } |
2430 } | |
2431 | 2379 |
2432 if(islocalIP && ptr->ai_next) | 2380 if (islocalIP && ptr->ai_next) { |
2433 { | 2381 continue; |
2434 continue; | 2382 } |
2435 } | 2383 if (n_localIP[0] == 0xfe && n_localIP[1] == 0x80 && ptr->ai_next) { |
2436 if(n_localIP[0] == 0xfe && | 2384 continue; |
2437 n_localIP[1] == 0x80 && ptr->ai_next) | 2385 } |
2438 { | 2386 freeaddrinfo(result); |
2439 continue; | 2387 } |
2440 } | 2388 return 0; |
2441 freeaddrinfo(result); | 2389 default: |
2442 } | 2390 break; |
2443 return 0; | 2391 }; |
2444 default: | |
2445 break; | |
2446 }; | |
2447 } | 2392 } |
2448 freeaddrinfo(result); | 2393 freeaddrinfo(result); |
2449 WEBRTC_TRACE(kTraceWarning, kTraceTransport, -1, | 2394 WEBRTC_TRACE(kTraceWarning, kTraceTransport, -1, |
2450 "getaddrinfo failed to find address"); | 2395 "getaddrinfo failed to find address"); |
2451 return -1; | 2396 return -1; |
2452 | 2397 |
2453 #elif defined(WEBRTC_MAC) | 2398 #elif defined(WEBRTC_MAC) |
2454 struct ifaddrs* ptrIfAddrs = NULL; | 2399 struct ifaddrs* ptrIfAddrs = nullptr; |
2455 struct ifaddrs* ptrIfAddrsStart = NULL; | 2400 struct ifaddrs* ptrIfAddrsStart = nullptr; |
2456 | 2401 |
2457 getifaddrs(&ptrIfAddrsStart); | 2402 getifaddrs(&ptrIfAddrsStart); |
2458 ptrIfAddrs = ptrIfAddrsStart; | 2403 ptrIfAddrs = ptrIfAddrsStart; |
2459 while(ptrIfAddrs) | 2404 while (ptrIfAddrs) { |
2460 { | 2405 if (ptrIfAddrs->ifa_addr->sa_family == AF_INET6) { |
2461 if(ptrIfAddrs->ifa_addr->sa_family == AF_INET6) | 2406 const struct sockaddr_in6* sock_in6 = |
2462 { | 2407 reinterpret_cast<struct sockaddr_in6*>(ptrIfAddrs->ifa_addr); |
2463 const struct sockaddr_in6* sock_in6 = | 2408 const struct in6_addr* sin6_addr = &sock_in6->sin6_addr; |
2464 reinterpret_cast<struct sockaddr_in6*>(ptrIfAddrs->ifa_addr); | |
2465 const struct in6_addr* sin6_addr = &sock_in6->sin6_addr; | |
2466 | 2409 |
2467 if (IN6_IS_ADDR_LOOPBACK(sin6_addr) || | 2410 if (IN6_IS_ADDR_LOOPBACK(sin6_addr) || IN6_IS_ADDR_LINKLOCAL(sin6_addr)) { |
2468 IN6_IS_ADDR_LINKLOCAL(sin6_addr)) { | |
2469 ptrIfAddrs = ptrIfAddrs->ifa_next; | |
2470 continue; | |
2471 } | |
2472 memcpy(n_localIP, sin6_addr->s6_addr, sizeof(sin6_addr->s6_addr)); | |
2473 freeifaddrs(ptrIfAddrsStart); | |
2474 return 0; | |
2475 } | |
2476 ptrIfAddrs = ptrIfAddrs->ifa_next; | 2411 ptrIfAddrs = ptrIfAddrs->ifa_next; |
| 2412 continue; |
| 2413 } |
| 2414 memcpy(n_localIP, sin6_addr->s6_addr, sizeof(sin6_addr->s6_addr)); |
| 2415 freeifaddrs(ptrIfAddrsStart); |
| 2416 return 0; |
| 2417 } |
| 2418 ptrIfAddrs = ptrIfAddrs->ifa_next; |
2477 } | 2419 } |
2478 freeifaddrs(ptrIfAddrsStart); | 2420 freeifaddrs(ptrIfAddrsStart); |
2479 return -1; | 2421 return -1; |
2480 #elif defined(WEBRTC_ANDROID) | 2422 #elif defined(WEBRTC_ANDROID) |
2481 return -1; | 2423 return -1; |
2482 #else // WEBRTC_LINUX | 2424 #else // WEBRTC_LINUX |
2483 struct | 2425 struct |
2484 { | 2426 { |
2485 struct nlmsghdr n; | 2427 struct nlmsghdr n; |
2486 struct ifaddrmsg r; | 2428 struct ifaddrmsg r; |
2487 } req; | 2429 } req; |
2488 | 2430 |
2489 struct rtattr* rta = NULL; | 2431 struct rtattr* rta = nullptr; |
2490 int status; | 2432 int status; |
2491 char buf[16384]; // = 16 * 1024 (16 kB) | 2433 char buf[16384]; // = 16 * 1024 (16 kB) |
2492 struct nlmsghdr* nlmp; | 2434 struct nlmsghdr* nlmp; |
2493 struct ifaddrmsg* rtmp; | 2435 struct ifaddrmsg* rtmp; |
2494 struct rtattr* rtatp; | 2436 struct rtattr* rtatp; |
2495 int rtattrlen; | 2437 int rtattrlen; |
2496 struct in6_addr* in6p; | 2438 struct in6_addr* in6p; |
2497 | 2439 |
2498 int fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); | 2440 int fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); |
2499 if (fd == -1) | 2441 if (fd == -1) |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2668 #else // WEBRTC_LINUX | 2610 #else // WEBRTC_LINUX |
2669 int sockfd, size = 1; | 2611 int sockfd, size = 1; |
2670 struct ifreq* ifr; | 2612 struct ifreq* ifr; |
2671 struct ifconf ifc; | 2613 struct ifconf ifc; |
2672 | 2614 |
2673 if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) | 2615 if (0 > (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP))) |
2674 { | 2616 { |
2675 return -1; | 2617 return -1; |
2676 } | 2618 } |
2677 ifc.ifc_len = IFRSIZE; | 2619 ifc.ifc_len = IFRSIZE; |
2678 ifc.ifc_req = NULL; | 2620 ifc.ifc_req = nullptr; |
2679 do | 2621 do |
2680 { | 2622 { |
2681 ++size; | 2623 ++size; |
2682 // Buffer size needed is unknown. Try increasing it until no overflow | 2624 // Buffer size needed is unknown. Try increasing it until no overflow |
2683 // occurs. | 2625 // occurs. |
2684 if (NULL == (ifc.ifc_req = (ifreq*)realloc(ifc.ifc_req, IFRSIZE))) { | 2626 if (nullptr == (ifc.ifc_req = (ifreq*)realloc(ifc.ifc_req, IFRSIZE))) { |
2685 fprintf(stderr, "Out of memory.\n"); | 2627 fprintf(stderr, "Out of memory.\n"); |
2686 exit(EXIT_FAILURE); | 2628 exit(EXIT_FAILURE); |
2687 } | 2629 } |
2688 ifc.ifc_len = IFRSIZE; | 2630 ifc.ifc_len = IFRSIZE; |
2689 if (ioctl(sockfd, SIOCGIFCONF, &ifc)) | 2631 if (ioctl(sockfd, SIOCGIFCONF, &ifc)) |
2690 { | 2632 { |
2691 free(ifc.ifc_req); | 2633 free(ifc.ifc_req); |
2692 close(sockfd); | 2634 close(sockfd); |
2693 return -1; | 2635 return -1; |
2694 } | 2636 } |
(...skipping 30 matching lines...) Expand all Loading... |
2725 #endif | 2667 #endif |
2726 } | 2668 } |
2727 | 2669 |
2728 int32_t UdpTransport::IPAddress(const SocketAddress& address, | 2670 int32_t UdpTransport::IPAddress(const SocketAddress& address, |
2729 char* ip, | 2671 char* ip, |
2730 uint32_t& ipSize, | 2672 uint32_t& ipSize, |
2731 uint16_t& sourcePort) | 2673 uint16_t& sourcePort) |
2732 { | 2674 { |
2733 #if defined(_WIN32) | 2675 #if defined(_WIN32) |
2734 DWORD dwIPSize = ipSize; | 2676 DWORD dwIPSize = ipSize; |
2735 int32_t returnvalue = WSAAddressToStringA((LPSOCKADDR)(&address), | 2677 int32_t returnvalue = WSAAddressToStringA( |
2736 sizeof(SocketAddress), | 2678 (LPSOCKADDR)(&address), sizeof(SocketAddress), nullptr, ip, &dwIPSize); |
2737 NULL, | |
2738 ip, | |
2739 &dwIPSize); | |
2740 if(returnvalue == -1) | 2679 if(returnvalue == -1) |
2741 { | 2680 { |
2742 return -1; | 2681 return -1; |
2743 } | 2682 } |
2744 | 2683 |
2745 uint16_t source_port = 0; | 2684 uint16_t source_port = 0; |
2746 if(address._sockaddr_storage.sin_family == AF_INET) | 2685 if(address._sockaddr_storage.sin_family == AF_INET) |
2747 { | 2686 { |
2748 // Parse IP assuming format "a.b.c.d:port". | 2687 // Parse IP assuming format "a.b.c.d:port". |
2749 char* ipEnd = strchr(ip,':'); | 2688 char* ipEnd = strchr(ip,':'); |
2750 if(ipEnd != NULL) | 2689 if (ipEnd != nullptr) { |
2751 { | 2690 *ipEnd = '\0'; |
2752 *ipEnd = '\0'; | |
2753 } | 2691 } |
2754 ipSize = (int32_t)strlen(ip); | 2692 ipSize = (int32_t)strlen(ip); |
2755 if(ipSize == 0) | 2693 if(ipSize == 0) |
2756 { | 2694 { |
2757 return -1; | 2695 return -1; |
2758 } | 2696 } |
2759 source_port = address._sockaddr_in.sin_port; | 2697 source_port = address._sockaddr_in.sin_port; |
2760 } | 2698 } |
2761 else | 2699 else |
2762 { | 2700 { |
2763 // Parse IP assuming format "[address]:port". | 2701 // Parse IP assuming format "[address]:port". |
2764 char* ipEnd = strchr(ip,']'); | 2702 char* ipEnd = strchr(ip,']'); |
2765 if(ipEnd != NULL) | 2703 if (ipEnd != nullptr) { |
2766 { | |
2767 // Calculate length | 2704 // Calculate length |
2768 int32_t adrSize = int32_t(ipEnd - ip) - 1; | 2705 int32_t adrSize = int32_t(ipEnd - ip) - 1; |
2769 memmove(ip, &ip[1], adrSize); // Remove '[' | 2706 memmove(ip, &ip[1], adrSize); // Remove '[' |
2770 *(ipEnd - 1) = '\0'; | 2707 *(ipEnd - 1) = '\0'; |
2771 } | 2708 } |
2772 ipSize = (int32_t)strlen(ip); | 2709 ipSize = (int32_t)strlen(ip); |
2773 if(ipSize == 0) | 2710 if(ipSize == 0) |
2774 { | 2711 { |
2775 return -1; | 2712 return -1; |
2776 } | 2713 } |
2777 | 2714 |
2778 source_port = address._sockaddr_in6.sin6_port; | 2715 source_port = address._sockaddr_in6.sin6_port; |
2779 } | 2716 } |
2780 // Convert port number to network byte order. | 2717 // Convert port number to network byte order. |
2781 sourcePort = htons(source_port); | 2718 sourcePort = htons(source_port); |
2782 return 0; | 2719 return 0; |
2783 | 2720 |
2784 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) | 2721 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_MAC) |
2785 int32_t ipFamily = address._sockaddr_storage.sin_family; | 2722 int32_t ipFamily = address._sockaddr_storage.sin_family; |
2786 const void* ptrNumericIP = NULL; | 2723 const void* ptrNumericIP = nullptr; |
2787 | 2724 |
2788 if(ipFamily == AF_INET) | 2725 if(ipFamily == AF_INET) |
2789 { | 2726 { |
2790 ptrNumericIP = &(address._sockaddr_in.sin_addr); | 2727 ptrNumericIP = &(address._sockaddr_in.sin_addr); |
2791 } | 2728 } |
2792 else if(ipFamily == AF_INET6) | 2729 else if(ipFamily == AF_INET6) |
2793 { | 2730 { |
2794 ptrNumericIP = &(address._sockaddr_in6.sin6_addr); | 2731 ptrNumericIP = &(address._sockaddr_in6.sin6_addr); |
2795 } | 2732 } |
2796 else | 2733 else |
2797 { | 2734 { |
2798 return -1; | 2735 return -1; |
2799 } | 2736 } |
2800 if(inet_ntop(ipFamily, ptrNumericIP, ip, ipSize) == NULL) | 2737 if (inet_ntop(ipFamily, ptrNumericIP, ip, ipSize) == nullptr) { |
2801 { | 2738 return -1; |
2802 return -1; | |
2803 } | 2739 } |
2804 uint16_t source_port; | 2740 uint16_t source_port; |
2805 if(ipFamily == AF_INET) | 2741 if(ipFamily == AF_INET) |
2806 { | 2742 { |
2807 source_port = address._sockaddr_in.sin_port; | 2743 source_port = address._sockaddr_in.sin_port; |
2808 } else | 2744 } else |
2809 { | 2745 { |
2810 source_port = address._sockaddr_in6.sin6_port; | 2746 source_port = address._sockaddr_in6.sin6_port; |
2811 } | 2747 } |
2812 // Convert port number to network byte order. | 2748 // Convert port number to network byte order. |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3000 if (nDots != 3 || !allUnder256) | 2936 if (nDots != 3 || !allUnder256) |
3001 { | 2937 { |
3002 return false; | 2938 return false; |
3003 } | 2939 } |
3004 } | 2940 } |
3005 return true; | 2941 return true; |
3006 } | 2942 } |
3007 | 2943 |
3008 } // namespace test | 2944 } // namespace test |
3009 } // namespace webrtc | 2945 } // namespace webrtc |
OLD | NEW |