net/gcoap: use sock_udp_ep_equal()
This commit is contained in:
parent
8d1d509af9
commit
f2b1c5c87d
@ -733,6 +733,7 @@ endif
|
|||||||
ifneq (,$(filter gcoap,$(USEMODULE)))
|
ifneq (,$(filter gcoap,$(USEMODULE)))
|
||||||
USEMODULE += nanocoap
|
USEMODULE += nanocoap
|
||||||
USEMODULE += gnrc_sock_udp
|
USEMODULE += gnrc_sock_udp
|
||||||
|
USEMODULE += sock_util
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq (,$(filter luid,$(USEMODULE)))
|
ifneq (,$(filter luid,$(USEMODULE)))
|
||||||
|
|||||||
@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "assert.h"
|
#include "assert.h"
|
||||||
#include "net/gcoap.h"
|
#include "net/gcoap.h"
|
||||||
|
#include "net/sock/util.h"
|
||||||
#include "mutex.h"
|
#include "mutex.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
@ -45,7 +46,6 @@ static size_t _handle_req(coap_pkt_t *pdu, uint8_t *buf, size_t len,
|
|||||||
sock_udp_ep_t *remote);
|
sock_udp_ep_t *remote);
|
||||||
static ssize_t _finish_pdu(coap_pkt_t *pdu, uint8_t *buf, size_t len);
|
static ssize_t _finish_pdu(coap_pkt_t *pdu, uint8_t *buf, size_t len);
|
||||||
static void _expire_request(gcoap_request_memo_t *memo);
|
static void _expire_request(gcoap_request_memo_t *memo);
|
||||||
static bool _endpoints_equal(const sock_udp_ep_t *ep1, const sock_udp_ep_t *ep2);
|
|
||||||
static void _find_req_memo(gcoap_request_memo_t **memo_ptr, coap_pkt_t *pdu,
|
static void _find_req_memo(gcoap_request_memo_t **memo_ptr, coap_pkt_t *pdu,
|
||||||
const sock_udp_ep_t *remote);
|
const sock_udp_ep_t *remote);
|
||||||
static int _find_resource(coap_pkt_t *pdu, const coap_resource_t **resource_ptr,
|
static int _find_resource(coap_pkt_t *pdu, const coap_resource_t **resource_ptr,
|
||||||
@ -298,7 +298,7 @@ static size_t _handle_req(coap_pkt_t *pdu, uint8_t *buf, size_t len,
|
|||||||
}
|
}
|
||||||
/* otherwise OK to re-register resource with the same token */
|
/* otherwise OK to re-register resource with the same token */
|
||||||
}
|
}
|
||||||
else if (_endpoints_equal(remote, resource_memo->observer)) {
|
else if (sock_udp_ep_equal(remote, resource_memo->observer)) {
|
||||||
/* accept new token for resource */
|
/* accept new token for resource */
|
||||||
memo = resource_memo;
|
memo = resource_memo;
|
||||||
}
|
}
|
||||||
@ -477,7 +477,7 @@ static void _find_req_memo(gcoap_request_memo_t **memo_ptr, coap_pkt_t *src_pdu,
|
|||||||
if (coap_get_token_len(memo_pdu) == cmplen) {
|
if (coap_get_token_len(memo_pdu) == cmplen) {
|
||||||
memo_pdu->token = &memo_pdu->hdr->data[0];
|
memo_pdu->token = &memo_pdu->hdr->data[0];
|
||||||
if ((memcmp(src_pdu->token, memo_pdu->token, cmplen) == 0)
|
if ((memcmp(src_pdu->token, memo_pdu->token, cmplen) == 0)
|
||||||
&& _endpoints_equal(&memo->remote_ep, remote)) {
|
&& sock_udp_ep_equal(&memo->remote_ep, remote)) {
|
||||||
*memo_ptr = memo;
|
*memo_ptr = memo;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -591,24 +591,6 @@ static ssize_t _write_options(coap_pkt_t *pdu, uint8_t *buf, size_t len)
|
|||||||
return bufpos - buf;
|
return bufpos - buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool _endpoints_equal(const sock_udp_ep_t *ep1, const sock_udp_ep_t *ep2)
|
|
||||||
{
|
|
||||||
if (ep1->family != ep2->family) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ep1->port != ep2->port) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (ep1->family) {
|
|
||||||
case AF_INET6:
|
|
||||||
return memcmp(&ep1->addr.ipv6[0], &ep2->addr.ipv6[0], 16) == 0;
|
|
||||||
case AF_INET:
|
|
||||||
return ep1->addr.ipv4_u32 == ep2->addr.ipv4_u32;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find registered observer for a remote address and port.
|
* Find registered observer for a remote address and port.
|
||||||
*
|
*
|
||||||
@ -627,7 +609,7 @@ static int _find_observer(sock_udp_ep_t **observer, sock_udp_ep_t *remote)
|
|||||||
if (_coap_state.observers[i].family == AF_UNSPEC) {
|
if (_coap_state.observers[i].family == AF_UNSPEC) {
|
||||||
empty_slot = i;
|
empty_slot = i;
|
||||||
}
|
}
|
||||||
else if (_endpoints_equal(&_coap_state.observers[i], remote)) {
|
else if (sock_udp_ep_equal(&_coap_state.observers[i], remote)) {
|
||||||
*observer = &_coap_state.observers[i];
|
*observer = &_coap_state.observers[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user