InspIRCd  3.0
socket.h
1 /*
2  * InspIRCd -- Internet Relay Chat Daemon
3  *
4  * Copyright (C) 2009 Daniel De Graaf <[email protected]>
5  * Copyright (C) 2005-2007 Craig Edwards <[email protected]>
6  * Copyright (C) 2007 Dennis Friis <[email protected]>
7  * Copyright (C) 2007 Robin Burchell <[email protected]>
8  * Copyright (C) 2006 Oliver Lupton <[email protected]>
9  * Copyright (C) 2006 William Pitcock <[email protected]>
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 #pragma once
26 
27 #ifndef _WIN32
28 
29 #include <arpa/inet.h>
30 #include <sys/time.h>
31 #include <sys/resource.h>
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <sys/stat.h>
35 #include <netinet/in.h>
36 #include <unistd.h>
37 #include <fcntl.h>
38 #include <netdb.h>
39 
40 #else
41 
42 #include "inspircd_win32wrapper.h"
43 
44 #endif
45 
46 #include <cerrno>
47 
48 /* Contains irc-specific definitions */
49 namespace irc
50 {
55  namespace sockets
56  {
57  union CoreExport sockaddrs
58  {
59  struct sockaddr sa;
60  struct sockaddr_in in4;
61  struct sockaddr_in6 in6;
63  int sa_size() const;
65  int port() const;
67  std::string addr() const;
69  std::string str() const;
70  bool operator==(const sockaddrs& other) const;
71  inline bool operator!=(const sockaddrs& other) const { return !(*this == other); }
72  };
73 
74  struct CoreExport cidr_mask
75  {
77  unsigned char type;
79  unsigned char length;
81  unsigned char bits[16];
82 
83  cidr_mask() {}
85  cidr_mask(const std::string& mask);
87  cidr_mask(const irc::sockets::sockaddrs& addr, int len);
89  bool operator==(const cidr_mask& other) const;
91  bool operator<(const cidr_mask& other) const;
93  bool match(const irc::sockets::sockaddrs& addr) const;
95  std::string str() const;
96  };
97 
110  CoreExport bool MatchCIDR(const std::string &address, const std::string &cidr_mask, bool match_with_username);
111 
118  CoreExport bool aptosa(const std::string& addr, int port, irc::sockets::sockaddrs& sa);
119  }
120 }
121 
123 typedef std::vector<std::pair<irc::sockets::sockaddrs, int> > FailedPortList;
124 
125 #include "socketengine.h"
130 class CoreExport ListenSocket : public EventHandler
131 {
132  public:
133  reference<ConfigTag> bind_tag;
134  const irc::sockets::sockaddrs bind_sa;
135 
136  class IOHookProvRef : public dynamic_reference_nocheck<IOHookProvider>
137  {
138  public:
139  IOHookProvRef()
140  : dynamic_reference_nocheck<IOHookProvider>(NULL, std::string())
141  {
142  }
143  };
144 
145  typedef TR1NS::array<IOHookProvRef, 2> IOHookProvList;
146 
150  IOHookProvList iohookprovs;
151 
154  ListenSocket(ConfigTag* tag, const irc::sockets::sockaddrs& bind_to);
157  ~ListenSocket();
158 
161  void OnEventHandlerRead() CXX11_OVERRIDE;
162 
166  void ResetIOHookProvider();
167 };
Definition: hashcomp.h:69
Definition: configreader.h:36
IOHookProvList iohookprovs
Definition: socket.h:150
Definition: socket.h:57
bool MatchCIDR(const std::string &address, const std::string &cidr_mask, bool match_with_username)
Definition: cidr.cpp:29
Definition: socket.h:136
Definition: dynref.h:95
Definition: socket.h:74
unsigned char type
Definition: socket.h:77
bool aptosa(const std::string &addr, int port, irc::sockets::sockaddrs &sa)
Definition: socket.cpp:102
Definition: socketengine.h:151
Definition: socket.h:130
unsigned char length
Definition: socket.h:79