1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

pkg/tinydtls: join IPv6 address and port in addr member

This commit is contained in:
Leandro Lanzieri 2022-03-24 12:18:43 +01:00
parent 530e699de1
commit 05db36a3d0
No known key found for this signature in database
GPG Key ID: F4E9A721761C7593
4 changed files with 18 additions and 18 deletions

View File

@ -119,9 +119,8 @@ static int dtls_handle_read(dtls_context_t *ctx)
return 0;
}
/* session requires the remote socket (IPv6:UDP) address and netif */
session.size = sizeof(uint8_t) * 16 + sizeof(unsigned short);
session.port = remote.port;
dtls_session_init(&session);
session.addr.port = remote.port;
if (remote.netif == SOCK_ADDR_ANY_NETIF) {
session.ifindex = SOCK_ADDR_ANY_NETIF;
}
@ -129,11 +128,11 @@ static int dtls_handle_read(dtls_context_t *ctx)
session.ifindex = remote.netif;
}
memcpy(&session.addr, &remote.addr.ipv6, sizeof(session.addr));
memcpy(&session.addr.addr, &remote.addr.ipv6, sizeof(session.addr.addr));
if (IS_ACTIVE(ENABLE_DEBUG)) {
DEBUG("DBG-Client: Msg received from \n\t Addr Src: [");
ipv6_addr_print(&session.addr);
ipv6_addr_print(&session.addr.addr);
DEBUG("]:%u\n", remote.port);
}
@ -325,6 +324,8 @@ dtls_context_t *_init_dtls(sock_udp_t *sock, sock_udp_ep_t *local,
dtls_set_log_level(TINYDTLS_LOG_LVL);
#endif
dtls_session_init(dst);
/* First, we prepare the UDP Sock */
local->port = (unsigned short) CLIENT_PORT;
remote->port = (unsigned short) DTLS_DEFAULT_PORT;
@ -358,11 +359,10 @@ dtls_context_t *_init_dtls(sock_udp_t *sock, sock_udp_ep_t *local,
}
/* Second: We prepare the DTLS Session by means of ctx->app */
dst->size = sizeof(uint8_t) * 16 + sizeof(unsigned short);
dst->port = remote->port;
dst->addr.port = remote->port;
/* NOTE: remote.addr.ipv6 and dst->addr are different structures. */
if (ipv6_addr_from_str(&dst->addr, addr_str) == NULL) {
/* NOTE: remote.addr.ipv6 and dst->addr.addr are different structures. */
if (ipv6_addr_from_str(&dst->addr.addr, addr_str) == NULL) {
puts("ERROR: init_dtls was unable to load the IPv6 addresses!");
return new_context;
}

View File

@ -114,8 +114,8 @@ static int dtls_handle_read(dtls_context_t *ctx)
DEBUG("DBG-Server: Record Rcvd\n");
/* (DTLS) session requires the remote peer address (IPv6:Port) and netif */
session.size = sizeof(uint8_t) * 16 + sizeof(unsigned short);
session.port = remote_peer->remote->port;
dtls_session_init(&session);
session.addr.port = remote_peer->remote->port;
if (remote_peer->remote->netif == SOCK_ADDR_ANY_NETIF) {
session.ifindex = SOCK_ADDR_ANY_NETIF;
}
@ -123,7 +123,7 @@ static int dtls_handle_read(dtls_context_t *ctx)
session.ifindex = remote_peer->remote->netif;
}
memcpy(&session.addr, &remote_peer->remote->addr.ipv6, sizeof(session.addr));
memcpy(&session.addr.addr, &remote_peer->remote->addr.ipv6, sizeof(session.addr.addr));
return dtls_handle_message(ctx, &session, packet_rcvd, res);
}

View File

@ -817,9 +817,9 @@ void sock_dtls_init(void)
static void _ep_to_session(const sock_udp_ep_t *ep, session_t *session)
{
session->port = ep->port;
session->size = sizeof(ipv6_addr_t) + /* addr */
sizeof(unsigned short); /* port */
dtls_session_init(session);
session->addr.port = ep->port;
if (ipv6_addr_is_link_local((ipv6_addr_t *)ep->addr.ipv6)) {
/* set ifindex for link-local addresses */
session->ifindex = ep->netif;
@ -827,15 +827,15 @@ static void _ep_to_session(const sock_udp_ep_t *ep, session_t *session)
else {
session->ifindex = SOCK_ADDR_ANY_NETIF;
}
memcpy(&session->addr, &ep->addr.ipv6, sizeof(ipv6_addr_t));
memcpy(&session->addr.addr, &ep->addr.ipv6, sizeof(session->addr.addr));
}
static void _session_to_ep(const session_t *session, sock_udp_ep_t *ep)
{
ep->port = session->port;
ep->port = session->addr.port;
ep->netif = session->ifindex;
ep->family = AF_INET6;
memcpy(&ep->addr.ipv6, &session->addr, sizeof(ipv6_addr_t));
memcpy(&ep->addr.ipv6, &session->addr.addr, sizeof(ep->addr.ipv6));
}
static inline uint32_t _update_timeout(uint32_t start, uint32_t timeout)