]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socket.cpp
New logging implementation. Also write messages about InspIRCd::Log() being deprecate...
[user/henk/code/inspircd.git] / src / socket.cpp
index 3e9db5fd430fcdf42eea20aaa08e3d0fed48438e..bd8147b3fa08e2ebc74fdf4b2be751b036cbaaae 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
+ *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
  * See: http://www.inspircd.org/wiki/index.php/Credits
  *
  * This program is free but copyrighted software; see
@@ -11,9 +11,9 @@
  * ---------------------------------------------------
  */
 
+/* $Core: libIRCDsocket */
+
 #include "inspircd.h"
-#include <string>
-#include "configreader.h"
 #include "socket.h"
 #include "socketengine.h"
 #include "wildcard.h"
@@ -65,13 +65,24 @@ ListenSocket::~ListenSocket()
        }
 }
 
-void ListenSocket::HandleEvent(EventType et, int errornum)
+
+// XXX this is a bit of an untidy way to avoid reallocating this constantly. also, we leak it on shutdown.. but that's kinda minor - w
+static sockaddr *sock_us;
+static sockaddr *client;
+static bool setup_sock = false;
+
+void ListenSocket::HandleEvent(EventType, int)
 {
-       sockaddr* sock_us = new sockaddr[2];    // our port number
-       sockaddr* client = new sockaddr[2];
        socklen_t uslen, length;                // length of our port number
        int incomingSockfd, in_port;
 
+       if (!setup_sock)
+       {
+               sock_us = new sockaddr[2];
+               client = new sockaddr[2];
+               setup_sock = true;
+       }
+
 #ifdef IPV6
        if (this->family == AF_INET6)
        {
@@ -117,16 +128,14 @@ void ListenSocket::HandleEvent(EventType et, int errornum)
                        }
                }
                ServerInstance->stats->statsAccept++;
-               userrec::AddClient(ServerInstance, incomingSockfd, in_port, false, this->family, client);
+               ServerInstance->Users->AddClient(ServerInstance, incomingSockfd, in_port, false, this->family, client);
        }
        else
        {
                ServerInstance->SE->Shutdown(incomingSockfd, 2);
-               close(incomingSockfd);
+               ServerInstance->SE->Close(incomingSockfd);
                ServerInstance->stats->statsRefused++;
        }
-       delete[] client;
-       delete[] sock_us;
 }
 
 /* Match raw bytes using CIDR bit matching, used by higher level MatchCIDR() */
@@ -426,7 +435,8 @@ int irc::sockets::OpenTCPSocket(char* addr, int socktype)
 {
        int sockfd;
        int on = 1;
-       struct linger linger = { 0 };
+       addr = addr;
+       struct linger linger = { 0, 0 };
 #ifdef IPV6
        if (strchr(addr,':') || (!*addr))
                sockfd = socket (PF_INET6, socktype, 0);
@@ -450,7 +460,7 @@ int irc::sockets::OpenTCPSocket(char* addr, int socktype)
        }
 }
 
-int InspIRCd::BindPorts(bool bail, int &ports_found, FailedPortList &failed_ports)
+int InspIRCd::BindPorts(bool, int &ports_found, FailedPortList &failed_ports)
 {
        char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
        int bound = 0;
@@ -466,7 +476,10 @@ int InspIRCd::BindPorts(bool bail, int &ports_found, FailedPortList &failed_port
                Config->ConfValue(Config->config_data, "bind", "port", count, configToken, MAXBUF);
                Config->ConfValue(Config->config_data, "bind", "address", count, Addr, MAXBUF);
                Config->ConfValue(Config->config_data, "bind", "type", count, Type, MAXBUF);
-
+               
+               if (strncmp(Addr, "::ffff:", 7) == 0)
+                       this->Log(DEFAULT, "Using 4in6 (::ffff:) isn't recommended. You should bind IPv4 addresses directly instead.");
+               
                if ((!*Type) || (!strcmp(Type,"clients")))
                {
                        irc::portparser portrange(configToken, false);