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