-1

I need your help in extracting the query value in a coap message.The coap message looks like

coap://[ff08:90:5001:0:0:0:0:1]:12345/c?a=4 

decoded packet is 52 02 00 00 91 63 63 61 3d 34 . Here 63 61 3d 34 is the query part ?a=4 . There is a data after query. I have pointed my buffer pointer to 63(?), now I'm struck in getting the value 34(4). How do I go to the value and extract it?

coap_h *hdr = (coap_h *)(buf);

buf = (uint8_t *)(hdr + 1);
len = buf[0] & 0xf;
buf += len + 1;

buf points to 52 initially and then I move the buf to the options field 91 and check for length then increment the buf which points to 63 (?). hope i'm clear this time.

James
  • 24,676
  • 13
  • 84
  • 130
foo_l
  • 591
  • 2
  • 10
  • 28

1 Answers1

2

I don't have the time at the moment to parse your packet by hand, but you should know that the way options work has changed dramatically in CoAP-12. I have implemented some functions to encode and parse options, which you might find useful:

https://github.com/darconeous/smcp/blob/master/src/smcp/coap.c

https://github.com/darconeous/smcp/blob/master/src/smcp/coap.h

andrewsi
  • 10,807
  • 132
  • 35
  • 51