openafs/tests/common/network.c
Marc Dionne 0a528a52f5 tests: Improve failure mode for unresolvable hostname
In the case of a host where gethostbyname is unable to resolve
the hostname, afstest_BuildTestConfig() may return NULL which
can cause several tests to crash.

Add a common function to look out for this condition and use it where
appropriate.  When it occurs, the current module is skipped and
the user gets an error message that indicates the configuration
problem.

Change-Id: I7216876eb2424368f415e5759e2b95009ad055b2
Reviewed-on: http://gerrit.openafs.org/9120
Reviewed-by: Derrick Brashear <shadow@your-file-system.com>
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
2013-02-17 20:51:15 -08:00

64 lines
1.3 KiB
C

#include <afsconfig.h>
#include <afs/param.h>
#include <roken.h>
#include <afs/cellconfig.h>
#include <rx/rx.h>
#include <tests/tap/basic.h>
#include "common.h"
/*!
* 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);
if (!host) {
skip_all("Can't resolve hostname %s\n", 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;
retval = afstest_IsLoopbackNetworkDefault();
if (retval == 1) {
skip_all("Default IP address is on the loopback network!\n");
}
return retval;
}
/*!
* Skips all TAP tests if the current machine's hostname can't be resolved
* to any IP address.
*/
void
afstest_SkipTestsIfBadHostname(void)
{
char hostname[MAXHOSTCHARS];
struct hostent *host;
gethostname(hostname, sizeof(hostname));
host = gethostbyname(hostname);
if (!host)
skip_all("Can't resolve hostname %s\n", hostname);
}