diff --git a/common/utils/T/tracer/defs.h b/common/utils/T/tracer/defs.h index 7a6f57b312b0a26fd3a0cc413e83692af385b4d5..498f9e5b790847fdaa0d7b897da77d5234eab8f2 100644 --- a/common/utils/T/tracer/defs.h +++ b/common/utils/T/tracer/defs.h @@ -16,7 +16,7 @@ void iq_plot_set_sized(void *_plot, short *data, int len, int pp); void iq_plot_add_iq_point_loop(void *_plot, short i, short q, int pp); void iq_plot_add_energy_point_loop(void *_plot, int e, int pp); -void *forwarder(char *ip, int port); +void *forwarder(int port); void forward(void *forwarder, char *buf, int size); void forward_start_client(void *forwarder, int socket); diff --git a/common/utils/T/tracer/enb.c b/common/utils/T/tracer/enb.c index b370962e9dee749115df4a27f6cdb3c58dbb96a5..c80fd9bda330829bbe16cf05d8b1fe4cdf3fc310 100644 --- a/common/utils/T/tracer/enb.c +++ b/common/utils/T/tracer/enb.c @@ -19,6 +19,7 @@ typedef struct { view *legacy; } enb_gui; +#define DEFAULT_REMOTE_IP "127.0.0.1" #define DEFAULT_REMOTE_PORT 2021 void usage(void) @@ -33,8 +34,10 @@ void usage(void) " note: you may pass several -on/-off/-ON/-OFF,\n" " they will be processed in order\n" " by default, all is off\n" -" -p <port> use given port (default %d)\n" +" -ip <host> connect to given IP address (default %s)\n" +" -p <port> connect to given port (default %d)\n" " -debug-gui activate GUI debug logs\n", + DEFAULT_REMOTE_IP, DEFAULT_REMOTE_PORT ); exit(1); @@ -204,6 +207,7 @@ int main(int n, char **v) extern int volatile gui_logd; char *database_filename = NULL; void *database; + char *ip = DEFAULT_REMOTE_IP; int port = DEFAULT_REMOTE_PORT; char **on_off_name; int *on_off_action; @@ -225,6 +229,7 @@ int main(int n, char **v) if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); if (!strcmp(v[i], "-d")) { if (i > n-2) usage(); database_filename = v[++i]; continue; } + if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; } if (!strcmp(v[i], "-p")) { if (i > n-2) usage(); port = atoi(v[++i]); continue; } if (!strcmp(v[i], "-on")) { if (i > n-2) usage(); @@ -341,7 +346,7 @@ int main(int n, char **v) for (i = 0; i < on_off_n; i++) on_off(database, on_off_name[i], is_on, on_off_action[i]); - s = get_connection("0.0.0.0", port); + s = connect_to(ip, port); /* send the first message - activate selected traces */ t = 0; diff --git a/common/utils/T/tracer/forward.c b/common/utils/T/tracer/forward.c index 840f9fbc35297483ad625f80b1424f526432b3eb..e9eb93e1bb1490ba06a2b026ff23ba26c17d0131 100644 --- a/common/utils/T/tracer/forward.c +++ b/common/utils/T/tracer/forward.c @@ -102,10 +102,11 @@ void forward_start_client(void *_f, int s) new_thread(forward_s_to_sc, f); } -void *forwarder(char *ip, int port) +int get_connection(char *addr, int port); + +void *forwarder(int port) { forward_data *f; - struct sockaddr_in a; f = malloc(sizeof(*f)); if (f == NULL) abort(); @@ -119,23 +120,9 @@ void *forwarder(char *ip, int port) f->memusage = 0; f->last_warning_memusage = 0; - printf("connecting to remote tracer %s:%d\n", ip, port); - -again: - f->s = socket(AF_INET, SOCK_STREAM, 0); - if (f->s == -1) { perror("socket"); exit(1); } + printf("waiting for remote tracer on port %d\n", port); - 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"); - close(f->s); - printf("trying again in 1s\n"); - sleep(1); - goto again; - } + f->s = get_connection("127.0.0.1", port); printf("connected\n"); diff --git a/common/utils/T/tracer/local.c b/common/utils/T/tracer/local.c index 8f60eca34098529fe23e6ad23b7a09efd7add016..1648ae7d6036b1441b4c91bb9655bf90f05d7496 100644 --- a/common/utils/T/tracer/local.c +++ b/common/utils/T/tracer/local.c @@ -9,8 +9,7 @@ #include <fcntl.h> #include <pthread.h> -#define DEFAULT_REMOTE_IP "127.0.0.1" -#define DEFAULT_REMOTE_PORT 2021 +#define DEFAULT_PORT 2021 #include "defs.h" @@ -97,11 +96,9 @@ void usage(void) printf( "tracer - local side\n" "options:\n" -" -r <IP address> <port> forwards packets to remote IP:port\n" -" (default %s:%d)\n" -" -nowait don't wait for remote tracer,\n" -" start tracee immediately\n", - DEFAULT_REMOTE_IP, DEFAULT_REMOTE_PORT +" -p <port> wait for remote tracer on port <port> (default %d)\n" +" -nowait don't wait for remote tracer, start tracee immediately\n", + DEFAULT_PORT ); exit(1); } @@ -110,30 +107,29 @@ int main(int n, char **v) { int s; int i; - char *remote_ip = DEFAULT_REMOTE_IP; - int remote_port = DEFAULT_REMOTE_PORT; - int port = 2020; + int port = DEFAULT_PORT; + int local_port = 2020; int dont_wait = 0; void *f; for (i = 1; i < n; i++) { if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); - if (!strcmp(v[i], "-r")) { if (i > n-3) usage(); - remote_ip = v[++i]; remote_port = atoi(v[++i]); continue; } + if (!strcmp(v[i], "-p")) { if (i > n-2) usage(); + port = atoi(v[++i]); continue; } if (!strcmp(v[i], "-nowait")) { dont_wait = 1; continue; } printf("ERROR: unknown option %s\n", v[i]); usage(); } init_shm(); - s = get_connection("127.0.0.1", port); + s = get_connection("127.0.0.1", local_port); if (dont_wait) { char t = 2; if (write(s, &t, 1) != 1) abort(); } - f = forwarder(remote_ip, remote_port); + f = forwarder(port); forward_start_client(f, s); /* read messages */ diff --git a/common/utils/T/tracer/textlog.c b/common/utils/T/tracer/textlog.c index 9b1b4864600d332f491fcd97c2613777d0ead2a2..6ff36f650c476c9d96b27f8502d7cc5199603b65 100644 --- a/common/utils/T/tracer/textlog.c +++ b/common/utils/T/tracer/textlog.c @@ -13,6 +13,7 @@ #include "event_selector.h" #include "config.h" +#define DEFAULT_REMOTE_IP "127.0.0.1" #define DEFAULT_REMOTE_PORT 2021 void usage(void) @@ -27,10 +28,12 @@ void usage(void) " note: you may pass several -on/-off/-ON/-OFF,\n" " they will be processed in order\n" " by default, all is off\n" -" -p <port> use given port (default %d)\n" +" -ip <host> connect to given IP address (default %s)\n" +" -p <port> connect to given port (default %d)\n" " -x GUI output\n" " -debug-gui activate GUI debug logs\n" " -no-gui disable GUI entirely\n", + DEFAULT_REMOTE_IP, DEFAULT_REMOTE_PORT ); exit(1); @@ -48,6 +51,7 @@ int main(int n, char **v) extern int volatile gui_logd; char *database_filename = NULL; void *database; + char *ip = DEFAULT_REMOTE_IP; int port = DEFAULT_REMOTE_PORT; char **on_off_name; int *on_off_action; @@ -72,6 +76,7 @@ int main(int n, char **v) if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); if (!strcmp(v[i], "-d")) { if (i > n-2) usage(); database_filename = v[++i]; continue; } + if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; } if (!strcmp(v[i], "-p")) { if (i > n-2) usage(); port = atoi(v[++i]); continue; } if (!strcmp(v[i], "-on")) { if (i > n-2) usage(); @@ -136,7 +141,7 @@ int main(int n, char **v) for (i = 0; i < on_off_n; i++) on_off(database, on_off_name[i], is_on, on_off_action[i]); - s = get_connection("0.0.0.0", port); + s = connect_to(ip, port); /* send the first message - activate selected traces */ t = 0; diff --git a/common/utils/T/tracer/utils.c b/common/utils/T/tracer/utils.c index aac80e9fa588fb6e8990498a1bed462a8f9011d6..cb2e123fce1a2100a7beb8bdc2a713acaa629f3e 100644 --- a/common/utils/T/tracer/utils.c +++ b/common/utils/T/tracer/utils.c @@ -125,6 +125,32 @@ int fullread(int fd, void *_buf, int count) return ret; } +int connect_to(char *addr, int port) +{ + int s; + struct sockaddr_in a; + + printf("connecting to %s:%d\n", addr, port); + +again: + s = socket(AF_INET, SOCK_STREAM, 0); + if (s == -1) { perror("socket"); exit(1); } + + a.sin_family = AF_INET; + a.sin_port = htons(port); + a.sin_addr.s_addr = inet_addr(addr); + + if (connect(s, (struct sockaddr *)&a, sizeof(a)) == -1) { + perror("connect"); + close(s); + printf("trying again in 1s\n"); + sleep(1); + goto again; + } + + return s; +} + /****************************************************************************/ /* buffer */ /****************************************************************************/ diff --git a/common/utils/T/tracer/utils.h b/common/utils/T/tracer/utils.h index cdee2e0bc95bf950330c90ad2ebade5fe4c75191..00193b9eeb03fe74b68e7da1ced8bad0da554025 100644 --- a/common/utils/T/tracer/utils.h +++ b/common/utils/T/tracer/utils.h @@ -23,6 +23,7 @@ list *list_append(list *l, void *data); void socket_send(int socket, void *buffer, int size); int get_connection(char *addr, int port); int fullread(int fd, void *_buf, int count); +int connect_to(char *addr, int port); /****************************************************************************/ /* buffer */ diff --git a/common/utils/T/tracer/vcd.c b/common/utils/T/tracer/vcd.c index 4d36db59dfd293403ff707973b7ae684adfaec13..bf66bddd29e0590d1862ab253251f224ae20ce99 100644 --- a/common/utils/T/tracer/vcd.c +++ b/common/utils/T/tracer/vcd.c @@ -13,6 +13,7 @@ #include "event_selector.h" #include "config.h" +#define DEFAULT_REMOTE_IP "127.0.0.1" #define DEFAULT_REMOTE_PORT 2021 void usage(void) @@ -27,8 +28,10 @@ void usage(void) " note: you may pass several -on/-off/-ON/-OFF,\n" " they will be processed in order\n" " by default, all is off\n" -" -p <port> use given port (default %d)\n" +" -ip <host> connect to given IP address (default %s)\n" +" -p <port> connect to given port (default %d)\n" " -debug-gui activate GUI debug logs\n", + DEFAULT_REMOTE_IP, DEFAULT_REMOTE_PORT ); exit(1); @@ -88,6 +91,7 @@ int main(int n, char **v) extern int volatile gui_logd; char *database_filename = NULL; void *database; + char *ip = DEFAULT_REMOTE_IP; int port = DEFAULT_REMOTE_PORT; char **on_off_name; int *on_off_action; @@ -108,6 +112,7 @@ int main(int n, char **v) if (!strcmp(v[i], "-h") || !strcmp(v[i], "--help")) usage(); if (!strcmp(v[i], "-d")) { if (i > n-2) usage(); database_filename = v[++i]; continue; } + if (!strcmp(v[i], "-ip")) { if (i > n-2) usage(); ip = v[++i]; continue; } if (!strcmp(v[i], "-p")) { if (i > n-2) usage(); port = atoi(v[++i]); continue; } if (!strcmp(v[i], "-on")) { if (i > n-2) usage(); @@ -147,7 +152,7 @@ int main(int n, char **v) for (i = 0; i < on_off_n; i++) on_off(database, on_off_name[i], is_on, on_off_action[i]); - s = get_connection("0.0.0.0", port); + s = connect_to(ip, port); /* send the first message - activate selected traces */ t = 0;