From 0516999449252bc2006eb32a446581218f9c64a8 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Fri, 21 Nov 2025 13:55:59 +0100 Subject: [PATCH] Rename udp_connect to udp_create_socket During the resumed (second) DTLS connection, read any server data that arrives during the handshake and print it. This adds a memset and wolfSSL_read into recvBuf and prints when len > 0. --- dtls/client-dtls13-earlydata.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/dtls/client-dtls13-earlydata.c b/dtls/client-dtls13-earlydata.c index 004b2835..80876b4c 100644 --- a/dtls/client-dtls13-earlydata.c +++ b/dtls/client-dtls13-earlydata.c @@ -45,7 +45,7 @@ #define DATA_MSG "Normal data hello from early data DTLS client!" #define DATA_MSG_LEN (sizeof(DATA_MSG)) -static int udp_connect(const char* ip, int port, struct sockaddr_in* servAddr) { +static int udp_create_socket(const char* ip, int port, struct sockaddr_in* servAddr) { int sockfd; if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { @@ -105,7 +105,7 @@ int main(int argc, char** argv) } /* === 1st connection: perform handshake and get session ticket === */ - sockfd = udp_connect(server_ip, DEFAULT_PORT, &servAddr); + sockfd = udp_create_socket(server_ip, DEFAULT_PORT, &servAddr); if (sockfd < 0) goto cleanup; ssl = wolfSSL_new(ctx); @@ -150,7 +150,7 @@ int main(int argc, char** argv) sockfd = -1; /* === 2nd connection: resume session and send early data === */ - sockfd = udp_connect(server_ip, DEFAULT_PORT, &servAddr); + sockfd = udp_create_socket(server_ip, DEFAULT_PORT, &servAddr); if (sockfd < 0) goto cleanup; ssl = wolfSSL_new(ctx); @@ -183,6 +183,13 @@ int main(int argc, char** argv) fprintf(stderr, "wolfSSL_connect (2nd) failed\n"); goto cleanup; } + else { + memset(recvBuf, 0, sizeof(recvBuf)); + len = wolfSSL_read(ssl, recvBuf, sizeof(recvBuf) - 1); + if (len > 0) { + printf("Server sent during handshake: %s\n", recvBuf); + } + } } printf("Handshake complete after early data.\n");