Hi Guys
I have a bunch of encoded messages that I need to process. Whilst working on this in our test environment the messages where present in file. The file was binary, and I was reading the file a bit at a time using fread, and sticking the read bytes into structs. This was working great thanks to help from Salem and ZuK : )
My problem is now that I need to process the same messages via a function but the messages are no longer in a file, they are coming into another process(a PERL program) that reads them of the network but cannot decode them. It can however pass them to a C function. My question is, where I was using fread before, what do I do now ?? If I pass them into the fucntion as a char array what then is the best way to deal with them ?? Here's my current attempt, which doesn't work :
Code:
char *decodeMsg(char *msg)
{
char messageType;
char ProtoOrVer;
uint16_t MsgLen;
sscanf(msg, "%c%c%hu", &messageType, &ProtoOrVer, &MsgLen);
printf("messageType == %c\n", messageType);
printf("ProtoOrVer == %c\n", ProtoOrVer);
printf("MsgLen == %hu\n", MsgLen);
Here's the output :
Code:
16:48:50 : 1265810793.133140 : J2t0D cEy]\ufffd\ufffd 0002900262O0NL0006445199NL0006275711
received msg : J2
messageType == J
ProtoOrVer == 2
MsgLen == 0
Now I know that the MsgLen is actually 116 and is stored in a short unsigned int but sscanf isn't storing that in the unit "MsgLen".
I'm a PERL programmer really, so sorry if this question sounds silly but I'm stuck !!
Any pointers greatlly appreciated !!