diff options
author | Peter Powell <petpow@saberuk.com> | 2019-02-16 14:25:29 +0000 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2019-02-16 14:25:29 +0000 |
commit | 6daf442c77b411517ff656e543f5ecec02384ce8 (patch) | |
tree | 29edbc54ae54766aa0fd0c715670c06a52779d5d /src/configreader.cpp | |
parent | 9b031d4d98e5ca35b960d3f9b2498edf19b02939 (diff) |
Use the local hostname as the server name if one is not specified.
Diffstat (limited to 'src/configreader.cpp')
-rw-r--r-- | src/configreader.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp index 5a0ceff06..00880cfff 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -309,6 +309,23 @@ void ServerConfig::CrossCheckConnectBlocks(ServerConfig* current) } } +static std::string GetServerName() +{ +#ifndef _WIN32 + char hostname[256]; + if (gethostname(hostname, sizeof(hostname)) == 0) + { + std::string name(hostname); + if (name.find('.') == std::string::npos) + name.push_back('.'); + + if (name.length() <= ServerInstance->Config->Limits.MaxHost && InspIRCd::IsHost(name)) + return name; + } +#endif + return "irc.example.com"; +} + void ServerConfig::Fill() { ConfigTag* options = ConfValue("options"); @@ -316,7 +333,7 @@ void ServerConfig::Fill() ConfigTag* server = ConfValue("server"); if (sid.empty()) { - ServerName = server->getString("name", "irc.example.com", InspIRCd::IsHost); + ServerName = server->getString("name", GetServerName(), InspIRCd::IsHost); sid = server->getString("id"); if (!sid.empty() && !InspIRCd::IsSID(sid)) |