|
45 | 45 | #define DATA_MSG "Normal data hello from early data DTLS client!" |
46 | 46 | #define DATA_MSG_LEN (sizeof(DATA_MSG)) |
47 | 47 |
|
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) { |
49 | 49 | int sockfd; |
50 | 50 |
|
51 | 51 | if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { |
@@ -105,7 +105,7 @@ int main(int argc, char** argv) |
105 | 105 | } |
106 | 106 |
|
107 | 107 | /* === 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); |
109 | 109 | if (sockfd < 0) goto cleanup; |
110 | 110 |
|
111 | 111 | ssl = wolfSSL_new(ctx); |
@@ -150,7 +150,7 @@ int main(int argc, char** argv) |
150 | 150 | sockfd = -1; |
151 | 151 |
|
152 | 152 | /* === 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); |
154 | 154 | if (sockfd < 0) goto cleanup; |
155 | 155 |
|
156 | 156 | ssl = wolfSSL_new(ctx); |
@@ -183,6 +183,13 @@ int main(int argc, char** argv) |
183 | 183 | fprintf(stderr, "wolfSSL_connect (2nd) failed\n"); |
184 | 184 | goto cleanup; |
185 | 185 | } |
| 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 | + } |
186 | 193 | } |
187 | 194 | printf("Handshake complete after early data.\n"); |
188 | 195 |
|
|
0 commit comments