20 #include <freerdp/config.h>
26 #include <winpr/wlog.h>
28 #define TAG FREERDP_TAG("core.tpkt")
70 int tpkt_verify_header(
wStream* s)
74 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
77 Stream_Peek_UINT8(s, version);
94 BOOL tpkt_read_header(
wStream* s, UINT16* length)
98 if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
101 Stream_Peek_UINT8(s, version);
106 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
110 Stream_Read_UINT16_BE(s, len);
115 WLog_ERR(TAG,
"TPKT header too short, require minimum of 7 bytes, got %" PRId16, len);
119 if (!Stream_CheckAndLogRequiredLength(TAG, s, len - 4))
121 WLog_ERR(TAG,
"TPKT header length %" PRIu16
", but received less", len);
135 BOOL tpkt_ensure_stream_consumed_(
wStream* s,
size_t length,
const char* fkt)
137 if (length > UINT16_MAX)
139 WLog_ERR(TAG,
"[%s] length %" PRIuz
" > %" PRIu16, fkt, length, UINT16_MAX);
143 size_t rem = Stream_GetRemainingLength(s);
147 "[%s] Received invalid TPKT header length %" PRIu16
", %" PRIdz
" bytes too long!",
163 BOOL tpkt_write_header(
wStream* s,
size_t length)
165 if (!Stream_CheckAndLogRequiredCapacity(TAG, (s), 4))
167 Stream_Write_UINT8(s, 3);
168 Stream_Write_UINT8(s, 0);
170 WINPR_ASSERT(length <= UINT16_MAX);
171 Stream_Write_UINT16_BE(s, (UINT16)length);