Skip to content

Commit 72a3658

Browse files
authored
Merge pull request #508 from anhu/connfd_to_bytesReceived
recvfrom() returns the bytes received; not a file descriptor.
2 parents 41d61d2 + dbb4c30 commit 72a3658

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

dtls/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ With this change we will also rename `addrlen` to `clilen` to remind us that thi
394394
```c
395395
int on = 1;
396396
int res = 1;
397-
int connfd = 0;
397+
int bytesReceived = 0;
398398
int recvlen = 0; /* length of message */
399399
int listenfd = 0; /* Initialize our socket */
400400
WOLFSSL* ssl = NULL;
@@ -556,16 +556,16 @@ Here is where we will now set `clilen = sizeof(cliaddr);` as well. We will decla
556556
/* set clilen to |cliaddr| */
557557
clilen = sizeof(cliaddr); /* will be moved to the variable section later */
558558
unsigned char b[1500]; /* will be moved to the variable section later */
559-
int connfd = 0; /* will be moved to the variable section later */
559+
int bytesReceived = 0; /* will be moved to the variable section later */
560560

561-
connfd = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK,
561+
bytesReceived = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK,
562562
(struct sockaddr*)&cliaddr, &clilen);
563-
if (connfd < 0){
563+
if (bytesReceived < 0){
564564
printf("No clients in que, enter idle state\n");
565565
continue;
566566
}
567567

568-
else if (connfd > 0) {
568+
else if (bytesReceived > 0) {
569569
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
570570
sizeof(cliaddr)) != 0) {
571571
printf("Udp connect failed.\n");

dtls/server-dtls-ipv6.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int main(int argc, char** argv)
6464
/* Variables for awaiting datagram */
6565
int on = 1;
6666
int res = 1;
67-
int connfd = 0;
67+
int bytesReceived = 0;
6868
int recvLen = 0; /* length of message */
6969
int listenfd = 0; /* Initialize our socket */
7070
WOLFSSL* ssl = NULL;
@@ -147,14 +147,14 @@ int main(int argc, char** argv)
147147
printf("Awaiting client connection on port %d\n", SERV_PORT);
148148

149149
cliLen = sizeof(cliaddr);
150-
connfd = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK,
150+
bytesReceived = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK,
151151
(struct sockaddr*)&cliaddr, &cliLen);
152152

153-
if (connfd < 0) {
153+
if (bytesReceived < 0) {
154154
printf("No clients in que, enter idle state\n");
155155
continue;
156156
}
157-
else if (connfd > 0) {
157+
else if (bytesReceived > 0) {
158158
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
159159
sizeof(cliaddr)) != 0) {
160160
printf("Udp connect failed.\n");

dtls/server-dtls-rw-threads.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ int main(int argc, char** argv)
228228
/* Variables for awaiting datagram */
229229
int on = 1;
230230
int res = 1;
231-
int connfd = 0;
231+
int bytesReceived = 0;
232232
int listenfd = 0; /* Initialize our socket */
233233
int flags = fcntl(*(&listenfd), F_GETFL, 0);
234234
WOLFSSL* ssl = NULL;
@@ -319,15 +319,15 @@ int main(int argc, char** argv)
319319
printf("Awaiting client connection on port %d\n", SERV_PORT);
320320

321321
cliLen = sizeof(cliaddr);
322-
connfd = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK,
322+
bytesReceived = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK,
323323
(struct sockaddr*)&cliaddr, &cliLen);
324324

325-
if (connfd < 0) {
325+
if (bytesReceived < 0) {
326326
printf("No clients in que, enter idle state\n");
327327
close(listenfd);
328328
continue;
329329
}
330-
else if (connfd > 0) {
330+
else if (bytesReceived > 0) {
331331
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
332332
sizeof(cliaddr)) != 0) {
333333
printf("Udp connect failed.\n");

dtls/server-dtls.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int main(int argc, char** argv)
5757
/* Variables for awaiting datagram */
5858
int on = 1;
5959
int res = 1;
60-
int connfd = 0;
60+
int bytesReceived = 0;
6161
int recvLen = 0; /* length of message */
6262
int listenfd = 0; /* Initialize our socket */
6363
WOLFSSL* ssl = NULL;
@@ -140,15 +140,15 @@ int main(int argc, char** argv)
140140
printf("Awaiting client connection on port %d\n", SERV_PORT);
141141

142142
cliLen = sizeof(cliaddr);
143-
connfd = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK,
143+
bytesReceived = (int)recvfrom(listenfd, (char *)&b, sizeof(b), MSG_PEEK,
144144
(struct sockaddr*)&cliaddr, &cliLen);
145145

146-
if (connfd < 0) {
146+
if (bytesReceived < 0) {
147147
printf("No clients in que, enter idle state\n");
148148
close(listenfd);
149149
continue;
150150
}
151-
else if (connfd > 0) {
151+
else if (bytesReceived > 0) {
152152
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
153153
sizeof(cliaddr)) != 0) {
154154
printf("Udp connect failed.\n");

0 commit comments

Comments
 (0)