recvfrom() returns the bytes received; not a file descriptor.
parent
85733255d7
commit
dbb4c309e7
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue