X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilccore%2Fsilcprivate.c;h=ac99257f21595ee14a737d7fb8be608a9c1e6d84;hb=c41b6607947087a49fec26756966dad8e1f39508;hp=6136dc75349eb720bae50ac568731c558616adfc;hpb=c12a20d93d116b0648e4fcfe28da32a730011883;p=silc.git diff --git a/lib/silccore/silcprivate.c b/lib/silccore/silcprivate.c index 6136dc75..ac99257f 100644 --- a/lib/silccore/silcprivate.c +++ b/lib/silccore/silcprivate.c @@ -29,8 +29,19 @@ ******************************************************************************/ +/* Calculates padding length for message payload */ #define SILC_PRIVATE_MESSAGE_PAD(__payloadlen) (16 - (__payloadlen) % 16) +/* Header length plus maximum padding length */ +#define SILC_PRIVATE_MESSAGE_HLEN 4 + 16 + +/* Returns the data length that fits to the packet. If data length is too + big it will be truncated to fit to the payload. */ +#define SILC_PRIVATE_MESSAGE_DATALEN(data_len) \ + ((data_len + SILC_PRIVATE_MESSAGE_HLEN) > SILC_PACKET_MAX_LEN ? \ + data_len - ((data_len + SILC_PRIVATE_MESSAGE_HLEN) - \ + SILC_PACKET_MAX_LEN) : data_len) + /* Private Message Payload structure. Contents of this structure is parsed from SILC packets. */ struct SilcPrivateMessagePayloadStruct { @@ -105,6 +116,7 @@ SilcBuffer silc_private_message_payload_encode(SilcUInt16 flags, SILC_LOG_DEBUG(("Encoding private message payload")); + data_len = SILC_PRIVATE_MESSAGE_DATALEN(data_len); len = 4 + data_len; if (cipher) {