mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #20476 from benpicco/nanocoap-ipv4
nanocoap_sock: add support for IPv4
This commit is contained in:
commit
4850881369
@ -822,6 +822,26 @@ static inline bool sock_udp_ep_is_multicast(const sock_udp_ep_t *ep)
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks if the IP address of an endpoint is an IPv6 address
|
||||
*
|
||||
* @param[in] ep end point to check
|
||||
*
|
||||
* @returns true if end point is IPv6
|
||||
*/
|
||||
static inline bool sock_udp_ep_is_v6(const sock_udp_ep_t *ep)
|
||||
{
|
||||
#if !defined(SOCK_HAS_IPV6)
|
||||
(void)ep;
|
||||
return false;
|
||||
#elif !defined(SOCK_HAS_IPV4)
|
||||
(void)ep;
|
||||
return true;
|
||||
#else
|
||||
return ep->family == AF_INET6;
|
||||
#endif
|
||||
}
|
||||
|
||||
#include "sock_types.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -722,9 +722,9 @@ int nanocoap_sock_url_connect(const char *url, nanocoap_sock_t *sock)
|
||||
}
|
||||
|
||||
if (is_coaps) {
|
||||
|
||||
#if SOCK_HAS_IPV6
|
||||
/* tinydtls wants the interface to match */
|
||||
if (!remote.netif &&
|
||||
if (!remote.netif && sock_udp_ep_is_v6(&remote) &&
|
||||
ipv6_addr_is_link_local((ipv6_addr_t *)remote.addr.ipv6)) {
|
||||
netif_t *iface = netif_iter(NULL);
|
||||
if (iface == NULL) {
|
||||
@ -734,6 +734,12 @@ int nanocoap_sock_url_connect(const char *url, nanocoap_sock_t *sock)
|
||||
}
|
||||
|
||||
sock_udp_ep_t local = SOCK_IPV6_EP_ANY;
|
||||
if (!sock_udp_ep_is_v6(&remote)) {
|
||||
local.family = AF_INET;
|
||||
}
|
||||
#else
|
||||
sock_udp_ep_t local = SOCK_IPV4_EP_ANY;
|
||||
#endif
|
||||
return nanocoap_sock_dtls_connect(sock, &local, &remote, CONFIG_NANOCOAP_SOCK_DTLS_TAG);
|
||||
} else {
|
||||
return nanocoap_sock_connect(sock, NULL, &remote);
|
||||
|
Loading…
Reference in New Issue
Block a user