summaryrefslogtreecommitdiff
path: root/src/inspsocket.cpp
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-06-27 17:45:59 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2006-06-27 17:45:59 +0000
commitc55f9831ab1a2ecde85fa1174c1d9dbebe250a53 (patch)
tree5671cd71c4e5dcda43bda18708d75b9d62c8ff56 /src/inspsocket.cpp
parent1805486ae50cbeaaffcef37e66e79f3d985da4bf (diff)
Added auto-binding, picks the first ip in the <bind> tags that isnt localhost or INADDR_ANY, and auto binds to that IP to allow us to put back the security tweak
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4064 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/inspsocket.cpp')
-rw-r--r--src/inspsocket.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp
index 74931cee3..1989e43b1 100644
--- a/src/inspsocket.cpp
+++ b/src/inspsocket.cpp
@@ -157,6 +157,49 @@ bool InspSocket::DoResolve()
return true;
}
+bool InspSocket::BindAddr()
+{
+ insp_inaddr 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"))
+ {
+ insp_sockaddr 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()");
@@ -169,6 +212,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;