diff options
| author | 2006-06-27 17:52:46 +0000 | |
|---|---|---|
| committer | 2006-06-27 17:52:46 +0000 | |
| commit | 7dbd72891cb3a6af62b630a8cbcdc0b85af905c3 (patch) | |
| tree | 884e10487515115c9974416285e0c86503f98482 /src/socket.cpp | |
| parent | Temporarily revert special's security improvement until we have bind= and mask= (diff) | |
Added BindAddr() smart binding, ensures that outbound ports always bind to the first server ip given rather than INADDR_ANY unless of course none are available or the only ip is localhost...
git-svn-id: http://svn.inspircd.org/repository/branches/1_0_stable@4065 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/socket.cpp')
| -rw-r--r-- | src/socket.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/socket.cpp b/src/socket.cpp index e3248d5be..493f2447b 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -159,6 +159,49 @@ bool InspSocket::DoResolve() return true; } +bool InspSocket::BindAddr() +{ + in_addr n; + ConfigReader Conf; + + log(DEBUG,"In InspSocket::BindAddr()"); + for (int j =0; j < Conf.Enumerate("bind"); j++) + { + std::string Type = Conf.ReadValue("bind","type",j); + std::string IP = Conf.ReadValue("bind","address",j); + if (Type == "servers") + { + if ((IP != "*") && (IP != "127.0.0.1")) + { + sockaddr_in s; + + if (inet_aton(IP.c_str(),&n)) + { + log(DEBUG,"Found an IP to bind to: %s",IP.c_str()); + s.sin_addr = n; + s.sin_family = AF_INET; + if (bind(this->fd,(struct sockaddr*)&s,sizeof(s)) < 0) + { + log(DEBUG,"Cant bind()"); + this->state = I_ERROR; + this->OnError(I_ERR_BIND); + this->fd = -1; + return false; + } + log(DEBUG,"bind() reports outbound fd bound to ip %s",IP.c_str()); + return true; + } + else + { + log(DEBUG,"Address '%s' was not an IP address",IP.c_str()); + } + } + } + } + log(DEBUG,"Found no suitable IPs to bind, binding INADDR_ANY"); + return true; +} + bool InspSocket::DoConnect() { log(DEBUG,"In DoConnect()"); @@ -172,6 +215,9 @@ bool InspSocket::DoConnect() return false; } + if (!this->BindAddr()) + return false; + log(DEBUG,"Part 2 DoConnect() %s",this->IP); inet_aton(this->IP,&addy); addr.sin_family = AF_INET; |
