diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-02 00:49:15 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-09-02 00:49:15 +0000 |
commit | 347dcb9ef44e19e2e2613ee7e8c7d5fbb0aca4ca (patch) | |
tree | 870f6d58f03829c35724665d3313ed6ab017e828 /src/socket.cpp | |
parent | 24731c63b6320be22f7b3220236271fa7476b975 (diff) |
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
Diffstat (limited to 'src/socket.cpp')
-rw-r--r-- | src/socket.cpp | 37 |
1 files changed, 10 insertions, 27 deletions
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) |