tests: Tidy up loopback adapter tests
[openafs.git] / tests / common / network.c
1 #include <afsconfig.h>
2 #include <afs/param.h>
3
4 #include <roken.h>
5
6 #include <afs/cellconfig.h>
7 #include <rx/rx.h>
8
9 #include <tests/tap/basic.h>
10 #include "common.h"
11
12 /*! Check if the current machine's hostname resolves to the loopback
13  * network.
14  */
15 int
16 afstest_IsLoopbackNetworkDefault(void) {
17   char hostname[MAXHOSTCHARS];
18   afs_uint32 addr;
19   struct hostent *host;
20
21   gethostname(hostname, sizeof(hostname));
22   host = gethostbyname(hostname);
23   memcpy(&addr, host->h_addr, sizeof(addr));
24
25   return(rx_IsLoopbackAddr(ntohl(addr)));
26 }
27
28 /*! Skips all TAP tests if the current machine's hostname resolves to the
29  * loopback network.
30  */
31 int
32 afstest_SkipTestsIfLoopbackNetIsDefault(void) {
33   int retval=0;
34   retval=afstest_IsLoopbackNetworkDefault();
35   if(retval==1) {
36     skip_all("Default IP address is on the loopback network!\n");
37   }
38
39   return retval;
40 }