From cb2454cca3bbe3aaacafdf2ee02a068611885fd2 Mon Sep 17 00:00:00 2001 From: Cedric Roux <cedric.roux@eurecom.fr> Date: Sun, 20 Mar 2016 00:23:15 +0100 Subject: [PATCH] first version of forwarder to be redone (the local tracer shall not configure the tracee by itself but only forward what the remote tracer sends) --- tracer/forward.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tracer/forward.c b/tracer/forward.c index 77ee156751..9e0df61fbf 100644 --- a/tracer/forward.c +++ b/tracer/forward.c @@ -1,10 +1,42 @@ #include "defs.h" +#include <stdlib.h> +#include <stdio.h> +#include <netinet/ip.h> +#include <arpa/inet.h> +#include <unistd.h> + +typedef struct { + int s; +} forward_data; void *forwarder(char *ip, int port) { - return 0; + forward_data *f; + struct sockaddr_in a; + + f = malloc(sizeof(*f)); if (f == NULL) abort(); + + f->s = socket(AF_INET, SOCK_STREAM, 0); + if (f->s == -1) { perror("socket"); exit(1); } + + a.sin_family = AF_INET; + a.sin_port = htons(port); + a.sin_addr.s_addr = inet_addr(ip); + + if (connect(f->s, (struct sockaddr *)&a, sizeof(a)) == -1) + { perror("connect"); exit(1); } + + return f; } -void forward(void *_fowarder, char *buf, int size) +void forward(void *_forwarder, char *buf, int size) { + forward_data *f = _forwarder; + + while (size) { + int l = write(f->s, buf, size); + if (l <= 0) { printf("forward error\n"); exit(1); } + size -= l; + buf += l; + } } -- GitLab