summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/dns.h6
-rw-r--r--include/hashcomp.h3
-rw-r--r--include/inspsocket.h5
-rw-r--r--include/socket.h37
-rw-r--r--src/configreader.cpp2
-rw-r--r--src/dns.cpp7
-rw-r--r--src/hashcomp.cpp1
-rw-r--r--src/inspircd.cpp6
-rw-r--r--src/inspsocket.cpp4
-rw-r--r--src/modules/m_spanningtree.cpp2
-rw-r--r--src/socket.cpp25
-rw-r--r--src/wildcard.cpp2
12 files changed, 75 insertions, 25 deletions
diff --git a/include/dns.h b/include/dns.h
index ebe628bb9..c3b74fdca 100644
--- a/include/dns.h
+++ b/include/dns.h
@@ -40,6 +40,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include "socket.h"
#include "base.h"
+using namespace std;
+using irc::sockets::insp_aton;
+using irc::sockets::insp_ntoa;
+using irc::sockets::insp_sockaddr;
+using irc::sockets::insp_inaddr;
+
class InspIRCd;
/**
diff --git a/include/hashcomp.h b/include/hashcomp.h
index 714d3286f..6c90ee919 100644
--- a/include/hashcomp.h
+++ b/include/hashcomp.h
@@ -37,6 +37,9 @@
*******************************************************/
using namespace std;
+using irc::sockets::insp_aton;
+using irc::sockets::insp_ntoa;
+using irc::sockets::insp_inaddr;
namespace nspace
{
diff --git a/include/inspsocket.h b/include/inspsocket.h
index 42ce01a27..ddb0baedb 100644
--- a/include/inspsocket.h
+++ b/include/inspsocket.h
@@ -37,6 +37,11 @@ enum InspSocketError { I_ERR_TIMEOUT, I_ERR_SOCKET, I_ERR_CONNECT, I_ERR_BIND, I
class InspSocket;
class InspIRCd;
+using irc::sockets::insp_sockaddr;
+using irc::sockets::insp_inaddr;
+using irc::sockets::insp_ntoa;
+using irc::sockets::insp_aton;
+
/**
* InspSocket is an extendable socket class which modules
* can use for TCP socket support. It is fully integrated
diff --git a/include/socket.h b/include/socket.h
index ed6373ce8..8219ff5dd 100644
--- a/include/socket.h
+++ b/include/socket.h
@@ -32,35 +32,42 @@
#include "inspircd_config.h"
-/* macros to the relevant system address description structs */
+namespace irc
+{
+ namespace sockets
+ {
+
+ /* macros to the relevant system address description structs */
#ifdef IPV6
-typedef struct sockaddr_in6 insp_sockaddr;
-typedef struct in6_addr insp_inaddr;
+ typedef struct sockaddr_in6 insp_sockaddr;
+ typedef struct in6_addr insp_inaddr;
#define AF_FAMILY AF_INET6
#define PF_PROTOCOL PF_INET6
#else
-typedef struct sockaddr_in insp_sockaddr;
-typedef struct in_addr insp_inaddr;
+ typedef struct sockaddr_in insp_sockaddr;
+ typedef struct in_addr insp_inaddr;
#define AF_FAMILY AF_INET
#define PF_PROTOCOL PF_INET
#endif
-bool MatchCIDRBits(unsigned char* address, unsigned char* mask, unsigned int mask_bits);
-bool MatchCIDR(const char* address, const char* cidr_mask);
-bool MatchCIDR(const char* address, const char* cidr_mask, bool match_with_username);
+ bool MatchCIDRBits(unsigned char* address, unsigned char* mask, unsigned int mask_bits);
+ bool MatchCIDR(const char* address, const char* cidr_mask);
+ bool MatchCIDR(const char* address, const char* cidr_mask, bool match_with_username);
-const char* insp_ntoa(insp_inaddr n);
-int insp_aton(const char* a, insp_inaddr* n);
+ const char* insp_ntoa(insp_inaddr n);
+ int insp_aton(const char* a, insp_inaddr* n);
-void Blocking(int s);
-void NonBlocking(int s);
+ void Blocking(int s);
+ void NonBlocking(int s);
-int OpenTCPSocket();
-bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr);
-int BindPorts(bool bail);
+ int OpenTCPSocket();
+ bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr);
+ int BindPorts(bool bail);
+ };
+};
#endif
diff --git a/src/configreader.cpp b/src/configreader.cpp
index c8ecdaf39..0b712ca6c 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -34,6 +34,8 @@ extern int MODCOUNT;
extern std::vector<Module*> modules;
extern std::vector<ircd_module*> factory;
+using irc::sockets::BindPorts;
+
std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules;
ServerConfig::ServerConfig()
diff --git a/src/dns.cpp b/src/dns.cpp
index 9bc81e453..b67fef8d9 100644
--- a/src/dns.cpp
+++ b/src/dns.cpp
@@ -42,6 +42,13 @@ using namespace std;
#include "inspircd_config.h"
#include "socketengine.h"
#include "configreader.h"
+#include "socket.h"
+
+using namespace std;
+using irc::sockets::insp_sockaddr;
+using irc::sockets::insp_inaddr;
+using irc::sockets::insp_ntoa;
+using irc::sockets::insp_aton;
/* Master file descriptor */
int DNS::MasterSocket;
diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp
index bfbabfde9..278ea0044 100644
--- a/src/hashcomp.cpp
+++ b/src/hashcomp.cpp
@@ -58,6 +58,7 @@ extern const char lowermap[255];
******************************************************/
using namespace std;
+using namespace irc::sockets;
size_t nspace::hash<insp_inaddr>::operator()(const insp_inaddr &a) const
{
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index a4b6181ab..aaf20062f 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -65,6 +65,12 @@
#include "typedefs.h"
#include "command_parse.h"
+using irc::sockets::BindPorts;
+using irc::sockets::NonBlocking;
+using irc::sockets::insp_ntoa;
+using irc::sockets::insp_inaddr;
+using irc::sockets::insp_sockaddr;
+
InspIRCd* ServerInstance = NULL;
extern ModuleList modules;
diff --git a/src/inspsocket.cpp b/src/inspsocket.cpp
index 6a0fbc556..187a5265d 100644
--- a/src/inspsocket.cpp
+++ b/src/inspsocket.cpp
@@ -28,6 +28,10 @@
#include "message.h"
#include "inspircd.h"
+using irc::sockets::BindSocket;
+using irc::sockets::OpenTCPSocket;
+using irc::sockets::insp_inaddr;
+using irc::sockets::insp_sockaddr;
extern time_t TIME;
extern Server* MyServer;
diff --git a/src/modules/m_spanningtree.cpp b/src/modules/m_spanningtree.cpp
index 003a4868d..72ae322f6 100644
--- a/src/modules/m_spanningtree.cpp
+++ b/src/modules/m_spanningtree.cpp
@@ -65,6 +65,8 @@ using namespace std;
* we can resort to recursion to walk the tree structure.
*/
+using irc::sockets::MatchCIDR;
+
class ModuleSpanningTree;
static ModuleSpanningTree* TreeProtocolModule;
diff --git a/src/socket.cpp b/src/socket.cpp
index 693685428..0f84912de 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -27,6 +27,9 @@
extern InspIRCd* ServerInstance;
extern time_t TIME;
+using namespace std;
+using namespace irc::sockets;
+
/* Used when comparing CIDR masks for the modulus bits left over.
* A lot of ircd's seem to do this:
* ((-1) << (8 - (mask % 8)))
@@ -43,7 +46,7 @@ const char inverted_bits[8] = { 0x00, /* 00000000 - 0 bits - never actually used
};
/* Match raw bytes using CIDR bit matching, used by higher level MatchCIDR() */
-bool MatchCIDRBits(unsigned char* address, unsigned char* mask, unsigned int mask_bits)
+bool irc::sockets::MatchCIDRBits(unsigned char* address, unsigned char* mask, unsigned int mask_bits)
{
unsigned int modulus = mask_bits % 8; /* Number of whole bytes in the mask */
unsigned int divisor = mask_bits / 8; /* Remaining bits in the mask after whole bytes are dealt with */
@@ -63,7 +66,7 @@ bool MatchCIDRBits(unsigned char* address, unsigned char* mask, unsigned int mas
}
/* Match CIDR, but dont attempt to match() against leading *!*@ sections */
-bool MatchCIDR(const char* address, const char* cidr_mask)
+bool irc::sockets::MatchCIDR(const char* address, const char* cidr_mask)
{
return MatchCIDR(address, cidr_mask, false);
}
@@ -75,7 +78,7 @@ bool MatchCIDR(const char* address, const char* cidr_mask)
* This will also attempt to match any leading usernames or nicknames on the mask, using
* match(), when match_with_username is true.
*/
-bool MatchCIDR(const char* address, const char* cidr_mask, bool match_with_username)
+bool irc::sockets::MatchCIDR(const char* address, const char* cidr_mask, bool match_with_username)
{
unsigned char addr_raw[16];
unsigned char mask_raw[16];
@@ -208,13 +211,13 @@ bool MatchCIDR(const char* address, const char* cidr_mask, bool match_with_usern
return MatchCIDRBits(addr_raw, mask_raw, bits);
}
-inline void Blocking(int s)
+inline void irc::sockets::Blocking(int s)
{
int flags = fcntl(s, F_GETFL, 0);
fcntl(s, F_SETFL, flags ^ O_NONBLOCK);
}
-inline void NonBlocking(int s)
+inline void irc::sockets::NonBlocking(int s)
{
int flags = fcntl(s, F_GETFL, 0);
fcntl(s, F_SETFL, flags | O_NONBLOCK);
@@ -225,7 +228,7 @@ inline void NonBlocking(int s)
* It can only bind to IP addresses, if you wish to bind to hostnames
* you should first resolve them using class 'Resolver'.
*/
-bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr)
+bool irc::sockets::BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr)
{
memset(&server,0,sizeof(server));
insp_inaddr addy;
@@ -287,7 +290,7 @@ bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port
// Open a TCP Socket
-int OpenTCPSocket()
+int irc::sockets::OpenTCPSocket()
{
int sockfd;
int on = 1;
@@ -309,6 +312,7 @@ int OpenTCPSocket()
}
}
+/* XXX: Probably belongs in class InspIRCd */
bool HasPort(int port, char* addr)
{
ServerConfig* Config = ServerInstance->Config;
@@ -322,7 +326,8 @@ bool HasPort(int port, char* addr)
return false;
}
-int BindPorts(bool bail)
+/* XXX: Probably belongs in class InspIRCd */
+int irc::sockets::BindPorts(bool bail)
{
char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
insp_sockaddr client, server;
@@ -442,14 +447,14 @@ int BindPorts(bool bail)
return BoundPortCount;
}
-const char* insp_ntoa(insp_inaddr n)
+const char* irc::sockets::insp_ntoa(insp_inaddr n)
{
static char buf[1024];
inet_ntop(AF_FAMILY, &n, buf, sizeof(buf));
return buf;
}
-int insp_aton(const char* a, insp_inaddr* n)
+int irc::sockets::insp_aton(const char* a, insp_inaddr* n)
{
return inet_pton(AF_FAMILY, a, n);
}
diff --git a/src/wildcard.cpp b/src/wildcard.cpp
index e626f2aa2..6b84ef5b3 100644
--- a/src/wildcard.cpp
+++ b/src/wildcard.cpp
@@ -22,6 +22,8 @@ using namespace std;
#include "helperfuncs.h"
#include "inspstring.h"
+using irc::sockets::MatchCIDR;
+
extern char lowermap[255];
// Wed 27 Apr 2005 - Brain