summaryrefslogtreecommitdiff
path: root/latency.c
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2016-07-08 09:24:12 +0100
committerFrediano Ziglio <fziglio@redhat.com>2016-07-08 09:24:12 +0100
commit55b65d04b5ed1313c5d250d5f26b5e8a3abfb321 (patch)
treea6e17312e4e222b40d45b3b8ceb7e21df441e8d2 /latency.c
parent40530cc27cf1a36179993a70ef2237827b6b392a (diff)
use tun/tap instead of normal sockets
Diffstat (limited to 'latency.c')
-rw-r--r--latency.c74
1 files changed, 5 insertions, 69 deletions
diff --git a/latency.c b/latency.c
index a54b8bf..fab0a8b 100644
--- a/latency.c
+++ b/latency.c
@@ -49,14 +49,13 @@ setup_signals(void)
signal(SIGCHLD, sig_chld);
}
-int connect_port;
uint64_t latency_us;
unsigned rate_bytes;
static void
usage(void)
{
- fprintf(stderr, "syntax: latency <listen_port> <connect_port> <latency> <rate>\n");
+ fprintf(stderr, "syntax: latency <latency> <rate>\n");
exit(EXIT_FAILURE);
}
@@ -86,77 +85,14 @@ main(int argc, char **argv)
{
tun_fd = tun_setup();
- handle_tun(tun_fd);
- return 1;
-
- if (argc < 5)
- usage();
-
- int listen_port = atoi(argv[1]);
- connect_port = atoi(argv[2]);
- latency_us = parse_value(argv[3], 0, 10000000, latency_units);
- rate_bytes = parse_value(argv[4], 1, INT_MAX, rate_units);
-
- if (listen_port <= 0 || connect_port <= 0
- || listen_port > 0xffff || connect_port > 0xffff
- || listen_port == connect_port)
+ if (argc < 3)
usage();
- int sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock == -1) {
- perror("socket");
- exit(EXIT_FAILURE);
- }
-
- int on = 1;
- setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
-
- struct sockaddr_in sin;
- sin.sin_family = AF_INET;
- sin.sin_port = htons(listen_port);
- sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- if (bind(sock, (struct sockaddr*) &sin, sizeof(sin)) < 0) {
- perror("bind");
- exit(EXIT_FAILURE);
- }
-
- if (listen(sock, 5) < 0) {
- perror("listen");
- exit(EXIT_FAILURE);
- }
+ latency_us = parse_value(argv[1], 0, 10000000, latency_units);
+ rate_bytes = parse_value(argv[2], 1, INT_MAX, rate_units);
setup_signals();
- unsigned connection_id = 0;
- while (!term) {
- int fd = accept(sock, NULL, NULL);
- if (fd == -1) {
- if (term)
- break;
- perror("accept");
- continue;
- }
-
- setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
-
- switch (fork()) {
- case -1:
- perror("fork");
- close(fd);
- break;
- case 0:
- /* child */
- close(sock);
- signal(SIGTERM, SIG_DFL);
- signal(SIGINT, SIG_DFL);
- handle_client(fd, ++connection_id);
- exit(EXIT_SUCCESS);
- break;
- default:
- /* parent */
- close(fd);
- break;
- }
- }
+ handle_tun(tun_fd);
return EXIT_SUCCESS;
}