00001 /*************************************************************************** 00002 sock_shared.h - description 00003 ------------------- 00004 begin : Thu Dec 9 2004 00005 copyright : (C) 2004 by VooDooMan 00006 email : vdmfun@hotmail.com 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 00011 VooDoo cIRCle - an IRC (ro)bot 00012 Copyright (C) 2004 by Marian VooDooMan Meravy (vdmfun@hotmail.com) 00013 00014 This program is free software; you can redistribute it and/or 00015 modify it under the terms of the GNU General Public License 00016 as published by the Free Software Foundation; either version 2 00017 of the License, or (at your option) any later version. 00018 00019 This program is distributed in the hope that it will be useful, 00020 but WITHOUT ANY WARRANTY; without even the implied warranty of 00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00022 GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License 00025 along with this program; if not, write to the Free Software 00026 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00027 00028 ****************************************************************************/ 00029 00030 /*! 00031 \file 00032 \brief Provides low-level implementation of TCP IP sockets 00033 */ 00034 00035 #ifndef _SOCK_SHARED_H_ 00036 #define _SOCK_SHARED_H_ 00037 00038 #include <time.h> 00039 00040 #ifndef _WIN32 00041 # include <sys/types.h> 00042 # include <sys/socket.h> 00043 # include <netinet/in.h> 00044 # include <arpa/inet.h> 00045 # include <netdb.h> 00046 00047 # include <errno.h> 00048 # include <fcntl.h> 00049 00050 # define WSAGetLastError() errno 00051 # define WSAEWOULDBLOCK EAGAIN 00052 # define closesocket close 00053 # define ioctlsocket ioctl 00054 # define SOCKET int 00055 # define PROTOENT protoent 00056 # define SOCKET_ERROR -1 00057 # define INVALID_SOCKET -1 00058 #else 00059 # include <winsock2.h> 00060 #endif 00061 00062 /*! 00063 \brief Stores informnations about socket handle 00064 \author VooDooMan 00065 \version 1 00066 \date 2004 00067 */ 00068 struct s_socket { 00069 #ifdef _WIN32 00070 SOCKET handle; //!< Handle to socket (Windows(TM) only) 00071 HWND wnd; 00072 #else 00073 SOCKET handle; 00074 #endif 00075 00076 size_t received; //!< Number of bytes received 00077 size_t sent; //!< Number of bytes sent 00078 00079 bool ssl_accepted; //!< Were we called ssl_server_accept() ? 00080 int ssl_data_index; //!< If ssl_accepted==true, this is SSL's user data (something like context index) 00081 00082 time_t last_io; //!< Timestamp of last receive, or send data (only for client sockets) 00083 00084 char host[2048]; //!< If it is IPv6 server, there is numeric host of remote peer 00085 00086 /*! 00087 \brief Clears the structure 00088 \author VooDooMan 00089 \version 1 00090 \date 2004 00091 */ 00092 void clear() { 00093 handle=(unsigned)-1; 00094 received=sent=0; 00095 ssl_accepted=false; 00096 host[0]=0; 00097 last_io=time(NULL); 00098 } 00099 00100 /*! 00101 \brief Returns true if handle to socket is not -1 00102 \author VooDooMan 00103 \version 1 00104 \date 2004 00105 */ 00106 bool cmp() 00107 { 00108 return handle!=-1; 00109 } 00110 00111 /*! 00112 \brief Compares two handles for identicality 00113 \author VooDooMan 00114 \version 1 00115 \date 2004 00116 */ 00117 bool operator== (s_socket& x) { 00118 return this->handle==x.handle; 00119 } 00120 00121 s_socket() { 00122 clear(); 00123 } 00124 }; 00125 00126 /*! 00127 \brief Stores IPv6 address 00128 \author VooDooMan 00129 \version 1 00130 \date 2004 00131 */ 00132 struct in_addr6_ { 00133 unsigned char bytes[16]; //!< 16 bytes of IPv6 address 00134 }; 00135 00136 #endif