title: How to preoperly prepare a DTLS server in OpenSSL 1.1.1
body: <p>I am trying to get a DTLS "connection" going using OpenSSL 1.1.1.</p>
  
  <p>I am constantly getting a <code>SSL_ERROR_SYSCALL</code> when trying to run <code>DTLSv1_listen()</code> on the socket.</p>
  
  <p>I use a single AF_INET, DGRAM, UDP socket to receive all incoming data. I <em>assumed</em> I could leave it at that and OpenSSL would take care of determining the sender whenever a datagram is received but I am starting to think I am mistaken.</p>
  
  <p>I have: (error handling omitted for brevity)</p>
  
  <pre><code>SSL_CTX *ctx = SSL_CTX_new(DTLS());
  SSL_CTX_use_certificate_file(ctx, "certs/server-cert.pem", SSL_FILETYPE_PEM);
  SSL_CTX_use_PrivateKey_file(ctx, "certs/server-key.pem", SSL_FILETYPE_PEM);
  SSL_CTX_set_cookie_generate_cb(ctx, generate_cookie);
  SSL_CTX_set_cookie_verify_cb(ctx, &amp;verify_cookie);
  
  int fd = socket(AF_INET, SOCK_DGRAM, 0);
  setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (const void*) &amp;on, (socklen_t) sizeof(on));
  bind(fd, (const struct sockaddr *) &amp;server_addr, sizeof(struct sockaddr_in))
  
  SSL *ssl = SSL_new(ctx);
  SSL_set_fd(ssl, fd);
  SSL_set_accept_state(ssl);
  while(DTLSv1_listen(ssl, (BIO_ADDR *) BIO_get_conn_address(SSL_get_rbio(ssl))) &lt;= 0)
  ...
  </code></pre>
  
  <p>As I mentioned, that last line gives me an `SSL_ERROR_SYSCALL'.</p>
  
  <p><code>errno</code> gives me <code>0</code>.</p>
  
  <p>I suspect I'm missing some steps in the CTX configuration but I'm not sure what.</p>
  
  <p>I've been looking through some examples and <a href="https://github.com/nplab/DTLS-Examples/blob/master/src/dtls_udp_echo.c" rel="nofollow noreferrer">one in particular</a> caught my eye. It seems to create a <em>new</em> socket whenever it receives a datagram and does a <code>connect()</code> on that socket to the remote address. This seems a bit ridicuous to me as I don't think UDP requires a soket per client AFAIK.</p>