configure: fix comment about unix variants
[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 /*!
13  * Check if the current machine's hostname resolves to the loopback
14  * network.
15  */
16 int
17 afstest_IsLoopbackNetworkDefault(void)
18 {
19     char hostname[MAXHOSTCHARS];
20     afs_uint32 addr;
21     struct hostent *host;
22
23     gethostname(hostname, sizeof(hostname));
24     host = gethostbyname(hostname);
25     if (!host) {
26         skip_all("Can't resolve hostname %s\n", hostname);
27     }
28     memcpy(&addr, host->h_addr, sizeof(addr));
29
30     return(rx_IsLoopbackAddr(ntohl(addr)));
31 }
32
33 /*!
34  * Skips all TAP tests if the current machine's hostname resolves to the
35  * loopback network.
36  */
37 int
38 afstest_SkipTestsIfLoopbackNetIsDefault(void)
39 {
40     int retval;
41
42     retval = afstest_IsLoopbackNetworkDefault();
43     if (retval == 1) {
44         skip_all("Default IP address is on the loopback network!\n");
45     }
46     return retval;
47 }
48
49 /*!
50  * Skips all TAP tests if the current machine's hostname can't be resolved
51  * to any IP address.
52  */
53 void
54 afstest_SkipTestsIfBadHostname(void)
55 {
56     char hostname[MAXHOSTCHARS];
57     struct hostent *host;
58
59     gethostname(hostname, sizeof(hostname));
60     host = gethostbyname(hostname);
61     if (!host)
62         skip_all("Can't resolve hostname %s\n", hostname);
63 }