1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#if defined(HAVE_CONFIG_H) && !defined(MPICHCONF_INC)
/* This includes the definitions found by configure, and can be found in
the library directory (lib/$ARCH/$COMM) corresponding to this configuration
*/
#define MPICHCONF_INC
#include "mpichconf.h"
#endif
#include "mpe.h"
#if defined(HAVE_UNAME)
#include <sys/utsname.h>
#endif
#if defined(HAVE_GETHOSTBYNAME)
#include <netdb.h>
#endif
#if defined(HAVE_SYSINFO)
#if defined(HAVE_SYS_SYSTEMINFO_H)
#include <sys/systeminfo.h>
#else
#ifdef HAVE_SYSINFO
#undef HAVE_SYSINFO
#endif
#endif
#endif
void MPE_GetHostName( name, nlen )
int nlen;
char *name;
{
/* This is the perfered form, IF IT WORKS. */
#if defined(HAVE_UNAME) && defined(HAVE_GETHOSTBYNAME)
struct utsname utname;
struct hostent *he;
uname( &utname );
he = gethostbyname( utname.nodename );
/* We must NOT use strncpy because it will null pad to the full length
(nlen). If the user has not allocated MPI_MAX_PROCESSOR_NAME chars,
then this will unnecessarily overwrite storage.
*/
/* strncpy(name,he->h_name,nlen); */
{
char *p_out = name;
char *p_in = he->h_name;
int i;
for (i=0; i<nlen-1 && *p_in; i++)
*p_out++ = *p_in++;
*p_out = 0;
}
#else
#if defined(HAVE_UNAME)
struct utsname utname;
uname(&utname);
/* We must NOT use strncpy because it will null pad to the full length
(nlen). If the user has not allocated MPI_MAX_PROCESSOR_NAME chars,
then this will unnecessarily overwrite storage.
*/
/* strncpy(name,utname.nodename,nlen); */
{
char *p_out = name;
char *p_in = utname.nodename;
int i;
for (i=0; i<nlen-1 && *p_in; i++)
*p_out++ = *p_in++;
*p_out = 0;
}
#elif defined(HAVE_GETHOSTNAME)
gethostname( name, nlen );
#elif defined(HAVE_SYSINFO)
sysinfo(SI_HOSTNAME, name, nlen);
#else
strncpy( name, "Unknown!", nlen );
#endif
/* See if this name includes the domain */
if (!strchr(name,'.')) {
int l;
l = strlen(name);
name[l++] = '.';
name[l] = 0; /* In case we have neither SYSINFO or GETDOMAINNAME */
#if defined(HAVE_SYSINFO) && defined(SI_SRPC_DOMAIN)
sysinfo( SI_SRPC_DOMAIN,name+l,nlen-l);
#elif defined(HAVE_GETDOMAINNAME)
getdomainname( name+l, nlen - l );
#endif
}
#endif
}
|