Logo
~Sockets~
~Examples~
~Contact~


socket_include.h

Go to the documentation of this file.
00001 
00005 /*
00006 Copyright (C) 2004-2007  Anders Hedstrom
00007 
00008 This library is made available under the terms of the GNU GPL.
00009 
00010 If you would like to use this library in a closed-source application,
00011 a separate license agreement is available. For information about 
00012 the closed-source license agreement for the C++ sockets library,
00013 please visit http://www.alhem.net/Sockets/license.html and/or
00014 email license@alhem.net.
00015 
00016 This program is free software; you can redistribute it and/or
00017 modify it under the terms of the GNU General Public License
00018 as published by the Free Software Foundation; either version 2
00019 of the License, or (at your option) any later version.
00020 
00021 This program is distributed in the hope that it will be useful,
00022 but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 GNU General Public License for more details.
00025 
00026 You should have received a copy of the GNU General Public License
00027 along with this program; if not, write to the Free Software
00028 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00029 */
00030 #ifndef _SOCKETS_socket_include_H
00031 #define _SOCKETS_socket_include_H
00032 #include "sockets-config.h"
00033 
00034 #ifdef _WIN32
00035 #pragma warning(disable:4514)
00036 #endif
00037 
00038 // common defines affecting library and applications using library
00039 
00040 /* Define SOCKETS_DYNAMIC_TEMP to use dynamically allocated buffers
00041    in read operations - helps on ECOS */
00042 #define SOCKETS_DYNAMIC_TEMP
00043 
00044 
00045 // platform specific stuff
00046 #if (defined(__unix__) || defined(unix)) && !defined(USG)
00047 #include <sys/param.h>
00048 #endif
00049 #include <list>
00050 
00051 #ifndef _WIN32 
00052 // ----------------------------------------
00053 // common unix includes / defines
00054 #include <unistd.h>
00055 #include <sys/time.h>
00056 #include <sys/types.h>
00057 #include <sys/socket.h>
00058 #include <netinet/in.h>
00059 #include <arpa/inet.h>
00060 //#include <netdb.h>
00061 
00062 // all typedefs in this file will be declared outside the sockets namespace,
00063 // because some os's will already have one or more of the type defined.
00064 typedef int SOCKET;
00065 #define Errno errno
00066 #define StrError strerror
00067 
00068 #ifdef SOCKETS_NAMESPACE
00069 namespace SOCKETS_NAMESPACE {
00070 #endif
00071 
00072 
00073 // WIN32 adapt
00074 #define closesocket close
00075 #define INVALID_SOCKET -1
00076 #define SOCKET_ERROR -1
00077 
00078 #ifndef INADDR_NONE
00079 #define INADDR_NONE ((unsigned long) -1)
00080 #endif // INADDR_NONE
00081 
00082 #ifdef SOCKETS_NAMESPACE
00083 }
00084 #endif
00085 
00086 #endif // !_WIN32
00087 
00088 
00089 // ----------------------------------------
00090 // Generic
00091 #ifndef SOL_IP
00092 #define SOL_IP IPPROTO_IP
00093 #endif
00094 
00095 
00096 // ----------------------------------------
00097 // OS specific adaptions
00098 
00099 #ifdef SOLARIS 
00100 // ----------------------------------------
00101 // Solaris
00102 typedef unsigned short port_t;
00103 #ifdef SOCKETS_NAMESPACE
00104 namespace SOCKETS_NAMESPACE {
00105 #endif
00106 // no defs
00107 
00108 #ifdef SOCKETS_NAMESPACE
00109 }
00110 #endif
00111 
00112 #define s6_addr16 _S6_un._S6_u8
00113 #define MSG_NOSIGNAL 0
00114 
00115 #elif defined __FreeBSD__
00116 // ----------------------------------------
00117 // FreeBSD
00118 # if __FreeBSD_version >= 400014
00119 #  define s6_addr16 __u6_addr.__u6_addr16
00120 #  if !defined(MSG_NOSIGNAL)
00121 #   define MSG_NOSIGNAL 0
00122 #  endif
00123 #  include <netinet/in.h>
00124 typedef in_addr_t ipaddr_t;
00125 typedef in_port_t port_t;
00126 #ifdef SOCKETS_NAMESPACE
00127 namespace SOCKETS_NAMESPACE {
00128 #endif
00129 // no defs
00130 
00131 #ifdef SOCKETS_NAMESPACE
00132 }
00133 #endif
00134 
00135 #  define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
00136 #  define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
00137 # else
00138 #  error FreeBSD versions prior to 400014 does not support ipv6
00139 # endif
00140 
00141 #elif defined MACOSX 
00142 // ----------------------------------------
00143 // Mac OS X
00144 #include <string.h>
00145 #include <mach/port.h>
00146 typedef unsigned long ipaddr_t;
00147 #ifdef SOCKETS_NAMESPACE
00148 namespace SOCKETS_NAMESPACE {
00149 #endif
00150 // no defs
00151 
00152 #ifdef SOCKETS_NAMESPACE
00153 }
00154 #endif
00155 
00156 #define s6_addr16 __u6_addr.__u6_addr16
00157 #define MSG_NOSIGNAL 0 // oops - thanks Derek
00158 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
00159 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
00160 
00161 #elif defined _WIN32 
00162 // ----------------------------------------
00163 // Win32
00164 #pragma comment(lib, "wsock32.lib")
00165 #define strcasecmp _stricmp
00166 
00167 typedef unsigned long ipaddr_t;
00168 typedef unsigned short port_t;
00169 typedef int socklen_t;
00170 #ifdef SOCKETS_NAMESPACE
00171 namespace SOCKETS_NAMESPACE {
00172 #endif
00173 // no defs
00174 
00175 #ifdef SOCKETS_NAMESPACE
00176 }
00177 #endif
00178 
00179 // 1.8.6: define FD_SETSIZE to something bigger than 64 if there are a lot of
00180 // simultaneous connections (must be done before including winsock.h)
00181 //#define FD_SETSIZE 1024
00182 
00183 // windows 2000 with ipv6 preview installed:
00184 //    http://msdn.microsoft.com/downloads/sdks/platform/tpipv6.asp
00185 // see the FAQ on how to install
00186 #define WIN32_LEAN_AND_MEAN
00187 #include <winsock2.h>
00188 #include <ws2tcpip.h>
00189 #if MSC_VER < 1200
00190 #ifndef __CYGWIN__
00191 #ifdef ENABLE_IPV6
00192 #include <tpipv6.h>  // For IPv6 Tech Preview.
00193 #endif
00194 #endif
00195 #endif // MSC_VER < 1200
00196 
00197 
00198 #define MSG_NOSIGNAL 0
00199 //#define SHUT_RDWR 2
00200 #define SHUT_WR 1
00201 
00202 #define Errno WSAGetLastError()
00203 const char *StrError(int x);
00204 
00205 #ifdef SOCKETS_NAMESPACE
00206 namespace SOCKETS_NAMESPACE {
00207 #endif
00208 
00209 
00210 // class WSAInitializer is a part of the Socket class (on win32)
00211 // as a static instance - so whenever an application uses a Socket,
00212 // winsock is initialized
00213 class WSAInitializer // Winsock Initializer
00214 {
00215 public:
00216         WSAInitializer() {
00217                 if (WSAStartup(0x101,&m_wsadata)) 
00218                 {
00219                         exit(-1);
00220                 }
00221         }
00222         ~WSAInitializer() {
00223                 WSACleanup();
00224         }
00225 private:
00226         WSADATA m_wsadata;
00227 };
00228 
00229 #ifdef SOCKETS_NAMESPACE
00230 }
00231 #endif
00232 
00233 #else 
00234 // ----------------------------------------
00235 // LINUX 
00236 typedef unsigned long ipaddr_t;
00237 typedef unsigned short port_t;
00238 #ifdef SOCKETS_NAMESPACE
00239 namespace SOCKETS_NAMESPACE {
00240 #endif
00241 // no defs
00242 
00243 #ifdef SOCKETS_NAMESPACE
00244 }
00245 #endif
00246 
00247 
00248 #endif
00249 
00250 #ifdef SOCKETS_NAMESPACE
00251 namespace SOCKETS_NAMESPACE {
00252 #endif
00253 
00254         typedef std::list<SOCKET> socket_v;
00255 
00256 
00257 #ifdef SOCKETS_NAMESPACE
00258 }
00259 #endif
00260 
00261 
00262 // getaddrinfo / getnameinfo replacements
00263 #ifdef NO_GETADDRINFO
00264 #ifndef AI_NUMERICHOST
00265 #define AI_NUMERICHOST 1
00266 #endif
00267 #ifndef NI_NUMERICHOST
00268 #define NI_NUMERICHOST 1
00269 #endif
00270 #endif
00271 
00272 
00273 #endif // _SOCKETS_socket_include_H
Page, code, and content Copyright (C) 2007 by Anders Hedström
Generated for C++ Sockets by  doxygen 1.4.4