- ConfigReader Conf(this->ServerInstance);
- bool v6 = false;
-
- // Case one: If they provided an IP, try bind it
- if (!ip_to_bind.empty())
- {
-#ifdef IPV6
- // Check whether or not they are binding to an IPv6 IP..
- if (ip_to_bind.find(':') != std::string::npos)
- v6 = true;
-#endif
- // And if it fails, don't do anything.
- return this->DoBindMagic(ip_to_bind, v6);
- }
-
- for (int j = 0; j < Conf.Enumerate("bind"); j++)
- {
- // We only want to try bind to a server ip.
- if (Conf.ReadValue("bind","type",j) != "servers")
- continue;
-
- // set current IP to the <bind> tag
- std::string current_ip = Conf.ReadValue("bind","address",j);
-
-#ifdef IPV6
- // Check whether this <bind> is for an ipv6 address
- if (current_ip.find(':') != std::string::npos)
- v6 = true;
- else
- v6 = false;
-#endif
-
- // Make sure IP is nothing local
- if (current_ip == "*" || current_ip == "127.0.0.1" || current_ip.empty() || current_ip == "::1")
- continue;
-
- // Try bind, don't fail if it doesn't bind though.
- if (this->DoBindMagic(current_ip, v6))
- return true;
- }
-
- // NOTE: You may wonder WTF we are returning *true* here, but that is because there were no custom binds setup, and so we have nothing to do
- // (remember, outgoing connections without binding are perfectly ok).
- ServerInstance->Logs->Log("SOCKET", DEBUG,"nothing in the config to bind()!");
- return true;
-}
-
-bool BufferedSocket::DoConnect(unsigned long maxtime)
-{
- /* The [2] is required because we may write a sockaddr_in6 here, and sockaddr_in6 is larger than sockaddr, where sockaddr_in4 is not. */
- sockaddr* addr = new sockaddr[2];
- socklen_t size = sizeof(sockaddr_in);
-#ifdef IPV6
- bool v6 = false;
- if ((!*this->host) || strchr(this->host, ':'))
- v6 = true;
-
- if (v6)
- {
- this->fd = socket(AF_INET6, SOCK_STREAM, 0);
- if ((this->fd > -1) && ((strstr(this->IP,"::ffff:") != (char*)&this->IP) && (strstr(this->IP,"::FFFF:") != (char*)&this->IP)))
- {
- if (!this->BindAddr(this->cbindip))
- {
- this->Close();
- this->fd = -1;
- delete[] addr;
- return false;
- }
- }
- }
- else
-#endif
- {
- this->fd = socket(AF_INET, SOCK_STREAM, 0);
- if (this->fd > -1)
- {
- if (!this->BindAddr(this->cbindip))
- {
- this->Close();
- this->fd = -1;
- delete[] addr;
- return false;
- }
- }
- }