mirror of
https://github.com/pocoproject/poco.git
synced 2024-12-13 02:22:57 +01:00
- fixed SF# 2644940: on Windows the COMPUTER-NAME and the HOSTNAME can be different
This commit is contained in:
parent
060e32101b
commit
25fc7512ad
@ -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.
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user