diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-02-12 21:43:56 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2007-02-12 21:43:56 +0000 |
commit | 1a2623a51bcec6ffd692c6e1d9b333c11d23d51d (patch) | |
tree | 0bdb1ea2a25ca4eb77ceaa39942a045bb3451cb9 /src | |
parent | 84951d4b109ddfe6b68871516afa0e76d3b8e3af (diff) |
Fixed <link:bind> which was only working on an ipv6 connection. Fixes bug #213 reported by owine
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6581 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/inspsocket.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp index 093b133f0..b9d31845f 100644 --- a/src/inspsocket.cpp +++ b/src/inspsocket.cpp @@ -129,7 +129,14 @@ InspSocket::InspSocket(InspIRCd* SI, const std::string &ipaddr, int aport, bool { strlcpy(this->IP,host,MAXBUF); timeout_val = maxtime; - this->DoConnect(); + if (!this->DoConnect()) + { + this->Close(); + this->fd = -1; + this->state = I_ERROR; + this->OnError(I_ERR_CONNECT); + return; + } } } } @@ -159,6 +166,7 @@ void InspSocket::SetQueues(int nfd) */ bool InspSocket::BindAddr(const std::string &ip) { + Instance->Log(DEBUG,"BindAddr(%s)", ip.c_str()); ConfigReader Conf(this->Instance); bool bindfail = false; socklen_t size = sizeof(sockaddr_in); @@ -169,7 +177,7 @@ bool InspSocket::BindAddr(const std::string &ip) v6 = true; #endif int j = 0; - while ((j < Conf.Enumerate("bind")) && (!ip.empty())) + while (j < Conf.Enumerate("bind") || (!ip.empty())) { std::string IP = ip.empty() ? Conf.ReadValue("bind","address",j) : ip; if (!ip.empty() || Conf.ReadValue("bind","type",j) == "servers") @@ -259,9 +267,25 @@ bool InspSocket::DoConnect() else { this->fd = socket(AF_INET, SOCK_STREAM, 0); + if (this->fd > -1) + { + if (!this->BindAddr(this->cbindip)) + { + delete[] addr; + return false; + } + } } #else this->fd = socket(AF_INET, SOCK_STREAM, 0); + if (this->fd > -1) + { + if (!this->BindAddr(this->cbindip)) + { + delete[] addr; + return false; + } + } #endif if (this->fd == -1) |