2004-10-31 22:01:53 +03:00
|
|
|
/*
|
2005-11-05 22:57:48 +03:00
|
|
|
* Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
|
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2004-11-28 23:09:25 +03:00
|
|
|
* Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
|
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-10-31 22:01:53 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ompi_config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
2005-03-27 15:59:23 +04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
2005-04-05 02:03:18 +04:00
|
|
|
#ifdef HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
2004-10-31 22:01:53 +03:00
|
|
|
|
2005-08-21 23:21:09 +04:00
|
|
|
#include "support.h"
|
2005-07-04 18:53:10 +04:00
|
|
|
#include "opal/runtime/opal.h"
|
2005-07-04 05:36:20 +04:00
|
|
|
#include "opal/util/if.h"
|
2006-02-12 22:51:24 +03:00
|
|
|
#include "opal/constants.h"
|
2004-10-31 22:01:53 +03:00
|
|
|
|
|
|
|
|
|
|
|
static bool
|
|
|
|
test_ifaddrtoname(char *addr)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char addrname[100];
|
|
|
|
int len = 99;
|
|
|
|
|
2005-07-04 05:36:20 +04:00
|
|
|
ret = opal_ifaddrtoname(addr, addrname, len);
|
2004-10-31 22:01:53 +03:00
|
|
|
|
2005-08-21 23:21:09 +04:00
|
|
|
if (ret == OPAL_SUCCESS) {
|
2004-10-31 22:01:53 +03:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
char hostname[MAXHOSTNAMELEN];
|
|
|
|
|
2005-07-04 18:53:10 +04:00
|
|
|
opal_init();
|
2005-07-04 05:36:20 +04:00
|
|
|
test_init("opal_if");
|
2004-10-31 22:01:53 +03:00
|
|
|
|
|
|
|
/* 127.0.0.1 */
|
|
|
|
if (test_ifaddrtoname("127.0.0.1")) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure("ifaddrtoname test failed for 127.0.0.1");
|
|
|
|
}
|
2005-07-04 05:36:20 +04:00
|
|
|
if (opal_ifislocal("127.0.0.1")) {
|
2004-10-31 22:01:53 +03:00
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure("ifislocal test failed for 127.0.0.1");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* localhost */
|
|
|
|
if (test_ifaddrtoname("localhost")) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure("ifaddrtoname test failed for localhost");
|
|
|
|
}
|
2005-07-04 05:36:20 +04:00
|
|
|
if (opal_ifislocal("localhost")) {
|
2004-10-31 22:01:53 +03:00
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure("ifislocal test failed for localhost");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 0.0.0.0 */
|
|
|
|
if (test_ifaddrtoname("0.0.0.0")) {
|
|
|
|
test_failure("ifaddrtoname test failed for 0.0.0.0");
|
|
|
|
} else {
|
|
|
|
test_success();
|
|
|
|
}
|
2005-07-04 05:36:20 +04:00
|
|
|
if (opal_ifislocal("0.0.0.0")) {
|
|
|
|
test_failure("opal_ifislocal test failed for 0.0.0.0");
|
2004-10-31 22:01:53 +03:00
|
|
|
} else {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* foo.example.com */
|
2005-03-27 16:05:41 +04:00
|
|
|
printf("This should generate a warning:\n");
|
|
|
|
fflush(stdout);
|
2004-10-31 22:01:53 +03:00
|
|
|
if (test_ifaddrtoname("foo.example.com")) {
|
|
|
|
test_failure("ifaddrtoname test failed for foo.example.com");
|
|
|
|
} else {
|
|
|
|
test_success();
|
|
|
|
}
|
2005-03-27 16:05:41 +04:00
|
|
|
printf("This should generate a warning:\n");
|
|
|
|
fflush(stdout);
|
2005-07-04 05:36:20 +04:00
|
|
|
if (opal_ifislocal("foo.example.com")) {
|
2004-10-31 22:01:53 +03:00
|
|
|
test_failure("ifislocal test failed for foo.example.com");
|
|
|
|
} else {
|
|
|
|
test_success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* local host name */
|
|
|
|
gethostname(hostname, MAXHOSTNAMELEN);
|
|
|
|
if (test_ifaddrtoname(hostname)) {
|
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure("ifaddrtoname test failed for local host name");
|
|
|
|
}
|
2005-07-04 05:36:20 +04:00
|
|
|
if (opal_ifislocal(hostname)) {
|
2004-10-31 22:01:53 +03:00
|
|
|
test_success();
|
|
|
|
} else {
|
|
|
|
test_failure("ifislocal test failed for local host name");
|
|
|
|
}
|
|
|
|
|
|
|
|
test_finalize();
|
2005-07-04 18:53:10 +04:00
|
|
|
opal_finalize();
|
2004-10-31 22:01:53 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|