InspIRCd  2.0
 All Classes Namespaces Functions Variables Typedefs Enumerations
socket.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
5  * Copyright (C) 2005-2007 Craig Edwards <craigedwards@brainbox.cc>
6  * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
7  * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
8  * Copyright (C) 2006 Oliver Lupton <oliverlupton@gmail.com>
9  * Copyright (C) 2006 William Pitcock <nenolod@dereferenced.org>
10  *
11  * This file is part of InspIRCd. InspIRCd is free software: you can
12  * redistribute it and/or modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation, version 2.
14  *
15  * This program is distributed in the hope that it will be useful, but WITHOUT
16  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 
25 #ifndef INSPIRCD_SOCKET_H
26 #define INSPIRCD_SOCKET_H
27 
28 #ifndef _WIN32
29 
30 #include <arpa/inet.h>
31 #include <sys/time.h>
32 #include <sys/resource.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <sys/stat.h>
36 #include <netinet/in.h>
37 #include <unistd.h>
38 #include <fcntl.h>
39 #include <netdb.h>
40 
41 #else
42 
43 #include "inspircd_win32wrapper.h"
44 
45 #endif
46 
47 #include <cerrno>
48 
49 /* Contains irc-specific definitions */
50 namespace irc
51 {
56  namespace sockets
57  {
58  union CoreExport sockaddrs
59  {
60  struct sockaddr sa;
61  struct sockaddr_in in4;
62  struct sockaddr_in6 in6;
64  int sa_size() const;
66  int port() const;
68  std::string addr() const;
70  std::string str() const;
71  bool operator==(const sockaddrs& other) const;
72  inline bool operator!=(const sockaddrs& other) const { return !(*this == other); }
73  };
74 
75  struct CoreExport cidr_mask
76  {
78  unsigned char type;
80  unsigned char length;
82  unsigned char bits[16];
83 
84  cidr_mask() {}
86  cidr_mask(const std::string& mask);
88  cidr_mask(const irc::sockets::sockaddrs& addr, int len);
90  bool operator==(const cidr_mask& other) const;
92  bool operator<(const cidr_mask& other) const;
94  bool match(const irc::sockets::sockaddrs& addr) const;
96  std::string str() const;
97  };
98 
111  CoreExport bool MatchCIDR(const std::string &address, const std::string &cidr_mask, bool match_with_username);
112 
114  inline int sa_size(const irc::sockets::sockaddrs& sa) { return sa.sa_size(); }
115 
122  CoreExport bool aptosa(const std::string& addr, int port, irc::sockets::sockaddrs& sa);
123 
130  CoreExport bool satoap(const irc::sockets::sockaddrs& sa, std::string& addr, int &port);
131 
137  inline std::string satouser(const irc::sockets::sockaddrs& sa) { return sa.str(); }
138  }
139 }
140 
141 #include "socketengine.h"
146 class CoreExport ListenSocket : public EventHandler
147 {
148  public:
149  reference<ConfigTag> bind_tag;
150  std::string bind_addr;
151  int bind_port;
153  std::string bind_desc;
156  ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_to);
159  void HandleEvent(EventType et, int errornum = 0);
162  ~ListenSocket();
163 
166  void AcceptInternal();
167 };
168 
169 #endif
170 
Definition: configreader.h:37
CoreExport bool satoap(const irc::sockets::sockaddrs &sa, std::string &addr, int &port)
Definition: socket.cpp:213
virtual void HandleEvent(EventType et, int errornum=0)=0
int sa_size(const irc::sockets::sockaddrs &sa)
Definition: socket.h:114
Definition: socket.h:58
CoreExport bool MatchCIDR(const std::string &address, const std::string &cidr_mask, bool match_with_username)
Definition: cidr.cpp:31
std::string bind_desc
Definition: socket.h:153
std::string str() const
Definition: socket.cpp:220
Definition: socket.h:75
unsigned char type
Definition: socket.h:78
CoreExport bool aptosa(const std::string &addr, int port, irc::sockets::sockaddrs &sa)
Definition: socket.cpp:154
int sa_size() const
Definition: socket.cpp:242
Definition: socketengine.h:164
Definition: socket.h:146
unsigned char length
Definition: socket.h:80
std::string satouser(const irc::sockets::sockaddrs &sa)
Definition: socket.h:137