- else
- {
- // Well, this is as good as it's gonna get.
- errno = EADDRNOTAVAIL;
- return false;
- }
- }
-
- if (ServerInstance->SE->Bind(this->fd, &s.sa, size) < 0)
- {
- this->state = I_ERROR;
- this->OnError(I_ERR_BIND);
- return false;
- }
-
- return true;
-}
-
-/* Most irc servers require you to specify the ip you want to bind to.
- * If you dont specify an IP, they rather dumbly bind to the first IP
- * of the box (e.g. INADDR_ANY). In InspIRCd, we scan thought the IP
- * addresses we've bound server ports to, and we try and bind our outbound
- * connections to the first usable non-loopback and non-any IP we find.
- * This is easier to configure when you have a lot of links and a lot
- * of servers to configure.
- */
-bool BufferedSocket::BindAddr(const std::string &ip_to_bind)
-{
- 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;