Merge pull request #508 from anhu/connfd_to_bytesReceived

recvfrom() returns the bytes received; not a file descriptor.
master
David Garske 2025-06-12 12:04:35 -07:00 committed by GitHub
commit 72a36587c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 17 deletions

View File

@ -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");

View File

@ -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");

View File

@ -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");

View File

@ -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");