diff options
author | Vinicius Costa Gomes <vinicius.gomes@intel.com> | 2016-09-14 11:10:29 -0300 |
---|---|---|
committer | Anas Nashif <nashif@linux.intel.com> | 2016-10-01 01:11:25 +0000 |
commit | 441d22a371b08900840f4f71528149cc696321c7 (patch) | |
tree | d6510e8b403d216dac7d42c6d1a15e60a6b17fbb /samples | |
parent | 92a79f735175c862f05ff445e325ff47bd6de3b3 (diff) |
iot/zoap: Add port information to network addresses
uIP keeps the port separated from the IP addresses, so if the
application wants to communicate with a remote endpoint we must also
have the port information available.
Change-Id: I8e2b01fe5717166e1f9cebcc74b2056325b8ccc3
Signed-off-by: Vinicius Costa Gomes <vinicius.gomes@intel.com>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/net/zoap_client/src/zoap-client.c | 13 | ||||
-rw-r--r-- | samples/net/zoap_server/src/zoap-server.c | 16 |
2 files changed, 22 insertions, 7 deletions
diff --git a/samples/net/zoap_client/src/zoap-client.c b/samples/net/zoap_client/src/zoap-client.c index 0afa0b701..3858caf01 100644 --- a/samples/net/zoap_client/src/zoap-client.c +++ b/samples/net/zoap_client/src/zoap-client.c @@ -17,6 +17,7 @@ #include <errno.h> #include <stdio.h> +#include <misc/byteorder.h> #include <misc/nano_work.h> #include <net/net_core.h> #include <net/net_socket.h> @@ -58,7 +59,9 @@ static void msg_dump(const char *s, uint8_t *data, unsigned len) } static int resource_reply_cb(const struct zoap_packet *response, - struct zoap_reply *reply, const void *from) + struct zoap_reply *reply, + const uip_ipaddr_t *addr, + uint16_t port) { struct net_buf *buf = response->buf; @@ -76,6 +79,8 @@ static void udp_receive(void) int r; while (true) { + struct uip_conn *conn; + buf = net_receive(receive_context, TICKS_UNLIMITED); if (!buf) { continue; @@ -87,13 +92,17 @@ static void udp_receive(void) continue; } + conn = uip_conn(buf); + pending = zoap_pending_received(&response, pendings, NUM_PENDINGS); if (pending) { /* If necessary cancel retransmissions */ } - reply = zoap_response_received(&response, buf, + reply = zoap_response_received(&response, + &conn->ripaddr, + sys_be16_to_cpu(conn->rport), replies, NUM_REPLIES); if (!reply) { printf("No handler for response (%d)\n", r); diff --git a/samples/net/zoap_server/src/zoap-server.c b/samples/net/zoap_server/src/zoap-server.c index 034a186df..649bcd4e0 100644 --- a/samples/net/zoap_server/src/zoap-server.c +++ b/samples/net/zoap_server/src/zoap-server.c @@ -19,6 +19,7 @@ #include <zephyr.h> +#include <misc/byteorder.h> #include <net/net_core.h> #include <net/net_socket.h> #include <net/ip_buf.h> @@ -42,10 +43,10 @@ char fiberStack[STACKSIZE]; static struct net_context *context; static int test_get(struct zoap_resource *resource, - struct zoap_packet *request, - const void *from) + struct zoap_packet *request, + const uip_ipaddr_t *addr, + uint16_t port) { - struct net_context *ctx = (struct net_context *) from; struct net_buf *buf; struct zoap_packet response; uint8_t *payload, code, type; @@ -93,7 +94,7 @@ static int test_get(struct zoap_resource *resource, return -EINVAL; } - return net_reply(ctx, buf); + return net_reply(context, buf); } static const char * const test_path[] = { "test", NULL }; @@ -111,6 +112,8 @@ static void udp_receive(void) int r; while (true) { + struct uip_conn *conn; + buf = net_receive(context, TICKS_UNLIMITED); if (!buf) { continue; @@ -122,7 +125,10 @@ static void udp_receive(void) continue; } - r = zoap_handle_request(&request, resources, context); + conn = uip_conn(buf); + + r = zoap_handle_request(&request, resources, &conn->ripaddr, + sys_be16_to_cpu(conn->rport)); if (r < 0) { printf("No handler for such request (%d)\n", r); continue; |