diff options
author | goodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164> | 2000-10-20 10:18:50 +0000 |
---|---|---|
committer | goodale <goodale@1faa4e14-9dd3-4be0-9f0e-ffe519881164> | 2000-10-20 10:18:50 +0000 |
commit | 9e42c49d93494ae88f5e8ead2729ab38706d81f0 (patch) | |
tree | 60cd07b34b24fe47edcd9ad605b3c2b5b14bef65 /src/Sockets.c | |
parent | fecce1e9c4bfc16bb92dc6ef3592c8524e238c11 (diff) |
Use gethostbyname if necessary and available to get fully qualified name of the
host.
Tom
git-svn-id: http://svn.cactuscode.org/arrangements/CactusConnect/HTTPD/trunk@94 1faa4e14-9dd3-4be0-9f0e-ffe519881164
Diffstat (limited to 'src/Sockets.c')
-rw-r--r-- | src/Sockets.c | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/src/Sockets.c b/src/Sockets.c index 2ba851e..8e621ff 100644 --- a/src/Sockets.c +++ b/src/Sockets.c @@ -90,6 +90,8 @@ static httpSocket *SocketCreate(unsigned long int filedes); static void SocketDestroy(httpSocket *this); static void SocketClose(httpSocket *this); +static void GetHostName(char *name, int length); + static int InitialiseTCP(void); /******************************************************************** @@ -148,7 +150,8 @@ int HTTP_SetupServer(int port, int queue_size, int hunt) exit (EXIT_FAILURE); } - gethostname(hostname, 1024); + + GetHostName(hostname, 1024); httpport = hunt ? realport : port; @@ -682,6 +685,51 @@ static void SocketClose(httpSocket *this) } } + /*@@ + @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 + } +} + /****************************************************************************** ****************************************************************************** ******************************************************************************/ |