Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion dtls/server-dtls-ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ int main(int argc, char** argv)
if ((listenfd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0 ) {
printf("Cannot create socket.\n");
cleanup = 1;
cont = 1;
break;
}
printf("Socket allocated\n");

Expand All @@ -135,13 +137,17 @@ int main(int argc, char** argv)
printf("Setsockopt SO_REUSEADDR failed.\n");
cleanup = 1;
cont = 1;
close(listenfd);
break;
}

/*Bind Socket*/
if (bind(listenfd, (struct sockaddr*)&servAddr, sizeof(servAddr)) < 0) {
printf("Bind failed.\n");
cleanup = 1;
cont = 1;
close(listenfd);
break;
}

printf("Awaiting client connection on port %d\n", SERV_PORT);
Expand All @@ -151,7 +157,8 @@ int main(int argc, char** argv)
(struct sockaddr*)&cliaddr, &cliLen);

if (bytesReceived < 0) {
printf("No clients in que, enter idle state\n");
printf("No clients in queue, enter idle state\n");
close(listenfd);
continue;
}
else if (bytesReceived > 0) {
Expand All @@ -160,12 +167,16 @@ int main(int argc, char** argv)
printf("Udp connect failed.\n");
cleanup = 1;
cont = 1;
close(listenfd);
break;
}
}
else {
printf("Recvfrom failed.\n");
cleanup = 1;
cont = 1;
close(listenfd);
break;
}
printf("Connected!\n");

Expand All @@ -174,6 +185,8 @@ int main(int argc, char** argv)
printf("wolfSSL_new error.\n");
cleanup = 1;
cont = 1;
close(listenfd);
break;
}

/* set the session ssl to client connection port */
Expand All @@ -185,6 +198,8 @@ int main(int argc, char** argv)

printf("error = %d, %s\n", e, wolfSSL_ERR_reason_error_string(e));
printf("SSL_accept failed.\n");
wolfSSL_free(ssl);
close(listenfd);
continue;
}
if ((recvLen = wolfSSL_read(ssl, buff, sizeof(buff)-1)) > 0) {
Expand Down Expand Up @@ -215,6 +230,7 @@ int main(int argc, char** argv)
wolfSSL_set_fd(ssl, 0);
wolfSSL_shutdown(ssl);
wolfSSL_free(ssl);
close(listenfd);

printf("Client left cont to idle state\n");
cont = 0;
Expand Down
17 changes: 17 additions & 0 deletions dtls/server-dtls-nonblocking.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ int main(int argc, char** argv)
if ((listenfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) {
printf("Cannot create socket.\n");
cont = 1;
break;
}

printf("Socket allocated\n");
Expand All @@ -162,6 +163,11 @@ int main(int argc, char** argv)
cleanup = 1;
}

if (cleanup == 1) {
close(listenfd);
break;
}

/* Clear servAddr each loop */
memset((char *)&servAddr, 0, sizeof(servAddr));

Expand All @@ -176,13 +182,17 @@ int main(int argc, char** argv)
if (res < 0) {
printf("Setsockopt SO_REUSEADDR failed.\n");
cont = 1;
close(listenfd);
break;
}

/*Bind Socket*/
if (bind(listenfd,
(struct sockaddr *)&servAddr, sizeof(servAddr)) < 0) {
printf("Bind failed.\n");
cont = 1;
close(listenfd);
break;
}

printf("Awaiting client connection on port %d\n", SERV_PORT);
Expand All @@ -192,12 +202,17 @@ int main(int argc, char** argv)
do {
if (cleanup == 1) {
cont = 1;
close(listenfd);
break;
}
bytesRecvd = (int)recvfrom(listenfd, (char*)b, sizeof(b), MSG_PEEK,
(struct sockaddr*)&cliAddr, &clilen);
} while (bytesRecvd <= 0);

if (cont == 1) {
break;
}

if (bytesRecvd > 0) {
if (connect(listenfd, (const struct sockaddr*)&cliAddr,
sizeof(cliAddr)) != 0) {
Expand All @@ -217,6 +232,8 @@ int main(int argc, char** argv)
if (( ssl = wolfSSL_new(ctx)) == NULL) {
printf("wolfSSL_new error.\n");
cont = 1;
close(listenfd);
break;
}

/* set clilen to |cliAddr| */
Expand Down
5 changes: 3 additions & 2 deletions psk/server-psk-threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,9 @@ void* wolfssl_thread(void* fd)

/* create WOLFSSL object */
if ((ssl = wolfSSL_new(ctx)) == NULL) {
printf("Fatal error : wolfSSL_new error");
/* place signal for forced error exit here */
printf("Fatal error : wolfSSL_new error\n");
close(connfd);
pthread_exit(NULL);
}

wolfSSL_set_fd(ssl, connfd);
Expand Down
2 changes: 1 addition & 1 deletion tls/client-tls13-resume.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ int main(int argc, char** argv)
}

#ifdef HAVE_SECRET_CALLBACK
wolfSSL_FreeArrays(ssl);
wolfSSL_FreeArrays(sslRes);
#endif


Expand Down