X-Git-Url: http://git.silcnet.org/gitweb/?p=silc.git;a=blobdiff_plain;f=lib%2Fsilccore%2Fsilcpacket.h;h=b2c9dd2790dc0b121ffc10c5f3919e452aa3dd01;hp=3583e473927e5a952819b8422e0aa2ebad5bde23;hb=382d15d447b7a95390decfa783836ae4fe255b3d;hpb=4fb6f761690a7adcd4f9f0c101dc73cbe334fca3 diff --git a/lib/silccore/silcpacket.h b/lib/silccore/silcpacket.h index 3583e473..b2c9dd27 100644 --- a/lib/silccore/silcpacket.h +++ b/lib/silccore/silcpacket.h @@ -332,10 +332,10 @@ typedef bool (*SilcPacketParserCallback)(SilcPacketParserContext * * SOURCE */ -#define SILC_PACKET_LENGTH(__packet, __ret_truelen, __ret_paddedlen) \ -do { \ - SILC_GET16_MSB((__ret_truelen), (__packet)->data); \ - (__ret_paddedlen) = (__ret_truelen) + (__packet)->data[4]; \ +#define SILC_PACKET_LENGTH(__packetdata, __ret_truelen, __ret_paddedlen) \ +do { \ + SILC_GET16_MSB((__ret_truelen), (__packetdata)); \ + (__ret_paddedlen) = (__ret_truelen) + (SilcUInt8)(__packetdata)[4]; \ } while(0) /***/ @@ -370,14 +370,18 @@ do { \ * * DESCRIPTION * - * Returns the length of the padding in the packet. This is used + * Calculates the length of the padding in the packet. This is used * by various library routines to determine needed padding length. * * SOURCE */ -#define SILC_PACKET_PADLEN(__packetlen, __blocklen) \ - SILC_PACKET_DEFAULT_PADLEN - (__packetlen) % \ - ((__blocklen) ? (__blocklen) : SILC_PACKET_DEFAULT_PADLEN) +#define SILC_PACKET_PADLEN(__packetlen, __blocklen, __padlen) \ +do { \ + __padlen = (SILC_PACKET_DEFAULT_PADLEN - (__packetlen) % \ + ((__blocklen) ? (__blocklen) : SILC_PACKET_DEFAULT_PADLEN)); \ + if (__padlen < 8) \ + __padlen += ((__blocklen) ? (__blocklen) : SILC_PACKET_DEFAULT_PADLEN); \ +} while(0) /***/ /****d* silccore/SilcPacketAPI/SILC_PACKET_PADLEN_MAX @@ -389,13 +393,16 @@ do { \ * DESCRIPTION * * Returns the length of the padding up to the maximum length, which - * is 128 butes. This is used by various library routines to determine + * is 128 bytes. This is used by various library routines to determine * needed padding length. * * SOURCE */ -#define SILC_PACKET_PADLEN_MAX(__packetlen) \ - SILC_PACKET_MAX_PADLEN - (__packetlen) % SILC_PACKET_MAX_PADLEN +#define SILC_PACKET_PADLEN_MAX(__packetlen, __blocklen, __padlen) \ +do { \ + __padlen = (SILC_PACKET_MAX_PADLEN - (__packetlen) % \ + ((__blocklen) ? (__blocklen) : SILC_PACKET_DEFAULT_PADLEN)); \ +} while(0) /***/ /* Prototypes */