This source file includes following definitions.
- test_ifaddrtoname
- main
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 #include "ompi_config.h"
  20 
  21 #include <stdio.h>
  22 #include <string.h>
  23 #include <stdlib.h>
  24 #ifdef HAVE_SYS_PARAM_H
  25 #include <sys/param.h>
  26 #endif
  27 #ifdef HAVE_NETINET_IN_H
  28 #include <netinet/in.h>
  29 #endif
  30 #ifdef HAVE_UNISTD_H
  31 #include <unistd.h>
  32 #endif
  33 #ifdef HAVE_NETDB_H
  34 #include <netdb.h>
  35 #endif
  36 
  37 #include "support.h"
  38 #include "opal/runtime/opal.h"
  39 #include "opal/util/if.h"
  40 #include "opal/constants.h"
  41 
  42 
  43 static bool
  44 test_ifaddrtoname(char *addr)
  45 {
  46     int ret;
  47     char addrname[100];
  48     int len = 99;
  49 
  50     ret = opal_ifaddrtoname(addr, addrname, len);
  51 
  52     if (ret == OPAL_SUCCESS) {
  53         return true;
  54     } else {
  55         return false;
  56     }
  57 }
  58 
  59 int
  60 main(int argc, char *argv[])
  61 {
  62     char hostname[OPAL_MAXHOSTNAMELEN];
  63 
  64     opal_init(&argc, &argv);
  65     test_init("opal_if");
  66 
  67     
  68     if (test_ifaddrtoname("127.0.0.1")) {
  69         test_success();
  70     } else {
  71         test_failure("ifaddrtoname test failed for 127.0.0.1");
  72     }
  73     if (opal_ifislocal("127.0.0.1")) {
  74         test_success();
  75     } else {
  76         test_failure("ifislocal test failed for 127.0.0.1");
  77     }
  78 
  79     
  80     if (test_ifaddrtoname("localhost")) {
  81         test_success();
  82     } else {
  83         test_failure("ifaddrtoname test failed for localhost");
  84     }
  85     if (opal_ifislocal("localhost")) {
  86         test_success();
  87     } else {
  88         test_failure("ifislocal test failed for localhost");
  89     }
  90 
  91     
  92     if (test_ifaddrtoname("0.0.0.0")) {
  93         test_failure("ifaddrtoname test failed for 0.0.0.0");
  94     } else {
  95         test_success();
  96     }
  97     if (opal_ifislocal("0.0.0.0")) {
  98         test_failure("opal_ifislocal test failed for 0.0.0.0");
  99     } else {
 100         test_success();
 101     }
 102 
 103     
 104     printf("This should generate a warning:\n");
 105     fflush(stdout);
 106     if (test_ifaddrtoname("foo.example.com")) {
 107         test_failure("ifaddrtoname test failed for foo.example.com");
 108     } else {
 109         test_success();
 110     }
 111     printf("This should generate a warning:\n");
 112     fflush(stdout);
 113     if (opal_ifislocal("foo.example.com")) {
 114         test_failure("ifislocal test failed for foo.example.com");
 115     } else {
 116         test_success();
 117     }
 118 
 119     
 120     gethostname(hostname, sizeof(hostname));
 121     if (test_ifaddrtoname(hostname)) {
 122         test_success();
 123     } else {
 124         test_failure("ifaddrtoname test failed for local host name");
 125     }
 126     if (opal_ifislocal(hostname)) {
 127         test_success();
 128     } else {
 129         test_failure("ifislocal test failed for local host name");
 130     }
 131 
 132     test_finalize();
 133     opal_finalize();
 134 
 135     return 0;
 136 }