diff --git a/components/coap/port/coap_io_socket.c b/components/coap/port/coap_io_socket.c index eec8cc1..cd63f38 100644 --- a/components/coap/port/coap_io_socket.c +++ b/components/coap/port/coap_io_socket.c @@ -251,7 +251,7 @@ coap_network_send(struct coap_context_t *context UNUSED_PARAM, (struct coap_endpoint_t *)local_interface; #ifndef WITH_CONTIKI - return sendto(ep->handle.fd, data, datalen, 0, (struct sockaddr*)&dst->addr.sa, sizeof(struct sockaddr)); + return sendto(ep->handle.fd, data, datalen, 0, &dst->addr.sa, dst->size); #else /* WITH_CONTIKI */ /* FIXME: untested */ /* FIXME: is there a way to check if send was successful? */ @@ -340,8 +340,6 @@ coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet) { #ifdef WITH_POSIX #define SOC_APPDATA_LEN 1460 char *soc_appdata = NULL; - struct sockaddr_in soc_srcipaddr; - socklen_t soc_srcsize = sizeof(struct sockaddr_in); #endif /* WITH_POSIX */ assert(ep); @@ -360,23 +358,14 @@ coap_network_read(coap_endpoint_t *ep, coap_packet_t **packet) { #ifdef WITH_POSIX soc_appdata = coap_malloc(SOC_APPDATA_LEN); if (soc_appdata){ - len = recvfrom(ep->handle.fd, soc_appdata, SOC_APPDATA_LEN, 0, (struct sockaddr *)&soc_srcipaddr, (socklen_t *)&soc_srcsize); + (*packet)->src.size = sizeof((*packet)->src.addr); + len = recvfrom(ep->handle.fd, soc_appdata, SOC_APPDATA_LEN, 0, + &(*packet)->src.addr.sa, &(*packet)->src.size); if (len < 0){ coap_log(LOG_WARNING, "coap_network_read: %s\n", strerror(errno)); goto error; } else { - /* use getsockname() to get the local port */ - (*packet)->dst.size = sizeof((*packet)->dst.addr); - if (getsockname(ep->handle.fd, &(*packet)->dst.addr.sa, &(*packet)->dst.size) < 0) { - coap_log(LOG_DEBUG, "cannot determine local port\n"); - goto error; - } - - /* local interface for IPv4 */ - (*packet)->src.size = sizeof((*packet)->src.addr); - memcpy(&(*packet)->src.addr.sa, &soc_srcipaddr, (*packet)->src.size); - if (len > coap_get_max_packetlength(*packet)) { /* FIXME: we might want to send back a response */ warn("discarded oversized packet\n");