From 62641f426bc95c247d18dc0e54ec4cedc5dbd6c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=80=81=E8=A1=B2=E4=B8=8D=E5=87=BA=E5=AE=B6?= Date: Wed, 24 Jan 2024 15:14:23 +0800 Subject: [PATCH] Fix a bug in WebRTC where the DTLS certificate is too large(big than MTU) (#3250) --- webrtc/WebRtcTransport.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 7fc8816e..d338a9d7 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -201,9 +201,26 @@ void WebRtcTransport::OnDtlsTransportConnected( onStartWebRTC(); } +#pragma pack(push, 1) +struct DtlsHeader { + uint8_t content_type; + uint16_t dtls_version; + uint16_t epoch; + uint8_t seq[6]; + uint16_t length; + uint8_t payload[1]; +}; +#pragma pack(pop) + void WebRtcTransport::OnDtlsTransportSendData( const RTC::DtlsTransport *dtlsTransport, const uint8_t *data, size_t len) { - sendSockData((char *)data, len, nullptr); + size_t offset = 0; + while(offset < len) { + auto *header = reinterpret_cast(data + offset); + auto length = ntohs(header->length) + offsetof(DtlsHeader, payload); + sendSockData((char *)data + offset, length, nullptr); + offset += length; + } } void WebRtcTransport::OnDtlsTransportConnecting(const RTC::DtlsTransport *dtlsTransport) {