diff --git a/dtls/README.md b/dtls/README.md index 959b58e9..9fa58825 100644 --- a/dtls/README.md +++ b/dtls/README.md @@ -394,7 +394,7 @@ With this change we will also rename `addrlen` to `clilen` to remind us that thi ```c int on = 1; int res = 1; -int connfd = 0; +int bytesReceived = 0; int recvlen = 0; /* length of message */ int listenfd = 0; /* Initialize our socket */ WOLFSSL* ssl = NULL; @@ -556,16 +556,16 @@ Here is where we will now set `clilen = sizeof(cliaddr);` as well. We will decla /* set clilen to |cliaddr| */ clilen = sizeof(cliaddr); /* will be moved to the variable section later */ unsigned char b[1500]; /* will be moved to the variable section later */ -int connfd = 0; /* will be moved to the variable section later */ +int bytesReceived = 0; /* will be moved to the variable section later */ -connfd = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK, +bytesReceived = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK, (struct sockaddr*)&cliaddr, &clilen); -if (connfd < 0){ +if (bytesReceived < 0){ printf("No clients in que, enter idle state\n"); continue; } -else if (connfd > 0) { +else if (bytesReceived > 0) { if (connect(listenfd, (const struct sockaddr *)&cliaddr, sizeof(cliaddr)) != 0) { printf("Udp connect failed.\n"); diff --git a/dtls/server-dtls-ipv6.c b/dtls/server-dtls-ipv6.c index aa3f4aed..2fd9b1d0 100644 --- a/dtls/server-dtls-ipv6.c +++ b/dtls/server-dtls-ipv6.c @@ -64,7 +64,7 @@ int main(int argc, char** argv) /* Variables for awaiting datagram */ int on = 1; int res = 1; - int connfd = 0; + int bytesReceived = 0; int recvLen = 0; /* length of message */ int listenfd = 0; /* Initialize our socket */ WOLFSSL* ssl = NULL; @@ -147,14 +147,14 @@ int main(int argc, char** argv) printf("Awaiting client connection on port %d\n", SERV_PORT); cliLen = sizeof(cliaddr); - connfd = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK, + bytesReceived = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK, (struct sockaddr*)&cliaddr, &cliLen); - if (connfd < 0) { + if (bytesReceived < 0) { printf("No clients in que, enter idle state\n"); continue; } - else if (connfd > 0) { + else if (bytesReceived > 0) { if (connect(listenfd, (const struct sockaddr *)&cliaddr, sizeof(cliaddr)) != 0) { printf("Udp connect failed.\n"); diff --git a/dtls/server-dtls-rw-threads.c b/dtls/server-dtls-rw-threads.c index 26ddb0a2..0c6d120b 100644 --- a/dtls/server-dtls-rw-threads.c +++ b/dtls/server-dtls-rw-threads.c @@ -228,7 +228,7 @@ int main(int argc, char** argv) /* Variables for awaiting datagram */ int on = 1; int res = 1; - int connfd = 0; + int bytesReceived = 0; int listenfd = 0; /* Initialize our socket */ int flags = fcntl(*(&listenfd), F_GETFL, 0); WOLFSSL* ssl = NULL; @@ -319,15 +319,15 @@ int main(int argc, char** argv) printf("Awaiting client connection on port %d\n", SERV_PORT); cliLen = sizeof(cliaddr); - connfd = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK, + bytesReceived = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK, (struct sockaddr*)&cliaddr, &cliLen); - if (connfd < 0) { + if (bytesReceived < 0) { printf("No clients in que, enter idle state\n"); close(listenfd); continue; } - else if (connfd > 0) { + else if (bytesReceived > 0) { if (connect(listenfd, (const struct sockaddr *)&cliaddr, sizeof(cliaddr)) != 0) { printf("Udp connect failed.\n"); diff --git a/dtls/server-dtls.c b/dtls/server-dtls.c index 44b7c1f2..fefc9ed4 100644 --- a/dtls/server-dtls.c +++ b/dtls/server-dtls.c @@ -57,7 +57,7 @@ int main(int argc, char** argv) /* Variables for awaiting datagram */ int on = 1; int res = 1; - int connfd = 0; + int bytesReceived = 0; int recvLen = 0; /* length of message */ int listenfd = 0; /* Initialize our socket */ WOLFSSL* ssl = NULL; @@ -140,15 +140,15 @@ int main(int argc, char** argv) printf("Awaiting client connection on port %d\n", SERV_PORT); cliLen = sizeof(cliaddr); - connfd = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK, + bytesReceived = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK, (struct sockaddr*)&cliaddr, &cliLen); - if (connfd < 0) { + if (bytesReceived < 0) { printf("No clients in que, enter idle state\n"); close(listenfd); continue; } - else if (connfd > 0) { + else if (bytesReceived > 0) { if (connect(listenfd, (const struct sockaddr *)&cliaddr, sizeof(cliaddr)) != 0) { printf("Udp connect failed.\n");