From 9cef74b796717075692cfef327380b8bfb8998a4 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 21 Dec 2010 18:27:17 +0100 Subject: [PATCH] ENH: optional argument to hostName() to return full hostname - value as reported by gethostbyname --- src/OSspecific/POSIX/POSIX.C | 18 ++++++++++++++---- src/OpenFOAM/include/OSspecific.H | 3 ++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C index fecea27cbe..380c785c0b 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -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; } diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index 7b4c3a5320..3ee759a596 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -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();