From 70c4369e893d6770f0f7b243c3e840c32b5a2a2b Mon Sep 17 00:00:00 2001 From: Jason Edgecombe Date: Fri, 21 Sep 2012 23:14:37 -0400 Subject: [PATCH] TESTS: Add a library to check for the default loopback network Change-Id: Id7bb92345e97309363fa5ddbff9147edf30ccd96 Reviewed-on: http://gerrit.openafs.org/8145 Reviewed-by: Marc Dionne Tested-by: BuildBot Reviewed-by: Derrick Brashear --- tests/common/Makefile.in | 5 +++-- tests/common/common.h | 4 ++++ tests/common/network.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/common/network.c diff --git a/tests/common/Makefile.in b/tests/common/Makefile.in index 11708e1..2909f61 100644 --- a/tests/common/Makefile.in +++ b/tests/common/Makefile.in @@ -4,9 +4,10 @@ abs_top_builddir=@abs_top_builddir@ include @TOP_OBJDIR@/src/config/Makefile.config include @TOP_OBJDIR@/src/config/Makefile.pthread -MODULE_CFLAGS=-I$(srcdir)/.. +MODULE_CFLAGS=-I$(srcdir)/.. -I$(srcdir)/../.. +CFLAGS_network.o = -Wno-strict-prototypes -all check test tests: config.o servers.o ubik.o rxkad.o +all check test tests: config.o servers.o ubik.o rxkad.o network.o clean: rm -f *.o diff --git a/tests/common/common.h b/tests/common/common.h index 9782a98..cf19692 100644 --- a/tests/common/common.h +++ b/tests/common/common.h @@ -50,3 +50,7 @@ extern int afstest_GetUbikClient(struct afsconf_dir *dir, char *service, struct rx_securityClass *secClass, int secIndex, struct ubik_client **ubikClient); + +/* network.c */ +extern int afstest_IsLoopbackNetworkDefault(void); +extern int afstest_SkipTestsIfLoopbackNetIsDefault(void); diff --git a/tests/common/network.c b/tests/common/network.c new file mode 100644 index 0000000..e605b28 --- /dev/null +++ b/tests/common/network.c @@ -0,0 +1,44 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include "common.h" + +extern int h_errno; + +/*! Check if the current machine's hostname resolves to the loopback + * network. + */ +int +afstest_IsLoopbackNetworkDefault(void) { + char hostname[MAXHOSTCHARS]; + afs_uint32 addr; + struct hostent *host; + + gethostname(hostname, sizeof(hostname)); + host = gethostbyname(hostname); + memcpy(&addr, host->h_addr, sizeof(addr)); + + return(rx_IsLoopbackAddr(ntohl(addr))); +} + +/*! Skips all TAP tests if the current machine's hostname resolves to the + * loopback network. + */ +int +afstest_SkipTestsIfLoopbackNetIsDefault(void) { + int retval=0; + retval=afstest_IsLoopbackNetworkDefault(); + if(retval==1) { + skip_all("Default IP address is on the loopback network!\n"); + } + + return retval; +} -- 1.9.4