]> git.sesse.net Git - bursty/blob - receiver.c
Fix some corruption issues in truncate-end.pl.
[bursty] / receiver.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <stdlib.h>
4 #include <unistd.h>
5 #include <sys/socket.h>
6 #include <sys/types.h>
7 #include <time.h>
8 #include <netinet/in.h>
9 #include <arpa/inet.h>
10
11 #define PACKET_SIZE 1200
12
13
14 int main(int argc, char **argv)
15 {
16         int sock = socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);
17         struct sockaddr_in6 addr;
18         addr.sin6_family = AF_INET6;
19         addr.sin6_port = htons(atoi(argv[2]));
20
21         inet_pton(AF_INET6, argv[1], &addr.sin6_addr);
22
23         bind(sock, (struct sockaddr *)&addr, sizeof(addr));
24         listen(sock, 255);
25
26         for ( ;; ) {
27                 static char buf[PACKET_SIZE];
28                 int seqno;
29                 ssize_t len = recv(sock, buf, PACKET_SIZE, 0);
30                 if (len == -1) {
31                         perror("recv");
32                         exit(1);
33                 }
34                 if (len < sizeof(int)) {
35                         fprintf(stderr, "short packet\n");
36                         continue;
37                 }
38                 memcpy(&seqno, buf, sizeof(int));
39                 printf("%d\n", seqno);
40         }
41 }