* | 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>
* ---------------------------------------------------
*/
-#ifndef __INSP_SOCKET_H__
-#define __INSP_SOCKET_H__
+#ifndef INSPIRCD_SOCKET_H
+#define INSPIRCD_SOCKET_H
+#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 <sstream>
-#include <string>
+#include <netdb.h>
+#include <errno.h>
-enum InspSocketState { I_DISCONNECTED, I_CONNECTING, I_CONNECTED, I_LISTENING, I_ERROR };
-enum InspSocketError { I_ERR_TIMEOUT, I_ERR_SOCKET, I_ERR_CONNECT, I_ERR_BIND };
+#include "inspircd_config.h"
-class InspSocket
-{
-private:
- int fd;
- std::string host;
- int port;
- InspSocketState state;
- sockaddr_in addr;
- in_addr addy;
- time_t timeout_end;
- bool timeout;
- pollfd polls;
- char ibuf[16384];
- std::string IP;
- sockaddr_in client;
- sockaddr_in server;
- socklen_t length;
-public:
- InspSocket();
- InspSocket(int newfd, char* ip);
- InspSocket(std::string host, int port, bool listening, unsigned long maxtime);
- virtual bool OnConnected();
- virtual void OnError(InspSocketError e);
- virtual int OnDisconnect();
- virtual bool OnDataReady();
- virtual void OnTimeout();
- virtual void OnClose();
- virtual char* Read();
- std::string GetIP();
- bool Timeout(time_t current);
- virtual int Write(std::string data);
- virtual int OnIncomingConnection(int newfd, char* ip);
- void SetState(InspSocketState s);
- InspSocketState GetState();
- bool Poll();
- int GetFd();
- virtual void Close();
- virtual ~InspSocket();
-};
+/* macros to the relevant system address description structs */
+#ifdef IPV6
+
+typedef struct sockaddr_in6 insp_sockaddr;
+typedef struct in6_addr insp_inaddr;
+
+#else
+
+typedef struct sockaddr_in insp_sockaddr;
+typedef struct in_addr insp_inaddr;
+
+#endif
+
+int OpenTCPSocket();
+bool BindSocket(int sockfd, insp_sockaddr client, insp_sockaddr server, int port, char* addr);
+int BindPorts(bool bail);
#endif