Skip to content

Commit 0516999

Browse files
committed
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.
1 parent dd8f171 commit 0516999

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

dtls/client-dtls13-earlydata.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#define DATA_MSG "Normal data hello from early data DTLS client!"
4646
#define DATA_MSG_LEN (sizeof(DATA_MSG))
4747

48-
static int udp_connect(const char* ip, int port, struct sockaddr_in* servAddr) {
48+
static int udp_create_socket(const char* ip, int port, struct sockaddr_in* servAddr) {
4949
int sockfd;
5050

5151
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
@@ -105,7 +105,7 @@ int main(int argc, char** argv)
105105
}
106106

107107
/* === 1st connection: perform handshake and get session ticket === */
108-
sockfd = udp_connect(server_ip, DEFAULT_PORT, &servAddr);
108+
sockfd = udp_create_socket(server_ip, DEFAULT_PORT, &servAddr);
109109
if (sockfd < 0) goto cleanup;
110110

111111
ssl = wolfSSL_new(ctx);
@@ -150,7 +150,7 @@ int main(int argc, char** argv)
150150
sockfd = -1;
151151

152152
/* === 2nd connection: resume session and send early data === */
153-
sockfd = udp_connect(server_ip, DEFAULT_PORT, &servAddr);
153+
sockfd = udp_create_socket(server_ip, DEFAULT_PORT, &servAddr);
154154
if (sockfd < 0) goto cleanup;
155155

156156
ssl = wolfSSL_new(ctx);
@@ -183,6 +183,13 @@ int main(int argc, char** argv)
183183
fprintf(stderr, "wolfSSL_connect (2nd) failed\n");
184184
goto cleanup;
185185
}
186+
else {
187+
memset(recvBuf, 0, sizeof(recvBuf));
188+
len = wolfSSL_read(ssl, recvBuf, sizeof(recvBuf) - 1);
189+
if (len > 0) {
190+
printf("Server sent during handshake: %s\n", recvBuf);
191+
}
192+
}
186193
}
187194
printf("Handshake complete after early data.\n");
188195

0 commit comments

Comments
 (0)