- errno = EADDRNOTAVAIL;
- return false;
- }
-
- if (ServerInstance->SE->Bind(this->fd, &s.sa, sa_size(s)) < 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);
-
- // Case one: If they provided an IP, try bind it
- if (!ip_to_bind.empty())
- {
- // And if it fails, don't do anything.
- return this->DoBindMagic(ip_to_bind);
- }
-
- 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);
-
- // 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))
- return true;