+void *sender_worker(void *arg)
+{
+ unsigned i;
+ int sock;
+ char buf[65536];
+
+ for (i = 0; i < 65536; ++i)
+ buf[i] = rand() & 0xff;
+
+ for (i = 0; i < 1000; ++i) {
+ unsigned src_num = (unsigned)(num_sources * gen_uniform_random());
+ unsigned dst_num = (unsigned)(num_destinations * gen_uniform_random());
+ unsigned num_bytes = (unsigned)gen_pareto_random(1048576.0, 1.0);
+ struct sockaddr_in sin;
+
+ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (sock == -1) {
+ perror("socket()");
+ exit(1);
+ }
+
+ // FIXME: bind to the right source
+
+ sin.sin_family = AF_INET;
+ sin.sin_port = htons(port);
+ sin.sin_addr = destinations[dst_num];
+
+ fprintf(stderr, "connecting %u\n", i);
+
+ if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
+ perror("connect()");
+ exit(1);
+ }
+
+ fprintf(stderr, "connected\n");
+
+ while (num_bytes > 0) {
+ unsigned bytes_to_send = num_bytes;
+ unsigned ret;
+
+ if (bytes_to_send > 65536) {
+ bytes_to_send = 65536;
+ }
+
+ ret = send(sock, buf, bytes_to_send, MSG_NOSIGNAL);
+ if (ret == -1) {
+ perror("send()");
+ exit(1);
+ }
+
+ num_bytes -= ret;
+ }
+ fprintf(stderr, "sent\n");
+
+ close(sock);
+ }
+
+ pthread_exit(0);
+}
+