The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

socket.h

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 #ifndef INSPIRCD_SOCKET_H
00015 #define INSPIRCD_SOCKET_H
00016 
00017 #ifndef WIN32
00018 
00019 #include <arpa/inet.h>
00020 #include <sys/time.h>
00021 #include <sys/resource.h>
00022 #include <sys/types.h>
00023 #include <sys/socket.h>
00024 #include <sys/stat.h>
00025 #include <netinet/in.h>
00026 #include <unistd.h>
00027 #include <fcntl.h>
00028 #include <netdb.h>
00029 
00030 #else
00031 
00032 #include "inspircd_win32wrapper.h"
00033 
00034 #endif
00035 
00036 #include <cerrno>
00037 #include "socketengine.h"
00038 
00039 /* Contains irc-specific definitions */
00040 namespace irc
00041 {
00046         namespace sockets
00047         {
00048 
00049         /* macros to the relevant system address description structs */
00050 #ifdef IPV6
00051 
00053                 typedef struct sockaddr_in6 insp_sockaddr;
00056                 typedef struct in6_addr     insp_inaddr;
00057 #define AF_FAMILY AF_INET6
00058 #define PF_PROTOCOL PF_INET6
00059 
00060 #else
00061 
00063                 typedef struct sockaddr_in  insp_sockaddr;
00066                 typedef struct in_addr      insp_inaddr;
00067 #define AF_FAMILY AF_INET
00068 #define PF_PROTOCOL PF_INET
00069 
00070 #endif
00071 
00084                 CoreExport bool MatchCIDRBits(const unsigned char* address, const unsigned char* mask, unsigned int mask_bits);
00085 
00095                 CoreExport bool MatchCIDR(const std::string &address, const std::string &cidr_mask);
00096 
00108                 CoreExport bool MatchCIDR(const std::string &address, const std::string &cidr_mask, bool match_with_username);
00109 
00116                 CoreExport const char* insp_ntoa(insp_inaddr n);
00117 
00131                 CoreExport int insp_aton(const char* a, insp_inaddr* n);
00132 
00138                 CoreExport int OpenTCPSocket(char* addr, int socktype = SOCK_STREAM);
00139         }
00140 }
00141 
00146 class CoreExport ListenSocket : public EventHandler
00147 {
00148  protected:
00151         InspIRCd* ServerInstance;
00153         std::string desc;
00155         int family;
00157         std::string bind_addr;
00159         int bind_port;
00160 
00161         static sockaddr *sock_us;
00162 
00163         static sockaddr *client;
00164 
00165         static sockaddr *raddr;
00166 
00167         static unsigned int socketcount;
00168 
00169  public:
00172         ListenSocket(InspIRCd* Instance, int port, char* addr);
00175         void HandleEvent(EventType et, int errornum = 0);
00178         ~ListenSocket();
00181         void SetDescription(const std::string &description)
00182         {
00183                 desc = description;
00184         }
00187         const std::string& GetDescription()
00188         {
00189                 return desc;
00190         }
00193         int GetPort()
00194         {
00195                 return bind_port;
00196         }
00199         std::string &GetIP()
00200         {
00201                 return bind_addr;
00202         }
00203 };
00204 
00205 #endif
00206