From 0f338a570c159935fc3684aa980318b8b859097d Mon Sep 17 00:00:00 2001 From: goodale Date: Wed, 8 Nov 2000 14:48:00 +0000 Subject: Adding the GetHostName function. We should probably move this into utils. Tom git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPDExtra/trunk@18 61ea717e-8e0c-4c3c-b38e-e9c67f54f1f1 --- src/HostNames.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/HostNames.c b/src/HostNames.c index 318b943..c09437d 100644 --- a/src/HostNames.c +++ b/src/HostNames.c @@ -19,6 +19,21 @@ #ifdef HAVE_UNISTD_H #include #endif /* HAVE_UNISTD_H */ +#ifdef HAVE_SYS_TIME_H +#include +#endif /* HAVE_SYS_TIME_H */ +#ifdef HAVE_SYS_TYPES_H +#include +#endif /* HAVE_SYS_TYPES_H */ +#ifdef HAVE_SYS_SOCKET_H +#include +#endif /* HAVE_SYS_SOCKET_H */ +#ifdef HAVE_NETINET_IN_H +#include +#endif /* HAVE_NETINET_IN_H */ +#ifdef HAVE_NETDB_H +#include +#endif /* HAVE_NETDB_H */ #ifdef CCTK_MPI #include "mpi.h" @@ -41,6 +56,7 @@ CCTK_FILEVERSION(CactusConnect_HTTPDExtra_HostNames_c) /******************************************************************** ********************* Local Routine Prototypes ********************* ********************************************************************/ +static void GetHostName(char *name, int length); /******************************************************************** ********************* Other Routine Prototypes ********************* @@ -76,7 +92,7 @@ void HTTPDExtra_CollateHostData(void) int nprocs; char thisdata[HOSTDATALENGTH+1]; - gethostname(thisdata, HOSTDATALENGTH); + GetHostName(thisdata, HOSTDATALENGTH); thisdata[HOSTDATALENGTH+1] = 0; @@ -133,6 +149,51 @@ const char *HTTPDExtra_RemoteHostName(int host) ********************* Local Routines ************************* ********************************************************************/ + /*@@ + @routine GetHostName + @date Fri Oct 20 12:12:34 2000 + @author Tom Goodale + @desc + Gets the fully qualified name of this host if possible. + @enddesc + @calls + @calledby + @history + + @endhistory + @var name + @vdesc character buffer to store name in + @vtype char * + @vio out + @vcomment + + @endvar + @var length + @vdesc length of the character buffer + @vtype int + @vio in + @vcomment + + @endvar + +@@*/ +static void GetHostName(char *name, int length) +{ + gethostname(name, length); + + /* Does the name include the domain. */ + if(!strchr(name, '.')) + { +#ifdef HAVE_GETHOSTBYNAME + struct hostent *thishostent; + + thishostent = gethostbyname(name); + + strncpy(name, thishostent->h_name, length); +#endif + } +} + #ifdef TEST_HOSTNAMES int main(int argc, char *argv[]) -- cgit v1.2.3