|
@ -9,7 +9,7 @@ |
|
|
#include <arpa/inet.h> |
|
|
#include <arpa/inet.h> |
|
|
#include <errno.h> |
|
|
#include <errno.h> |
|
|
|
|
|
|
|
|
#define HOST_IF_IP "192.168.0.191" |
|
|
#define HOST_IF_IP "192.168.31.89" |
|
|
#define GROUP_ADDR "225.0.0.5" |
|
|
#define GROUP_ADDR "225.0.0.5" |
|
|
#define PORTRECV 8310 |
|
|
#define PORTRECV 8310 |
|
|
|
|
|
|
|
@ -30,8 +30,7 @@ int main(int argc, char *argv[]) |
|
|
int yes=1; |
|
|
int yes=1; |
|
|
unsigned char buf[64] = {0}; |
|
|
unsigned char buf[64] = {0}; |
|
|
|
|
|
|
|
|
signal(SIGTERM, sigterm); |
|
|
signal(SIGINT, sigterm); |
|
|
|
|
|
|
|
|
sock = socket(AF_INET,SOCK_DGRAM,0); |
|
|
sock = socket(AF_INET,SOCK_DGRAM,0); |
|
|
printf("sockfd: %d\n",sock); |
|
|
printf("sockfd: %d\n",sock); |
|
|
if (sock == -1) { |
|
|
if (sock == -1) { |
|
@ -46,7 +45,7 @@ int main(int argc, char *argv[]) |
|
|
|
|
|
|
|
|
memset(&ser_addr,0,sizeof(ser_addr)); |
|
|
memset(&ser_addr,0,sizeof(ser_addr)); |
|
|
ser_addr.sin_family = AF_INET; |
|
|
ser_addr.sin_family = AF_INET; |
|
|
ser_addr.sin_addr.s_addr = inet_addr(HOST_IF_IP); |
|
|
ser_addr.sin_addr.s_addr = INADDR_ANY;//inet_addr(GROUP_ADDR);
|
|
|
ser_addr.sin_port = htons(PORTRECV); |
|
|
ser_addr.sin_port = htons(PORTRECV); |
|
|
if (bind(sock,(struct sockaddr *) &ser_addr,sizeof(ser_addr)) < 0){ |
|
|
if (bind(sock,(struct sockaddr *) &ser_addr,sizeof(ser_addr)) < 0){ |
|
|
perror("bind"); |
|
|
perror("bind"); |
|
@ -60,7 +59,9 @@ int main(int argc, char *argv[]) |
|
|
close(sock); |
|
|
close(sock); |
|
|
exit(1); |
|
|
exit(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
myfile = fopen("output.raw", "w"); |
|
|
myfile = fopen("output.raw", "w"); |
|
|
|
|
|
|
|
|
while (!got_sig) { |
|
|
while (!got_sig) { |
|
|
slen = sizeof ser_addr; |
|
|
slen = sizeof ser_addr; |
|
|
memset(&ser_addr, 0, sizeof ser_addr); |
|
|
memset(&ser_addr, 0, sizeof ser_addr); |
|
@ -69,13 +70,15 @@ int main(int argc, char *argv[]) |
|
|
perror("recvfrom"); |
|
|
perror("recvfrom"); |
|
|
exit(1); |
|
|
exit(1); |
|
|
} |
|
|
} |
|
|
|
|
|
printf("recv data %d\n", count); |
|
|
if (count == 64) { |
|
|
if (count == 64) { |
|
|
if (buf[0] == 0xac && buf[1] == 0x93 && buf[63] == 0x14) { |
|
|
if (buf[0] == 0xac && buf[1] == 0x93 && buf[63] == 0x14) { |
|
|
fwrite(buf + 16, 1, 6, myfile); |
|
|
fwrite(buf + 16, 1, 6, myfile); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
//fflush(myfile);
|
|
|
} |
|
|
} |
|
|
|
|
|
printf("---------------\n"); |
|
|
fclose(myfile); |
|
|
fclose(myfile); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|