+ if (dest->host.find('.') != std::string::npos || dest->host.find(':') != std::string::npos)
+ {
+ unsigned int iv[] = { cu->key1, cu->key2, cu->key3, cu->key4 };
+ std::string a = cu->LastTwoDomainParts(dest->host);
+ std::string b;
+
+ /* InspIRCd users have two hostnames; A displayed
+ * hostname which can be modified by modules (e.g.
+ * to create vhosts, implement chghost, etc) and a
+ * 'real' hostname which you shouldnt write to.
+ */
+
+ /* 2008/08/18: add <cloak:ipalways> which always cloaks
+ * the IP, for anonymity. --nenolod
+ */
+ if (!cu->ipalways)
+ {
+ /** Reset the Hash module, and send it our IV and hex table */
+ HashResetRequest(this, cu->HashProvider).Send();
+ HashKeyRequest(this, cu->HashProvider, iv).Send();
+ HashHexRequest(this, cu->HashProvider, cu->xtab[(dest->host[0]) % 4]);
+
+ /* Generate a cloak using specialized Hash */
+ std::string hostcloak = cu->prefix + "-" + std::string(HashSumRequest(this, cu->HashProvider, dest->host.c_str()).Send()).substr(0,8) + a;
+
+ /* Fix by brain - if the cloaked host is > the max length of a host (64 bytes
+ * according to the DNS RFC) then tough titty, they get cloaked as an IP.
+ * Their ISP shouldnt go to town on subdomains, or they shouldnt have a kiddie
+ * vhost.
+ */
+ std::string testaddr;
+ int testport;
+ if (!irc::sockets::satoap(&dest->client_sa, testaddr, testport) && (hostcloak.length() <= 64))
+ /* not a valid address, must have been a host, so cloak as a host */
+ b = hostcloak;
+ else if (dest->client_sa.sa.sa_family == AF_INET6)
+ b = cu->Cloak6(dest->GetIPString());
+ else
+ b = cu->Cloak4(dest->GetIPString());
+ }
+ else
+ {
+ if (dest->client_sa.sa.sa_family == AF_INET6)
+ b = cu->Cloak6(dest->GetIPString());
+ else
+ b = cu->Cloak4(dest->GetIPString());
+ }
+
+ dest->Extend("cloaked_host", new std::string(b));
+ }
+ }
+
+};
+
+MODULE_INIT(ModuleCloaking)