From 75acc0d03fa6c265f53dcb8f9eb6cab28d41d85e Mon Sep 17 00:00:00 2001 From: Markus Becker Date: Tue, 5 Feb 2013 14:56:39 +0100 Subject: [PATCH 1/2] Add token length to output of coap_show_pdu(). --- debug.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debug.c b/debug.c index 15bdda72..30d421bb 100644 --- a/debug.c +++ b/debug.c @@ -232,8 +232,9 @@ coap_show_pdu(const coap_pdu_t *pdu) { coap_opt_iterator_t opt_iter; coap_opt_t *option; - fprintf(COAP_DEBUG_FD, "v:%d t:%d c:%d id:%u", + fprintf(COAP_DEBUG_FD, "v:%d t:%d tkl:%d c:%d id:%u", pdu->hdr->version, pdu->hdr->type, + pdu->hdr->token_length, pdu->hdr->code, ntohs(pdu->hdr->id)); /* show options, if any */ From 5415743c300cb6d5424d7a5930ba8a6b033322d3 Mon Sep 17 00:00:00 2001 From: Markus Becker Date: Tue, 5 Feb 2013 14:57:12 +0100 Subject: [PATCH 2/2] Add token to request in example client. --- examples/client.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/client.c b/examples/client.c index f3580f37..06acf285 100644 --- a/examples/client.c +++ b/examples/client.c @@ -139,6 +139,13 @@ coap_new_request(coap_context_t *ctx, method_t m, coap_list_t *options ) { pdu->hdr->id = coap_new_message_id(ctx); pdu->hdr->code = m; + pdu->hdr->token_length = the_token.length; + if ( !coap_add_token(pdu, the_token.length, the_token.s)) { + debug("cannot add token to request\n"); + } + + coap_show_pdu(pdu); + for (opt = options; opt; opt = opt->next) { coap_add_option(pdu, COAP_OPTION_KEY(*(coap_option *)opt->data), COAP_OPTION_LENGTH(*(coap_option *)opt->data), @@ -759,8 +766,8 @@ cmdline_proxy(char *arg) { inline void cmdline_token(char *arg) { - strncpy((char *)the_token.s, arg, min(sizeof(_token_data), strlen(arg))); + the_token.length = strlen(arg); } void