size_t processed_bytes = 0; while (true) {
size_t bytes_left = data.size() - processed_bytes; // We need at least 4 bytes to read the STUN or ChannelData packet length. if (bytes_left < kPacketLenOffset + kPacketLenSize) return processed_bytes;
size_t AsyncStunTCPSocket::GetExpectedLength(constvoid* data,
size_t len, int* pad_bytes) {
*pad_bytes = 0;
std::span<const uint8_t> view(static_cast<const uint8_t*>(data), len);
PacketLength pkt_len = GetBE16(view.subspan(kPacketLenOffset, 2));
size_t expected_pkt_len;
uint16_t msg_type = GetBE16(view); if (IsStunMessage(msg_type)) { // STUN message.
expected_pkt_len = kStunHeaderSize + pkt_len;
} else { // TURN ChannelData message.
expected_pkt_len = kTurnChannelDataHdrSize + pkt_len; // From RFC 5766 section 11.5 // Over TCP and TLS-over-TCP, the ChannelData message MUST be padded to // a multiple of four bytes in order to ensure the alignment of // subsequent messages. The padding is not reflected in the length // field of the ChannelData message, so the actual size of a ChannelData // message (including padding) is (4 + Length) rounded up to the nearest // multiple of 4. Over UDP, the padding is not required but MAY be // included. if (expected_pkt_len % 4)
*pad_bytes = 4 - (expected_pkt_len % 4);
} return expected_pkt_len;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.