Actual source code: fhost.c
1: /*$Id: fhost.c,v 1.49 2001/03/23 23:20:45 balay Exp $*/
2: /*
3: Code for manipulating files.
4: */
5: #include petsc.h
6: #include petscsys.h
7: #if defined(PETSC_HAVE_STDLIB_H)
8: #include <stdlib.h>
9: #endif
10: #if !defined(PARCH_win32)
11: #include <sys/utsname.h>
12: #endif
13: #if defined(PARCH_win32)
14: #include <windows.h>
15: #include <io.h>
16: #include <direct.h>
17: #endif
18: #if defined (PARCH_win32_gnu)
19: #include <windows.h>
20: #endif
21: #if defined(PETSC_HAVE_SYS_SYSTEMINFO_H)
22: #include <sys/systeminfo.h>
23: #endif
24: #if defined(PETSC_HAVE_UNISTD_H)
25: #include <unistd.h>
26: #endif
27: #include "petscfix.h"
29: #undef __FUNCT__
31: /*@C
32: PetscGetHostName - Returns the name of the host. This attempts to
33: return the entire Internet name. It may not return the same name
34: as MPI_Get_processor_name().
36: Not Collective
38: Input Parameter:
39: . nlen - length of name
41: Output Parameter:
42: . name - contains host name. Must be long enough to hold the name
43: This is the fully qualified name, including the domain.
45: Level: developer
47: Concepts: machine name
48: Concepts: host name
50: .seealso: PetscGetUserName()
51: @*/
52: int PetscGetHostName(char name[],int nlen)
53: {
54: char *domain;
55: int ierr;
56: PetscTruth flag;
57: #if defined(PETSC_HAVE_UNAME)
58: struct utsname utname;
59: #endif
63: #if defined(PARCH_win32) || defined(PARCH_win32_gnu)
64: GetComputerName((LPTSTR)name,(LPDWORD)(&nlen));
65: #elif defined(PETSC_HAVE_UNAME)
66: uname(&utname);
67: PetscStrncpy(name,utname.nodename,nlen);
68: #elif defined(PETSC_HAVE_GETHOSTNAME)
69: gethostname(name,nlen);
70: #elif defined(PETSC_HAVE_SYSINFO_3ARG)
71: sysinfo(SI_HOSTNAME,name,nlen);
72: #endif
73: /* See if this name includes the domain */
74: PetscStrchr(name,'.',&domain);
75: if (!domain) {
76: int l,ll;
77: PetscStrlen(name,&l);
78: if (l == nlen) {name[nlen-1] = 0; return(0);}
79: name[l++] = '.';
80: #if defined(PETSC_HAVE_SYSINFO_3ARG)
81: sysinfo(SI_SRPC_DOMAIN,name+l,nlen-l);
82: #elif defined(PETSC_HAVE_GETDOMAINNAME)
83: getdomainname(name+l,nlen - l);
84: #endif
85: /* check if domain name is not a dnsdomainname and nuke it */
86: PetscStrlen(name,&ll);
87: if (ll > 4) {
88: PetscStrcmp(name + ll - 4,".edu",&flag);
89: if (!flag) {
90: PetscStrcmp(name + ll - 4,".com",&flag);
91: if (!flag) {
92: PetscStrcmp(name + ll - 4,".net",&flag);
93: if (!flag) {
94: PetscStrcmp(name + ll - 4,".org",&flag);
95: if (!flag) {
96: PetscStrcmp(name + ll - 4,".mil",&flag);
97: if (!flag) {
98: PetscLogInfo(0,"Rejecting domainname, likely is NIS %sn",name);
99: name[l-1] = 0;
100: }
101: }
102: }
103: }
104: }
105: }
106: }
107: name[nlen-1] = 0;
108: return(0);
109: }