]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - include/socket.h
Much faster hash<string> for case-insensitive hashing, combined copy and lowercase...
[user/henk/code/inspircd.git] / include / socket.h
index 3e681f1c4b27b4fde7e2fa428e26cfcb30cfad4b..8219ff5dd8b2bf59c6023ef79f6967d1ea7dcdbc 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
  * ---------------------------------------------------
  */
 
-#include <sstream>
-#include <string>
+#ifndef INSPIRCD_SOCKET_H
+#define INSPIRCD_SOCKET_H
 
-enum InspSocketState { I_DISCONNECTED, I_CONNECTING, I_CONNECTED, I_LISTENING };
+#include <arpa/inet.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <poll.h>
+#include <netdb.h>
+#include <errno.h>
 
-class InspSocket
+#include "inspircd_config.h"
+
+namespace irc
 {
-private:
-        int fd;
-       std::string host;
-       int port;
-       InspSocketState state;
-public:
-       InspSocket();
-       InspSocket(std::string host, int port, bool listening);
-       void Poll();
-       virtual int OnConnected();
-       virtual int OnError();
-       virtual int OnDisconnect();
-       virtual int OnIncomingConnection();
-       ~InspSocket();
+       namespace sockets
+       {
+
+       /* macros to the relevant system address description structs */
+#ifdef IPV6
+
+               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;
+#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);
+
+               const char* insp_ntoa(insp_inaddr n);
+               int insp_aton(const char* a, insp_inaddr* n);
+
+               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);
+       };
 };
+
+#endif