<h3>Contribution description</h3>
<p>On a <code>SOCK_ASNYC_MSG_RECV</code> event the received session (received via <code>sock_dtls_recv</code>) has no set address family for the endpoint. This fixes the bug by setting the address family when the endpoint is created out of the session in tinydtls.</p>

<h3>Testing procedure</h3>
<p><a href="https://github.com/RIOT-OS/RIOT/tree/master/tests/pkg_tinydtls_sock_async">This</a> test can be used as application together with this patch:</p>
<pre><code>diff --git a/tests/pkg_tinydtls_sock_async/dtls-client.c b/tests/pkg_tinydtls_sock_async/dtls-client.c
index 2cafecc18..f3c833c90 100644
--- a/tests/pkg_tinydtls_sock_async/dtls-client.c
+++ b/tests/pkg_tinydtls_sock_async/dtls-client.c
@@ -147,6 +147,15 @@ static void _dtls_handler(sock_dtls_t *sock, sock_async_flags_t type, void *arg)
             printf("Received %d bytes: \"%.*s\"\n", (int)res, (int)res,
                    (char *)_recv_buf);
         }
+        printf("Session.ep.family: ");
+        switch (session.ep.family) {
+            case (AF_INET6):
+                printf("AF_INET6\n");
+                break;
+            case (AF_UNSPEC):
+                printf("AF_UNSPEC\n");
+                break;
+        }
         puts("Terminating session");
         sock_dtls_session_destroy(sock, &session);
         _close_sock(sock);
</code></pre>
<ul>
<li>Create two tap interfaces (e.g. with <a href="https://github.com/RIOT-OS/RIOT/tree/master/dist/tools/tapsetup">tapsetup</a>) and run the application on both interfaces</li>
<li>Start DTLS server on one of the instances: <code>dtlss start</code></li>
<li>Send DTLS message from the other instance: <code>dtlsc {addr} {data}</code></li>
</ul>
<p>Without the patch <code>Session.ep.family: AF_UNSPEC</code> should be printed since no address family is set after receiving<br>
With patch the result should be <code>Session.ep.family: AF_INET6</code></p>

<h3>Issues/PRs references</h3>


<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/RIOT-OS/RIOT/pull/15416'>https://github.com/RIOT-OS/RIOT/pull/15416</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>pkg/tinydtls: set endpoint family on sock_dtls_recv</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/15416/files#diff-26677c27905d6477d358c9e0fb59c1c63e7f291b28126c63a55a3fda07632ba8">pkg/tinydtls/contrib/sock_dtls.c</a>
    (1)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/RIOT-OS/RIOT/pull/15416.patch'>https://github.com/RIOT-OS/RIOT/pull/15416.patch</a></li>
  <li><a href='https://github.com/RIOT-OS/RIOT/pull/15416.diff'>https://github.com/RIOT-OS/RIOT/pull/15416.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/RIOT-OS/RIOT/pull/15416">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABE7WYAF6JV7YP5YYNJSZMTSPCOD5ANCNFSM4TQCOUSQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABE7WYDMRXF5ZSOFSKCW2HTSPCOD5A5CNFSM4TQCOUS2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4LAUADGA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/RIOT-OS/RIOT/pull/15416",
"url": "https://github.com/RIOT-OS/RIOT/pull/15416",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>