From: Steinar H. Gunderson Date: Mon, 28 May 2012 11:42:59 +0000 (+0200) Subject: Initial commit of sender. X-Git-Url: https://git.sesse.net/?p=bursty;a=commitdiff_plain;h=9c2b44297d8d28944ccf973c4c71f372228713aa Initial commit of sender. --- 9c2b44297d8d28944ccf973c4c71f372228713aa diff --git a/sender.c b/sender.c new file mode 100644 index 0000000..826bb1d --- /dev/null +++ b/sender.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PACKET_SIZE 1200 + +static int burst_sizes[] = { 1, 2, 3, 5, 10, 20, 50, 100 }; +static int num_burst_sizes = sizeof(burst_sizes) / sizeof(burst_sizes[0]); + +static void send_burst(int sock, const struct sockaddr *addr, socklen_t addr_len, int burst_size) +{ + static char buf[PACKET_SIZE] = { 0 }; + static int pkt_num = 0; + int i; + + for (i = 0; i < burst_size; ++i) { + ++pkt_num; + printf("%d ", pkt_num); + memcpy(buf, &pkt_num, sizeof(pkt_num)); + sendto(sock, buf, PACKET_SIZE, 0, addr, addr_len); + } + printf("\n"); +} + +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])); + + srand(time(NULL)); + + for ( ;; ) { + int burst_size = burst_sizes[rand() % num_burst_sizes]; + send_burst(sock, (struct sockaddr *)&addr, sizeof(addr), burst_size); + sleep(1); + } +}