From b9880cb8003c2c257f7d31983e9ce125492eb3ae Mon Sep 17 00:00:00 2001 From: pokgak <m.aimanismail@gmail.com> Date: Mon, 6 Aug 2018 11:03:27 +0200 Subject: [PATCH] examples/gcoap: fix post/put without port number --- examples/gcoap/gcoap_cli.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/gcoap/gcoap_cli.c b/examples/gcoap/gcoap_cli.c index f1a2f6fb71..8cb823b8ac 100644 --- a/examples/gcoap/gcoap_cli.c +++ b/examples/gcoap/gcoap_cli.c @@ -233,7 +233,13 @@ int gcoap_cli_cmd(int argc, char **argv) apos++; } - if (argc == apos + 3 || argc == apos + 4) { + /* + * "get" (code_pos 0) must have exactly apos + 3 arguments + * while "post" (code_pos 1) and "put" (code_pos 2) and must have exactly + * apos + 4 arguments + */ + if (((argc == apos + 3) && (code_pos == 0)) || + ((argc == apos + 4) && (code_pos != 0))) { gcoap_req_init(&pdu, &buf[0], GCOAP_PDU_BUF_SIZE, code_pos+1, argv[apos+2]); if (argc == apos + 4) { memcpy(pdu.payload, argv[apos+3], strlen(argv[apos+3])); -- GitLab