]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspsocket.cpp
Fix warning, remove unused var
[user/henk/code/inspircd.git] / src / inspsocket.cpp
index 492cafdd934896d3583f1d10e25ac30a913a4cbe..093b133f0de9e28b21582bb8999f3bda4bbb7f04 100644 (file)
@@ -18,8 +18,6 @@
 #include "inspircd.h"
 
 using irc::sockets::OpenTCPSocket;
-using irc::sockets::insp_inaddr;
-using irc::sockets::insp_sockaddr;
 
 bool InspSocket::Readable()
 {
@@ -49,8 +47,9 @@ InspSocket::InspSocket(InspIRCd* SI, int newfd, const char* ip)
                this->Instance->SE->AddFd(this);
 }
 
-InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool listening, unsigned long maxtime)
+InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool listening, unsigned long maxtime, const std::string &connectbindip)
 {
+       this->cbindip = connectbindip;
        this->fd = -1;
        this->Instance = SI;
        strlcpy(host,ipaddr.c_str(),MAXBUF);
@@ -158,7 +157,7 @@ void InspSocket::SetQueues(int nfd)
  * This is easier to configure when you have a lot of links and a lot
  * of servers to configure.
  */
-bool InspSocket::BindAddr()
+bool InspSocket::BindAddr(const std::string &ip)
 {
        ConfigReader Conf(this->Instance);
        bool bindfail = false;
@@ -169,13 +168,13 @@ bool InspSocket::BindAddr()
        if ((!*this->host) || strchr(this->host, ':'))
                v6 = true;
 #endif
-       for (int j =0; j < Conf.Enumerate("bind"); j++)
+       int j = 0;
+       while ((j < Conf.Enumerate("bind")) && (!ip.empty()))
        {
-               std::string Type = Conf.ReadValue("bind","type",j);
-               std::string IP = Conf.ReadValue("bind","address",j);
-               if (Type == "servers")
+               std::string IP = ip.empty() ? Conf.ReadValue("bind","address",j) : ip;
+               if (!ip.empty() || Conf.ReadValue("bind","type",j) == "servers")
                {
-                       if ((IP != "*") && (IP != "127.0.0.1") && (IP != "") && (IP != "::1"))
+                       if (!ip.empty() || ((IP != "*") && (IP != "127.0.0.1") && (IP != "") && (IP != "::1")))
                        {
                                sockaddr* s = new sockaddr[2];
 #ifdef IPV6
@@ -231,6 +230,7 @@ bool InspSocket::BindAddr()
                                return true;
                        }
                }
+               j++;
        }
        return true;
 }
@@ -249,7 +249,7 @@ bool InspSocket::DoConnect()
                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())
+                       if (!this->BindAddr(this->cbindip))
                        {
                                delete[] addr;
                                return false;
@@ -595,7 +595,6 @@ bool InspSocket::Poll()
                break;
                case I_LISTENING:
                {
-                       Instance->Log(DEBUG,"InspSocket listen event");
                        sockaddr* client = new sockaddr[2];
                        length = sizeof (sockaddr_in);
                        std::string recvip;
@@ -604,9 +603,6 @@ bool InspSocket::Poll()
                                length = sizeof(sockaddr_in6);
 #endif
                        incoming = accept (this->fd, client, &length);
-
-                       Instance->Log(DEBUG,"Accepted socket, sockaddr length %d fd %d", length, incoming);
-
 #ifdef IPV6
                        if ((!*this->host) || strchr(this->host, ':'))
                        {
@@ -620,7 +616,6 @@ bool InspSocket::Poll()
 #else
                        recvip = inet_ntoa(((sockaddr_in*)client)->sin_addr);
 #endif
-                       Instance->Log(DEBUG,"Call OnIncomingConnection, recvip=%s", recvip.c_str());
                        this->OnIncomingConnection(incoming, (char*)recvip.c_str());
 
                        if (this->IsIOHooked)