rework uuids; rework Makefile

This commit is contained in:
Jon Dugan 2009-07-23 18:22:24 +00:00
parent a294fbda37
commit aa3ad76730
5 changed files with 63 additions and 55 deletions

View File

@ -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

View File

@ -17,17 +17,12 @@
#include <netinet/tcp.h>
#include <sys/time.h>
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(linux)
#include <uuid.h>
#endif
#if defined(MAC_OS_X) || defined(__APPLE__) || defined(__MACH__)
#include <uuid/uuid.h>
#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[] =
@ -58,17 +53,9 @@ void exchange_parameters(struct iperf_test *test)
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;
@ -117,31 +104,10 @@ int param_received(struct iperf_stream *sp, struct param_exchange *param)
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;

View File

@ -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;
};

18
src/t_uuid.c Normal file
View File

@ -0,0 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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);
}

26
src/uuid.c Normal file
View File

@ -0,0 +1,26 @@
#include <stdio.h>
#include <stdlib.h>
#if defined(__FreeBSD__)
#include <uuid.h>
#else
#include <uuid/uuid.h>
#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;
}