From fc18a4992b45cf70e0d78e9f79e4bd0dea976785 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 16 Jan 2015 08:44:12 +0100 Subject: [PATCH] lwip: implement coap_packet_copy_source --- coap_io.h | 1 + coap_io_lwip.c | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/coap_io.h b/coap_io.h index 175a3876..04294baa 100644 --- a/coap_io.h +++ b/coap_io.h @@ -132,6 +132,7 @@ void coap_packet_get_memmapped(coap_packet_t *packet, unsigned char **address, s struct coap_packet_t { struct pbuf *pbuf; const coap_endpoint_t *local_interface; + uint16_t srcport; }; #endif diff --git a/coap_io_lwip.c b/coap_io_lwip.c index fa894d76..73aa02ab 100644 --- a/coap_io_lwip.c +++ b/coap_io_lwip.c @@ -11,20 +11,20 @@ #include "mem.h" #include "coap_io.h" -void coap_packet_populate_endpoint(coap_packet_t *incoming, coap_endpoint_t *target) +void coap_packet_populate_endpoint(coap_packet_t *packet, coap_endpoint_t *target) { printf("FIXME no endpoint populated\n"); } -void coap_packet_copy_source(coap_packet_t *incoming, coap_address_t *target) +void coap_packet_copy_source(coap_packet_t *packet, coap_address_t *target) { - /** @FIXME types wtf */ - memcpy(target, ip_current_src_addr(), sizeof(coap_address_t)); + target->port = packet->srcport; + memcpy(&target->addr, ip_current_src_addr(), sizeof(ip_addr_t)); } -void coap_packet_get_memmapped(coap_packet_t *incoming, unsigned char **address, size_t *length) +void coap_packet_get_memmapped(coap_packet_t *packet, unsigned char **address, size_t *length) { - LWIP_ASSERT("Can only deal with contiguous PBUFs to read the initial details", incoming->pbuf->tot_len == incoming->pbuf->len); - *address = incoming->pbuf->payload; - *length = incoming->pbuf->tot_len; + LWIP_ASSERT("Can only deal with contiguous PBUFs to read the initial details", packet->pbuf->tot_len == packet->pbuf->len); + *address = packet->pbuf->payload; + *length = packet->pbuf->tot_len; } void coap_free_packet(coap_packet_t *packet) { @@ -47,6 +47,7 @@ static void coap_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p, ip_addr_t /* this is fatal because due to the short life of the packet, never should there be more than one coap_packet_t required */ LWIP_ASSERT("Insufficient coap_packet_t resources.", packet != NULL); packet->pbuf = p; + packet->srcport = port; /** FIXME derive the context without changing endopint definition */ coap_handle_message(ep->context, packet);