From c55f9831ab1a2ecde85fa1174c1d9dbebe250a53 Mon Sep 17 00:00:00 2001 From: brain Date: Tue, 27 Jun 2006 17:45:59 +0000 Subject: Added auto-binding, picks the first ip in the 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 --- include/inspsocket.h | 2 ++ src/inspsocket.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/include/inspsocket.h b/include/inspsocket.h index c9cc70acf..7e8593391 100644 --- a/include/inspsocket.h +++ b/include/inspsocket.h @@ -156,6 +156,8 @@ private: */ bool ClosePending; + bool BindAddr(); + public: /** 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; -- cgit v1.2.3