Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ diff -u test.c.original test.c
- --- test.c.original 2022-09-07 11:10:57.427143497 -0700
- +++ test.c 2022-09-07 11:18:48.435146489 -0700
- @@ -5,6 +5,7 @@
- #include <arpa/inet.h>
- #include <unistd.h>
- #include <pthread.h>
- +#include <fcntl.h>
- void *recv_thread(void *arg)
- {
- @@ -14,8 +15,9 @@
- char recvbuf[1024] = {0};
- while(1)
- {
- - recvfrom(socket_fd, recvbuf, 1024, 0,(struct sockaddr*)&recv_addr,&addrlen);
- - printf("[recv from %s:%d]%s \n",inet_ntoa(*(struct in_addr*)&recv_addr.sin_addr.s_addr),ntohs(recv_addr.sin_port),recvbuf);
- + int rv = recvfrom(socket_fd, recvbuf, 1024, 0,(struct sockaddr*)&recv_addr,&addrlen);
- + if (rv > 0)
- + printf("[recv from %s:%d]%s \n",inet_ntoa(*(struct in_addr*)&recv_addr.sin_addr.s_addr),ntohs(recv_addr.sin_port),recvbuf);
- }
- }
- @@ -32,9 +34,10 @@
- }
- struct sockaddr_in local_addr = {0};
- local_addr.sin_family = AF_INET;
- - local_addr.sin_addr.s_addr = inet_addr("192.168.0.107");
- + local_addr.sin_addr.s_addr = inet_addr("7.0.0.2");
- local_addr.sin_port = htons(12341);
- bind(sockfd, (struct sockaddr*)&local_addr, sizeof(local_addr));
- + fcntl(sockfd, F_SETFL, O_NONBLOCK);
- ret = pthread_create(&th, NULL, recv_thread, &sockfd);
- @@ -48,9 +51,10 @@
- }
- struct sockaddr_in local_addr2 = {0};
- local_addr2.sin_family = AF_INET;
- - local_addr2.sin_addr.s_addr = inet_addr("192.168.0.107");
- + local_addr2.sin_addr.s_addr = inet_addr("7.0.0.2");
- local_addr2.sin_port = htons(12342);
- bind(sockfd2, (struct sockaddr*)&local_addr2, sizeof(local_addr2));
- + fcntl(sockfd2, F_SETFL, O_NONBLOCK);
- ret2 = pthread_create(&th2, NULL, recv_thread, &sockfd2);
- void *status;
Advertisement
Add Comment
Please, Sign In to add comment