5443b67ebbedf81ee2490e7efa38aef989c5c9f1
6 #include <netinet/in.h>
11 #include <sys/socket.h>
12 #include <sys/types.h>
14 #include <linux/udp.h>
22 void sigalarm(int junk
);
23 unsigned long long recv_count
= 0;
24 unsigned long pps
= 0;
25 unsigned long bytes
= 0;
26 unsigned long dropped
= 0, seq
= 0;
29 int main(int argc
, char *argv
[])
32 struct sockaddr_in addr
;
36 while ((s
= getopt(argc
, argv
, "?p:")) > 0)
45 printf("\t-p port to listen on\n");
51 memset(&addr
, 0, sizeof(addr
));
52 addr
.sin_family
= AF_INET
;
53 addr
.sin_port
= htons(port
);
55 s
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
56 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
57 if (bind(s
, (void *) &addr
, sizeof(addr
)) < 0)
63 signal(SIGALRM
, sigalarm
);
66 printf("Waiting on port %d\n", port
);
67 packet
= (char *)malloc(65535);
70 struct sockaddr_in addr
;
71 int alen
= sizeof(addr
), l
;
74 l
= recvfrom(s
, packet
, 65535, 0, (void *) &addr
, &alen
);
79 iseq
= *((unsigned int *) packet
);
81 dropped
+= (iseq
- seq
);
84 sendto(s
, packet
, l
, 0, (struct sockaddr
*)&addr
, alen
);
90 void sigalarm(int junk
)
92 printf("Recv: %10llu %0.1fMbits/s (%lu pps) (%5ld dropped)\n", recv_count
, (bytes
/ 1024.0 / 1024.0 * 8), pps
, dropped
);