9d3f334e9f52d07d6e96c9ce49df92e98e84a96e
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;
28 int main(int argc
, char *argv
[])
31 struct sockaddr_in addr
;
35 while ((s
= getopt(argc
, argv
, "?p:")) > 0)
44 printf("\t-p port to listen on\n");
50 memset(&addr
, 0, sizeof(addr
));
51 addr
.sin_family
= AF_INET
;
52 addr
.sin_port
= htons(port
);
54 s
= socket(AF_INET
, SOCK_DGRAM
, IPPROTO_UDP
);
55 setsockopt(s
, SOL_SOCKET
, SO_REUSEADDR
, &on
, sizeof(on
));
56 if (bind(s
, (void *) &addr
, sizeof(addr
)) < 0)
62 signal(SIGALRM
, sigalarm
);
65 printf("Waiting on port %d\n", port
);
66 packet
= (char *)malloc(65535);
69 struct sockaddr_in addr
;
70 int alen
= sizeof(addr
), l
;
72 l
= recvfrom(s
, packet
, 65535, 0, (void *) &addr
, &alen
);
78 sendto(s
, packet
, l
, 0, (struct sockaddr
*)&addr
, alen
);
84 void sigalarm(int junk
)
86 printf("Recv: %10llu %0.1fMbits/s (%lu pps)\n", recv_count
, (bytes
/ 1024.0 / 1024.0 * 8), pps
);