From 347dcb9ef44e19e2e2613ee7e8c7d5fbb0aca4ca Mon Sep 17 00:00:00 2001 From: danieldg Date: Wed, 2 Sep 2009 00:49:15 +0000 Subject: Remove duplicated address conversion from InspIRCd::BindSocket, fix FD leak in listensocket git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11632 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/socket.cpp | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) (limited to 'src/socket.cpp') diff --git a/src/socket.cpp b/src/socket.cpp index e32bda901..277f61bcd 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -27,37 +27,20 @@ bool InspIRCd::BindSocket(int sockfd, int port, const char* addr, bool dolisten) sockaddrs servaddr; int ret; - if (*addr == '*') - addr = ""; + if (*addr == '*' || *addr == '\0') + addr = NULL; - if (*addr) - { - irc::sockets::aptosa(addr, port, &servaddr); - } - else + if (port == -1 && !addr) { + /* Port -1: Means UDP IPV4 port binding - Special case + * used by DNS engine. + */ memset(&servaddr, 0, sizeof(servaddr)); - if (port == -1) - { - /* Port -1: Means UDP IPV4 port binding - Special case - * used by DNS engine. - */ - servaddr.in4.sin_family = AF_INET; - } - else - { - /* No address */ -#ifdef IPV6 - /* Default to ipv6 bind to all */ - servaddr.in6.sin6_family = AF_INET6; - servaddr.in6.sin6_port = htons(port); -#else - /* Bind ipv4 to all */ - servaddr.in4.sin_family = AF_INET; - servaddr.in4.sin_port = htons(port); -#endif - } + servaddr.in4.sin_family = AF_INET; } + else if (!irc::sockets::aptosa(addr, port, &servaddr)) + return false; + ret = SE->Bind(sockfd, &servaddr.sa, sa_size(servaddr)); if (ret < 0) -- cgit v1.2.3