pkg/tinydtls: Implement sock_aux_local#14706
Merged
miri64 merged 1 commit intoRIOT-OS:masterfrom Dec 4, 2020
Merged
Conversation
Member
Author
|
Rebased on top of #14704 |
Member
sock_aux_local
Member
Author
Member
|
All dependencies are merged. Please rebase to current master. |
Member
While the code is simple enough, do you have a suggestion how to test this? |
Member
|
I applied the following patch diff --git a/examples/dtls-sock/Makefile b/examples/dtls-sock/Makefile
index 8861948702..1a15299175 100644
--- a/examples/dtls-sock/Makefile
+++ b/examples/dtls-sock/Makefile
@@ -23,6 +23,8 @@ USEPKG += tinydtls
# Pull in sock APIs
USEMODULE += sock_dtls
USEMODULE += sock_udp
+USEMODULE += sock_aux_local
+USEMODULE += sock_util
# tinydtls needs crypto secure PRNG
USEMODULE += prng_sha1prng
diff --git a/examples/dtls-sock/dtls-client.c b/examples/dtls-sock/dtls-client.c
index c5cb43a894..093cf24f9d 100644
--- a/examples/dtls-sock/dtls-client.c
+++ b/examples/dtls-sock/dtls-client.c
@@ -20,6 +20,7 @@
#include "net/sock/udp.h"
#include "net/sock/dtls.h"
+#include "net/sock/util.h"
#include "net/ipv6/addr.h"
#include "net/credman.h"
@@ -76,6 +77,7 @@ static int client_send(char *addr_str, char *data, size_t datalen)
sock_dtls_session_t session;
sock_udp_ep_t remote = SOCK_IPV6_EP_ANY;
sock_udp_ep_t local = SOCK_IPV6_EP_ANY;
+ sock_dtls_aux_rx_t aux = { .flags = SOCK_AUX_GET_LOCAL };
local.port = 12345;
remote.port = DTLS_DEFAULT_PORT;
uint8_t buf[DTLS_HANDSHAKE_BUFSIZE];
@@ -128,8 +130,8 @@ static int client_send(char *addr_str, char *data, size_t datalen)
return res;
}
- res = sock_dtls_recv(&dtls_sock, &session, buf, sizeof(buf),
- SOCK_NO_TIMEOUT);
+ res = sock_dtls_recv_aux(&dtls_sock, &session, buf, sizeof(buf),
+ SOCK_NO_TIMEOUT, &aux);
if (res != -SOCK_DTLS_HANDSHAKE) {
printf("Error creating session: %d\n", (int)res);
sock_dtls_close(&dtls_sock);
@@ -137,6 +139,13 @@ static int client_send(char *addr_str, char *data, size_t datalen)
return -1;
}
printf("Connection to server successful\n");
+ if (!(aux.flags & SOCK_AUX_GET_LOCAL)) {
+ uint16_t port;
+ char addr[IPV6_ADDR_MAX_STR_LEN];
+
+ sock_udp_ep_fmt(&aux.local, addr, &port);
+ printf("on local end-point [%s]:%u\n", addr, port);
+ }
if (sock_dtls_send(&dtls_sock, &session, data, datalen, 0) < 0) {
puts("Error sending data");
@@ -145,10 +154,18 @@ static int client_send(char *addr_str, char *data, size_t datalen)
printf("Sent DTLS message\n");
uint8_t rcv[512];
- if ((res = sock_dtls_recv(&dtls_sock, &session, rcv, sizeof(rcv),
- SOCK_NO_TIMEOUT)) >= 0) {
+ aux.flags |= SOCK_AUX_GET_LOCAL;
+ if ((res = sock_dtls_recv_aux(&dtls_sock, &session, rcv, sizeof(rcv),
+ SOCK_NO_TIMEOUT, &aux)) >= 0) {
printf("Received %d bytes: \"%.*s\"\n", (int)res, (int)res,
(char *)rcv);
+ if (!(aux.flags & SOCK_AUX_GET_LOCAL)) {
+ uint16_t port;
+ char addr[IPV6_ADDR_MAX_STR_LEN];
+
+ sock_udp_ep_fmt(&aux.local, addr, &port);
+ printf("on local end-point [%s]:%u\n", addr, port);
+ }
}
}
And I get the expected output: |
Member
Author
|
Thanks for reviewing and especially for taking the time to adapt the example application to properly test this! |
Member
With pleasure :-) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contribution description
This PR adds the implementation of the
sock_aux_localfor tinydtls, that provides access to the local address via the extended SOCK API of #14703.Testing procedure
No testing application provided :-/
Issues/PRs references
Depends on