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 // getaddrinfo / getnameinfo replacements
00046 #ifdef NO_GETADDRINFO
00047 #ifndef AI_NUMERICHOST
00048 #define AI_NUMERICHOST 1
00049 #endif
00050 #ifndef NI_NUMERICHOST
00051 #define NI_NUMERICHOST 1
00052 #endif
00053 #endif
00054 
00055 
00056 // platform specific stuff
00057 #if (defined(__unix__) || defined(unix)) && !defined(USG)
00058 #include <sys/param.h>
00059 #endif
00060 #include <list>
00061 
00062 #ifndef _WIN32 
00063 // ----------------------------------------
00064 // common unix includes / defines
00065 #include <unistd.h>
00066 #include <sys/time.h>
00067 #include <sys/types.h>
00068 #include <sys/socket.h>
00069 #include <netinet/in.h>
00070 #include <arpa/inet.h>
00071 //#include <netdb.h>
00072 
00073 // all typedefs in this file will be declared outside the sockets namespace,
00074 // because some os's will already have one or more of the type defined.
00075 typedef int SOCKET;
00076 #define Errno errno
00077 #define StrError strerror
00078 
00079 #ifdef SOCKETS_NAMESPACE
00080 namespace SOCKETS_NAMESPACE {
00081 #endif
00082 
00083 
00084 // WIN32 adapt
00085 #define closesocket close
00086 #define INVALID_SOCKET -1
00087 #define SOCKET_ERROR -1
00088 
00089 #ifndef INADDR_NONE
00090 #define INADDR_NONE ((unsigned long) -1)
00091 #endif // INADDR_NONE
00092 
00093 #ifdef SOCKETS_NAMESPACE
00094 }
00095 #endif
00096 
00097 #endif // !_WIN32
00098 
00099 
00100 // ----------------------------------------
00101 // Generic
00102 #ifndef SOL_IP
00103 #define SOL_IP IPPROTO_IP
00104 #endif
00105 
00106 
00107 // ----------------------------------------
00108 // OS specific adaptions
00109 
00110 #ifdef SOLARIS 
00111 // ----------------------------------------
00112 // Solaris
00113 typedef unsigned short port_t;
00114 #ifdef SOCKETS_NAMESPACE
00115 namespace SOCKETS_NAMESPACE {
00116 #endif
00117 // no defs
00118 
00119 #ifdef SOCKETS_NAMESPACE
00120 }
00121 #endif
00122 
00123 #define s6_addr16 _S6_un._S6_u8
00124 #define MSG_NOSIGNAL 0
00125 
00126 #elif defined __FreeBSD__
00127 // ----------------------------------------
00128 // FreeBSD
00129 # if __FreeBSD_version >= 400014
00130 #  define s6_addr16 __u6_addr.__u6_addr16
00131 #  if !defined(MSG_NOSIGNAL)
00132 #   define MSG_NOSIGNAL 0
00133 #  endif
00134 #  include <netinet/in.h>
00135 typedef in_addr_t ipaddr_t;
00136 typedef in_port_t port_t;
00137 #ifdef SOCKETS_NAMESPACE
00138 namespace SOCKETS_NAMESPACE {
00139 #endif
00140 // no defs
00141 
00142 #ifdef SOCKETS_NAMESPACE
00143 }
00144 #endif
00145 
00146 #  define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
00147 #  define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
00148 # else
00149 #  error FreeBSD versions prior to 400014 does not support ipv6
00150 # endif
00151 
00152 #elif defined MACOSX 
00153 // ----------------------------------------
00154 // Mac OS X
00155 #include <string.h>
00156 #include <mach/port.h>
00157 typedef unsigned long ipaddr_t;
00158 #ifdef SOCKETS_NAMESPACE
00159 namespace SOCKETS_NAMESPACE {
00160 #endif
00161 // no defs
00162 
00163 #ifdef SOCKETS_NAMESPACE
00164 }
00165 #endif
00166 
00167 #define s6_addr16 __u6_addr.__u6_addr16
00168 #define MSG_NOSIGNAL 0 // oops - thanks Derek
00169 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
00170 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
00171 
00172 #elif defined _WIN32 
00173 // ----------------------------------------
00174 // Win32
00175 #pragma comment(lib, "wsock32.lib")
00176 #define strcasecmp _stricmp
00177 
00178 typedef unsigned long ipaddr_t;
00179 typedef unsigned short port_t;
00180 typedef int socklen_t;
00181 #ifdef SOCKETS_NAMESPACE
00182 namespace SOCKETS_NAMESPACE {
00183 #endif
00184 // no defs
00185 
00186 #ifdef SOCKETS_NAMESPACE
00187 }
00188 #endif
00189 
00190 // 1.8.6: define FD_SETSIZE to something bigger than 64 if there are a lot of
00191 // simultaneous connections (must be done before including winsock.h)
00192 //#define FD_SETSIZE 1024
00193 
00194 // windows 2000 with ipv6 preview installed:
00195 //    http://msdn.microsoft.com/downloads/sdks/platform/tpipv6.asp
00196 // see the FAQ on how to install
00197 #define WIN32_LEAN_AND_MEAN
00198 #include <winsock2.h>
00199 #include <ws2tcpip.h>
00200 #if MSC_VER < 1200
00201 #ifndef __CYGWIN__
00202 #ifdef ENABLE_IPV6
00203 #include <tpipv6.h>  // For IPv6 Tech Preview.
00204 #endif
00205 #endif
00206 #endif // MSC_VER < 1200
00207 
00208 
00209 #define MSG_NOSIGNAL 0
00210 //#define SHUT_RDWR 2
00211 #define SHUT_WR 1
00212 
00213 #define Errno WSAGetLastError()
00214 const char *StrError(int x);
00215 
00216 #ifdef SOCKETS_NAMESPACE
00217 namespace SOCKETS_NAMESPACE {
00218 #endif
00219 
00220 
00221 // class WSAInitializer is a part of the Socket class (on win32)
00222 // as a static instance - so whenever an application uses a Socket,
00223 // winsock is initialized
00224 class WSAInitializer // Winsock Initializer
00225 {
00226 public:
00227         WSAInitializer() {
00228                 if (WSAStartup(0x101,&m_wsadata)) 
00229                 {
00230                         exit(-1);
00231                 }
00232         }
00233         ~WSAInitializer() {
00234                 WSACleanup();
00235         }
00236 private:
00237         WSADATA m_wsadata;
00238 };
00239 
00240 #ifdef SOCKETS_NAMESPACE
00241 }
00242 #endif
00243 
00244 #else 
00245 // ----------------------------------------
00246 // LINUX 
00247 typedef unsigned long ipaddr_t;
00248 typedef unsigned short port_t;
00249 #ifdef SOCKETS_NAMESPACE
00250 namespace SOCKETS_NAMESPACE {
00251 #endif
00252 // no defs
00253 
00254 #ifdef SOCKETS_NAMESPACE
00255 }
00256 #endif
00257 
00258 
00259 #endif
00260 
00261 #ifdef SOCKETS_NAMESPACE
00262 namespace SOCKETS_NAMESPACE {
00263 #endif
00264 
00265         typedef std::list<SOCKET> socket_v;
00266 
00267 
00268 #ifdef SOCKETS_NAMESPACE
00269 }
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