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

View File

@ -1,7 +1,7 @@
//
// DNS.cpp
//
// $Id: //poco/Main/Net/src/DNS.cpp#9 $
// $Id: //poco/Main/Net/src/DNS.cpp#10 $
//
// Library: Net
// Package: NetCore
@ -180,7 +180,7 @@ IPAddress DNS::resolveOne(const std::string& address)
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()
{
#if defined(_WIN32)