kay so this
void printPacketBuffer(void *buffer, unsigned int length)
{
unsigned int i=0;
char *c;
unsigned int limit = ( (length != 0)?length:PACKET_DATA );
for (i=0; i<limit; i++) {
c = (char *)(buffer+i);
if ( *c != '\0' ) {
printf("%c", *c);
}
}
}
is working but the following function short miss the last 14 bytes can’t understand why ?!
void printPacket (void * buffer) {
unsigned int size = getPacket_size(buffer);
printf("\n***********\nNew Packet holding %d bytes of data\n***********\n", size);
char *c;
int counter=0;
int i;
for (i=2; i<size+2; i++) {
c = (char *)(buffer+i);
if ( *c != '\0' ) {
printf("%c", *c);
counter++;
}
}
printf("\nactual printing %d, i=%d\n", counter, i);
}
and here is the calls
printPacketBuffer(pbuffer+2, getPacket_size(pbuffer));
printPacket(pbuffer);
i supposed that pbuffer+2 is the next address by two bytes but I was WRONG here’s what was happening
if bpuffer = 0x7fff2c03d8a0 the bpuffer + 2 = 0x7fff2c03d8b0
now to move to next 2 bytes location I used
anyway the morale of the story is to work with bytes cast to unsigned char