- else
-#endif
- {
- in_addr n;
- if (inet_aton(current_ip.c_str(), &n) > 0)
- {
- ((sockaddr_in*)s)->sin_addr = n;
- ((sockaddr_in*)s)->sin_port = 0;
- ((sockaddr_in*)s)->sin_family = AF_INET;
- }
- else
- {
- // Well, this is as good as it's gonna get.
- errno = EADDRNOTAVAIL;
- delete[] s;
- return false;
- }
- }
-
- if (ServerInstance->SE->Bind(this->fd, s, size) < 0)
- {
- this->state = I_ERROR;
- this->OnError(I_ERR_BIND);
- delete[] s;
- return false;
- }
-
- delete[] s;
- 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;
-#ifdef IPV6
- /* Are we looking for a binding to fit an ipv6 host? */
- if ((ip_to_bind.empty()) || (ip_to_bind.find(':') != std::string::npos))
- v6 = true;
-#endif
-
- // 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, 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);