Merge pull request #508 from anhu/connfd_to_bytesReceived
recvfrom() returns the bytes received; not a file descriptor.master
commit
72a36587c6
|
@ -394,7 +394,7 @@ With this change we will also rename `addrlen` to `clilen` to remind us that thi
|
||||||
```c
|
```c
|
||||||
int on = 1;
|
int on = 1;
|
||||||
int res = 1;
|
int res = 1;
|
||||||
int connfd = 0;
|
int bytesReceived = 0;
|
||||||
int recvlen = 0; /* length of message */
|
int recvlen = 0; /* length of message */
|
||||||
int listenfd = 0; /* Initialize our socket */
|
int listenfd = 0; /* Initialize our socket */
|
||||||
WOLFSSL* ssl = NULL;
|
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| */
|
/* set clilen to |cliaddr| */
|
||||||
clilen = sizeof(cliaddr); /* will be moved to the variable section later */
|
clilen = sizeof(cliaddr); /* will be moved to the variable section later */
|
||||||
unsigned char b[1500]; /* 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);
|
(struct sockaddr*)&cliaddr, &clilen);
|
||||||
if (connfd < 0){
|
if (bytesReceived < 0){
|
||||||
printf("No clients in que, enter idle state\n");
|
printf("No clients in que, enter idle state\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (connfd > 0) {
|
else if (bytesReceived > 0) {
|
||||||
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
|
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
|
||||||
sizeof(cliaddr)) != 0) {
|
sizeof(cliaddr)) != 0) {
|
||||||
printf("Udp connect failed.\n");
|
printf("Udp connect failed.\n");
|
||||||
|
|
|
@ -64,7 +64,7 @@ int main(int argc, char** argv)
|
||||||
/* Variables for awaiting datagram */
|
/* Variables for awaiting datagram */
|
||||||
int on = 1;
|
int on = 1;
|
||||||
int res = 1;
|
int res = 1;
|
||||||
int connfd = 0;
|
int bytesReceived = 0;
|
||||||
int recvLen = 0; /* length of message */
|
int recvLen = 0; /* length of message */
|
||||||
int listenfd = 0; /* Initialize our socket */
|
int listenfd = 0; /* Initialize our socket */
|
||||||
WOLFSSL* ssl = NULL;
|
WOLFSSL* ssl = NULL;
|
||||||
|
@ -147,14 +147,14 @@ int main(int argc, char** argv)
|
||||||
printf("Awaiting client connection on port %d\n", SERV_PORT);
|
printf("Awaiting client connection on port %d\n", SERV_PORT);
|
||||||
|
|
||||||
cliLen = sizeof(cliaddr);
|
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);
|
(struct sockaddr*)&cliaddr, &cliLen);
|
||||||
|
|
||||||
if (connfd < 0) {
|
if (bytesReceived < 0) {
|
||||||
printf("No clients in que, enter idle state\n");
|
printf("No clients in que, enter idle state\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (connfd > 0) {
|
else if (bytesReceived > 0) {
|
||||||
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
|
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
|
||||||
sizeof(cliaddr)) != 0) {
|
sizeof(cliaddr)) != 0) {
|
||||||
printf("Udp connect failed.\n");
|
printf("Udp connect failed.\n");
|
||||||
|
|
|
@ -228,7 +228,7 @@ int main(int argc, char** argv)
|
||||||
/* Variables for awaiting datagram */
|
/* Variables for awaiting datagram */
|
||||||
int on = 1;
|
int on = 1;
|
||||||
int res = 1;
|
int res = 1;
|
||||||
int connfd = 0;
|
int bytesReceived = 0;
|
||||||
int listenfd = 0; /* Initialize our socket */
|
int listenfd = 0; /* Initialize our socket */
|
||||||
int flags = fcntl(*(&listenfd), F_GETFL, 0);
|
int flags = fcntl(*(&listenfd), F_GETFL, 0);
|
||||||
WOLFSSL* ssl = NULL;
|
WOLFSSL* ssl = NULL;
|
||||||
|
@ -319,15 +319,15 @@ int main(int argc, char** argv)
|
||||||
printf("Awaiting client connection on port %d\n", SERV_PORT);
|
printf("Awaiting client connection on port %d\n", SERV_PORT);
|
||||||
|
|
||||||
cliLen = sizeof(cliaddr);
|
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);
|
(struct sockaddr*)&cliaddr, &cliLen);
|
||||||
|
|
||||||
if (connfd < 0) {
|
if (bytesReceived < 0) {
|
||||||
printf("No clients in que, enter idle state\n");
|
printf("No clients in que, enter idle state\n");
|
||||||
close(listenfd);
|
close(listenfd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (connfd > 0) {
|
else if (bytesReceived > 0) {
|
||||||
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
|
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
|
||||||
sizeof(cliaddr)) != 0) {
|
sizeof(cliaddr)) != 0) {
|
||||||
printf("Udp connect failed.\n");
|
printf("Udp connect failed.\n");
|
||||||
|
|
|
@ -57,7 +57,7 @@ int main(int argc, char** argv)
|
||||||
/* Variables for awaiting datagram */
|
/* Variables for awaiting datagram */
|
||||||
int on = 1;
|
int on = 1;
|
||||||
int res = 1;
|
int res = 1;
|
||||||
int connfd = 0;
|
int bytesReceived = 0;
|
||||||
int recvLen = 0; /* length of message */
|
int recvLen = 0; /* length of message */
|
||||||
int listenfd = 0; /* Initialize our socket */
|
int listenfd = 0; /* Initialize our socket */
|
||||||
WOLFSSL* ssl = NULL;
|
WOLFSSL* ssl = NULL;
|
||||||
|
@ -140,15 +140,15 @@ int main(int argc, char** argv)
|
||||||
printf("Awaiting client connection on port %d\n", SERV_PORT);
|
printf("Awaiting client connection on port %d\n", SERV_PORT);
|
||||||
|
|
||||||
cliLen = sizeof(cliaddr);
|
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);
|
(struct sockaddr*)&cliaddr, &cliLen);
|
||||||
|
|
||||||
if (connfd < 0) {
|
if (bytesReceived < 0) {
|
||||||
printf("No clients in que, enter idle state\n");
|
printf("No clients in que, enter idle state\n");
|
||||||
close(listenfd);
|
close(listenfd);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (connfd > 0) {
|
else if (bytesReceived > 0) {
|
||||||
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
|
if (connect(listenfd, (const struct sockaddr *)&cliaddr,
|
||||||
sizeof(cliaddr)) != 0) {
|
sizeof(cliaddr)) != 0) {
|
||||||
printf("Udp connect failed.\n");
|
printf("Udp connect failed.\n");
|
||||||
|
|
Loading…
Reference in New Issue