]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspsocket.cpp
Remove some debug
[user/henk/code/inspircd.git] / src / inspsocket.cpp
index c9c5ba4ec601609e6ccc1fb698badf968d59573e..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()
 {
@@ -28,6 +26,7 @@ bool InspSocket::Readable()
 
 InspSocket::InspSocket(InspIRCd* SI)
 {
+       this->Timeout = NULL;
        this->state = I_DISCONNECTED;
        this->fd = -1;
        this->WaitingForWriteEvent = false;
@@ -37,6 +36,7 @@ InspSocket::InspSocket(InspIRCd* SI)
 
 InspSocket::InspSocket(InspIRCd* SI, int newfd, const char* ip)
 {
+       this->Timeout = NULL;
        this->fd = newfd;
        this->state = I_CONNECTED;
        strlcpy(this->IP,ip,MAXBUF);
@@ -47,13 +47,15 @@ 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);
        this->WaitingForWriteEvent = false;
        this->IsIOHooked = false;
+       this->Timeout = NULL;
        if (listening)
        {
                if ((this->fd = OpenTCPSocket(host)) == ERROR)
@@ -99,19 +101,19 @@ InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool
 #ifdef IPV6
                if (strchr(host,':'))
                {
-                       in6_addr addy;
-                       if (inet_ntop(AF_INET6, host, &n) < 1)
+                       in6_addr n;
+                       if (inet_pton(AF_INET6, host, &n) < 1)
                                ipvalid = false;
                }
                else
                {
-                       in_addr addy;
-                       if (inet_aton(host,&addy) < 1)
+                       in_addr n;
+                       if (inet_aton(host,&n) < 1)
                                ipvalid = false;
                }
 #else
-               in_addr addy;
-               if (inet_aton(host,&addy) < 1)
+               in_addr n;
+               if (inet_aton(host,&n) < 1)
                        ipvalid = false;
 #endif
                if (!ipvalid)
@@ -155,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;
@@ -166,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
@@ -181,8 +183,8 @@ bool InspSocket::BindAddr()
                                        in6_addr n;
                                        if (inet_pton(AF_INET6, IP.c_str(), &n) > 0)
                                        {
-                                               memcpy(((sockaddr_in6*)s)->sin6_addr, &n, sizeof(n));
-                                               s.sin6_family = AF_INET6;
+                                               memcpy(&((sockaddr_in6*)s)->sin6_addr, &n, sizeof(n));
+                                               ((sockaddr_in6*)s)->sin6_family = AF_INET6;
                                                size = sizeof(sockaddr_in6);
                                        }
                                        else
@@ -228,6 +230,7 @@ bool InspSocket::BindAddr()
                                return true;
                        }
                }
+               j++;
        }
        return true;
 }
@@ -246,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;
@@ -548,6 +551,10 @@ void SocketTimeout::Tick(time_t now)
                delete this->sock;
                return;
        }
+       else
+       {
+               this->sock->Timeout = NULL;
+       }
 }
 
 bool InspSocket::Poll()
@@ -596,19 +603,18 @@ bool InspSocket::Poll()
                                length = sizeof(sockaddr_in6);
 #endif
                        incoming = accept (this->fd, client, &length);
-
 #ifdef IPV6
                        if ((!*this->host) || strchr(this->host, ':'))
                        {
                                char buf[1024];
-                               recvip = inet_ntop(AF_INET6, ((sockaddr_in6*)client)->sin6_addr, buf, sizeof(buf));
+                               recvip = inet_ntop(AF_INET6, &((sockaddr_in6*)client)->sin6_addr, buf, sizeof(buf));
                        }
                        else
                        {
-                               recvip = insp_ntoa(((sockaddr_in*)client)->sin_addr);
+                               recvip = inet_ntoa(((sockaddr_in*)client)->sin_addr);
                        }
 #else
-                       recvip = insp_ntoa(((sockaddr_in*)client)->sin_addr);
+                       recvip = inet_ntoa(((sockaddr_in*)client)->sin_addr);
 #endif
                        this->OnIncomingConnection(incoming, (char*)recvip.c_str());