]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Eliminated a strlcpy
[user/henk/code/inspircd.git] / src / inspircd.cpp
index a92a8ffdcb02177e7712814b0c7eea475b18c546..6d664389d318d15230527dcf0a751a2cebed8baa 100644 (file)
@@ -2326,11 +2326,14 @@ int InspIRCd(char** argv, int argc)
        bool expire_run = false;
        std::vector<int> activefds;
        int incomingSockfd;
+       int in_port;
        userrec* cu = NULL;
        InspSocket* s = NULL;
        InspSocket* s_del = NULL;
-       char target[MAXBUF];
+       char* target;
        unsigned int numberactive;
+        sockaddr_in sock_us;     // our port number
+        socklen_t uslen;         // length of our port number
 
        /* Beta 7 moved all this stuff out of the main function
         * into smaller sub-functions, much tidier -- Brain
@@ -2475,7 +2478,6 @@ int InspIRCd(char** argv, int argc)
                                         * within it, making them 'fire and forget'
                                         * and independent of the mainloop.
                                         */
-                                       log(DEBUG,"Got a ready socket of type X_ESTAB_DNS");
 #ifndef THREADED_DNS
                                        dns_poll(activefds[activefd]);
 #endif
@@ -2484,36 +2486,37 @@ int InspIRCd(char** argv, int argc)
                                case X_LISTEN:
 
                                        /* It's a listener */
-                                       for (int count = 0; count < boundPortCount; count++)
+                                       uslen = sizeof(sock_us);
+                                       length = sizeof(client);
+                                       incomingSockfd = accept (activefds[activefd],(struct sockaddr*)&client,&length);
+                                       if (!getsockname(incomingSockfd,(sockaddr*)&sock_us,&uslen))
                                        {
-                                               if (activefds[activefd] == openSockfd[count])
+                                               in_port = ntohs(sock_us.sin_port);
+                                               log(DEBUG,"Accepted socket %d",incomingSockfd);
+                                               target = (char*)inet_ntoa(client.sin_addr);
+                                               /* Years and years ago, we used to resolve here
+                                                * using gethostbyaddr(). That is sucky and we
+                                                * don't do that any more...
+                                                */
+                                               if (incomingSockfd >= 0)
                                                {
-                                                       length = sizeof (client);
-                                                       incomingSockfd = accept (openSockfd[count], (struct sockaddr *) &client, &length);
-                                                       log(DEBUG,"Accepted socket %d",incomingSockfd);
-                                                       strlcpy (target, (char *) inet_ntoa (client.sin_addr), MAXBUF);
-                                                       /* Years and years ago, we used to resolve here
-                                                        * using gethostbyaddr(). That is sucky and we
-                                                        * don't do that any more...
-                                                        */
-                                                       if (incomingSockfd >= 0)
-                                                       {
-                                                               FOREACH_MOD OnRawSocketAccept(incomingSockfd, target, ports[count]);
-                                                               statsAccept++;
-                                                               AddClient(incomingSockfd, target, ports[count], false, inet_ntoa (client.sin_addr));
-                                                               log(DEBUG,"Adding client on port %lu fd=%lu",(unsigned long)ports[count],(unsigned long)incomingSockfd);
-                                                       }
-                                                       else
-                                                       {
-                                                               WriteOpers("*** WARNING: accept() failed on port %lu (%s)",(unsigned long)ports[count],target);
-                                                               log(DEBUG,"accept failed: %lu",(unsigned long)ports[count]);
-                                                               statsRefused++;
-                                                       }
-                                                       /* We've found out what port it belongs on,
-                                                        * no need to iterate the rest
-                                                        */
-                                                       break;
+                                                       FOREACH_MOD OnRawSocketAccept(incomingSockfd, target, in_port);
+                                                       statsAccept++;
+                                                       AddClient(incomingSockfd, target, in_port, false, target);
+                                                       log(DEBUG,"Adding client on port %lu fd=%lu",(unsigned long)in_port,(unsigned long)incomingSockfd);
                                                }
+                                               else
+                                               {
+                                                       WriteOpers("*** WARNING: accept() failed on port %lu (%s)",(unsigned long)in_port,target);
+                                                       log(DEBUG,"accept failed: %lu",(unsigned long)in_port);
+                                                       statsRefused++;
+                                               }
+                                       }
+                                       else
+                                       {
+                                               log(DEBUG,"Couldnt look up the port number for fd %lu (OS BROKEN?!)",incomingSockfd);
+                                               shutdown(incomingSockfd,2);
+                                               close(incomingSockfd);
                                        }
                                break;