I\'m new on C programming and I\'m testing some code where I receive and process an UDP packet formatted as follow:
UINT16 port1
UINT16 port2
You declared primaryPort
and secondaryPort
to be pointers to unsigned short
.
But when you assign them values from a section of buffer, you already de-referenced the pointer. You don't need pointers-to-unsigned-short
. You just need an unsigned short
.
Change it to:
unsigned short primaryPort = *((unsigned short*) &buffer[l]);
unsigned short secondaryPort = *((unsigned short *) &buffer[l]);
Note the removal of a *
in the variable declarations.
If you're still having problems, you'll need to examine buffer
byte-by-byte, looking for the value you expect. You can expect that 6005
will show up as either hex 17 75
or 75 17
, depending on your platform's endianness.