}
/* Calculate a CRC-16 for the LEN byte message pointed at by P. */
-/* Pads with ^Z if necessary */
+/* Pads with ^Z up to 128 bytes if told to */
static unsigned short
-docrc (unsigned char *p, int len)
+docrc (unsigned char *p, int len, bool pad)
{
int len2 = len;
unsigned short crc = 0;
while (len-- > 0)
crc = (crc << 8) ^ crctab[(crc >> 8) ^ *p++];
- if (len2 < 128) {
+ if (pad && len2 < 128) {
len = 128-len;
while (len-- > 0)
crc = (crc << 8) ^ crctab[(crc >> 8) ^ 0x1a];
if (crcflag) {
u16 crc;
- crc = docrc ((unsigned char*)packet, len);
+ crc = docrc ((unsigned char*)packet, len, 1);
s[0] = crc >> 8;
s[1] = crc & 0xff;