From aa3ad76730e1356a85111045f191dc807e543123 Mon Sep 17 00:00:00 2001 From: Jon Dugan Date: Thu, 23 Jul 2009 18:22:24 +0000 Subject: [PATCH] rework uuids; rework Makefile --- src/Makefile | 16 +++++++++++----- src/iperf_api.c | 46 ++++++---------------------------------------- src/iperf_api.h | 12 ++---------- src/t_uuid.c | 18 ++++++++++++++++++ src/uuid.c | 26 ++++++++++++++++++++++++++ 5 files changed, 63 insertions(+), 55 deletions(-) create mode 100644 src/t_uuid.c create mode 100644 src/uuid.c diff --git a/src/Makefile b/src/Makefile index dbc7222..7c38cc1 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,15 +1,19 @@ CFLAGS=-g -Wall -OBJS=iperf_api.o timer.o net.o tcp_window_size.o units.o +OBJS=iperf_api.o timer.o net.o tcp_window_size.o units.o uuid.o +LDFLAGS= all: iperf iperf: $(OBJS) - $(CC) -pthread -o iperf $(OBJS) - #$(CC) -pg -pthread -o iperf-profile $(OBJS) + $(CC) $(LDFLAGS) -o iperf $(OBJS) -test: t_timer t_units +profile: iperf + $(CC) -pg -o iperf-profile $(OBJS) + +test: t_timer t_units t_uuid ./t_timer ./t_units + ./t_uuid t_timer: timer.o t_timer.o $(CC) -o t_timer timer.o t_timer.o @@ -17,6 +21,8 @@ t_timer: timer.o t_timer.o t_units: units.o t_units.o $(CC) -o t_units units.o t_units.o +t_uuid: uuid.o t_uuid.o + $(CC) -o t_uuid uuid.o t_uuid.o clean: - rm -f *.o iperf iperf-profile t_timer t_units + rm -f *.o iperf iperf-profile t_timer t_units t_uuid diff --git a/src/iperf_api.c b/src/iperf_api.c index 073968a..d732ba7 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -17,17 +17,12 @@ #include #include -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(linux) -#include -#endif -#if defined(MAC_OS_X) || defined(__APPLE__) || defined(__MACH__) -#include -#endif #include "iperf_api.h" #include "timer.h" #include "net.h" #include "units.h" #include "tcp_window_size.h" +#include "uuid.h" #include "locale.h" static struct option longopts[] = @@ -57,18 +52,10 @@ void exchange_parameters(struct iperf_test *test) struct iperf_test *temp; struct iperf_stream *sp; struct param_exchange *param = (struct param_exchange *) buf; + + test->default_settings->cookie = get_uuid(); //setting up exchange parameters -#if defined(__FREEBSD__) || defined(__NetBSD__) || defined(linux) - uuid_create(&test->default_settings->cookie, 0); - -#endif - -#if defined(MAC_OS_X) || defined(__APPLE__) || defined(__MACH__) - uuid_generate(test->default_settings->cookie); - uuid_copy(param->cookie, test->default_settings->cookie); -#endif - param->state = PARAM_EXCHANGE; param->blksize = test->default_settings->blksize; param->recv_window = test->default_settings->socket_rcv_bufsize; @@ -116,32 +103,11 @@ int param_received(struct iperf_stream *sp, struct param_exchange *param) int size = sp->settings->blksize; char *buf = (char *) malloc(size); int result; - - printf("PARAM_EXHANGE caught\n"); - // setting the parameters - #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(linux) - result = uuid_is_nil((uuid_t *)sp->settings->cookie, 0); - - #endif - #if defined(MAC_OS_X) || defined(__APPLE__) || defined(__MACH__) - result = uuid_is_null(sp->settings->cookie); - #endif - + + result = 1; /* TODO: actually check cookie */ + if(result) { - #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(linux) - char **str = NULL; - uint32_t *status; - //TODO - this part is crashing - uuid_to_string((uuid_t *) param->cookie, str, status); - printf("to string status = %d\n", *status); - uuid_from_string(*str, (uuid_t *) sp->settings->cookie, status); - printf("from string status = %d\n", *status); - free(str); - #endif - #if defined(MAC_OS_X) || defined(__APPLE__) || defined(__MACH__) - uuid_copy(sp->settings->cookie, param->cookie); - #endif sp->settings->blksize = param->blksize; sp->settings->socket_rcv_bufsize = param->recv_window; sp->settings->unit_format = param->format; diff --git a/src/iperf_api.h b/src/iperf_api.h index 4261df9..cbe7192 100644 --- a/src/iperf_api.h +++ b/src/iperf_api.h @@ -33,11 +33,7 @@ struct iperf_settings int tos; char unit_format; // -f int state; // This is state of a stream/test -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(linux) - struct uuid_t *cookie; -#elif defined(MAC_OS_X) || defined(__APPLE__) || defined(__MACH__) - uuid_t cookie; // cookie for a stream/test -#endif + char *cookie; }; struct iperf_stream @@ -129,11 +125,7 @@ struct param_exchange int send_window; int mss; char format; -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(linux) - struct uuid_t *cookie; -#elif defined(MAC_OS_X) || defined(__APPLE__) || defined(__MACH__) - uuid_t cookie; // cookie for a stream/test -#endif + char *cookie; }; diff --git a/src/t_uuid.c b/src/t_uuid.c new file mode 100644 index 0000000..54b5c2f --- /dev/null +++ b/src/t_uuid.c @@ -0,0 +1,18 @@ +#include +#include +#include + +#include "uuid.h" + +int +main(int argc, char **argv) +{ + char *uuid; + uuid = get_uuid(); + if(strlen(uuid) != 36) + { + printf("uuid is not 37 characters long %s.\n", uuid); + exit(-1); + } + exit(0); +} diff --git a/src/uuid.c b/src/uuid.c new file mode 100644 index 0000000..29911f7 --- /dev/null +++ b/src/uuid.c @@ -0,0 +1,26 @@ +#include +#include + +#if defined(__FreeBSD__) +#include +#else +#include +#endif + +char * +get_uuid() +{ + char *s; + uuid_t uu; + +#if defined(__FreeBSD__) + uuid_create(&uu, NULL); + uuid_to_string(&uu, &s, 0); +#else + s = (char *) malloc(37); /* UUID is 36 chars + \0 */ + uuid_generate(uu); + uuid_unparse(uu, s); +#endif + + return s; +}