From: Steinar H. Gunderson Date: Mon, 28 May 2012 12:02:09 +0000 (+0200) Subject: Add a simple receiver. X-Git-Url: https://git.sesse.net/?p=bursty;a=commitdiff_plain;h=77619ebfbb5ec81963d0cfc2506b8c59d2523abe Add a simple receiver. --- diff --git a/receiver.c b/receiver.c new file mode 100644 index 0000000..b4c0759 --- /dev/null +++ b/receiver.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PACKET_SIZE 1200 + + +int main(int argc, char **argv) +{ + int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + struct sockaddr_in addr; + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = inet_addr(argv[1]); + addr.sin_port = htons(atoi(argv[2])); + + bind(sock, (struct sockaddr *)&addr, sizeof(addr)); + listen(sock, 255); + + for ( ;; ) { + static char buf[PACKET_SIZE]; + int seqno; + ssize_t len = recv(sock, buf, PACKET_SIZE, 0); + if (len == -1) { + perror("recv"); + exit(1); + } + if (len < sizeof(int)) { + fprintf(stderr, "short packet\n"); + continue; + } + memcpy(&seqno, buf, sizeof(int)); + printf("%d\n", seqno); + } +}