- fixed SF# 2644940: on Windows the COMPUTER-NAME and the HOSTNAME can be different

This commit is contained in:
Guenter Obiltschnig 2009-03-13 13:22:51 +00:00
parent 060e32101b
commit 25fc7512ad
2 changed files with 17 additions and 3 deletions

View File

@ -1,7 +1,7 @@
// //
// DNS.h // DNS.h
// //
// $Id: //poco/Main/Net/include/Poco/Net/DNS.h#3 $ // $Id: //poco/Main/Net/include/Poco/Net/DNS.h#4 $
// //
// Library: Net // Library: Net
// Package: NetCore // Package: NetCore
@ -119,6 +119,9 @@ public:
static void flushCache(); static void flushCache();
/// Flushes the internal DNS cache. /// Flushes the internal DNS cache.
static std::string hostName();
/// Returns the host name of this host.
protected: protected:
static int lastError(); static int lastError();
/// Returns the code of the last error. /// Returns the code of the last error.

View File

@ -1,7 +1,7 @@
// //
// DNS.cpp // DNS.cpp
// //
// $Id: //poco/Main/Net/src/DNS.cpp#9 $ // $Id: //poco/Main/Net/src/DNS.cpp#10 $
// //
// Library: Net // Library: Net
// Package: NetCore // Package: NetCore
@ -180,7 +180,7 @@ IPAddress DNS::resolveOne(const std::string& address)
HostEntry DNS::thisHost() HostEntry DNS::thisHost()
{ {
return hostByName(Environment::nodeName()); return hostByName(hostName());
} }
@ -192,6 +192,17 @@ void DNS::flushCache()
} }
std::string DNS::hostName()
{
char buffer[256];
int rc = gethostname(buffer, sizeof(buffer));
if (rc == 0)
return std::string(buffer);
else
throw NetException("Cannot get host name");
}
int DNS::lastError() int DNS::lastError()
{ {
#if defined(_WIN32) #if defined(_WIN32)