ENH: optional argument to hostName() to return full hostname

- value as reported by gethostbyname
This commit is contained in:
Mark Olesen
2010-12-21 18:27:17 +01:00
parent f3b95df7b9
commit 9cef74b796
2 changed files with 16 additions and 5 deletions

View File

@ -109,12 +109,22 @@ bool Foam::setEnv
}
Foam::word Foam::hostName()
Foam::word Foam::hostName(bool full)
{
char buffer[256];
gethostname(buffer, 256);
char buf[256];
gethostname(buf, 256);
return buffer;
if (full)
{
struct hostent *hptr = gethostbyname(buf);
if (hptr)
{
return hptr->h_name;
}
}
return buf;
}

View File

@ -68,7 +68,8 @@ string getEnv(const word&);
bool setEnv(const word& name, const string& value, const bool overwrite);
//- Return the system's host name
word hostName();
// Optionally the full name reported from gethostbyname
word hostName(const bool full=false);
//- Return the user's login name
word userName();