1 /** \file socket_include.h
3 ** \author grymse@alhem.net
6 Copyright (C) 2004-2007 Anders Hedstrom
8 This library is made available under the terms of the GNU GPL.
10 If you would like to use this library in a closed-source application,
11 a separate license agreement is available. For information about
12 the closed-source license agreement for the C++ sockets library,
13 please visit http://www.alhem.net/Sockets/license.html and/or
14 email license@alhem.net.
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License
18 as published by the Free Software Foundation; either version 2
19 of the License, or (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifndef _SOCKETS_socket_include_H
31 #define _SOCKETS_socket_include_H
32 #include "sockets-config.h"
35 #pragma warning(disable:4514)
38 // common defines affecting library and applications using library
40 /* Define SOCKETS_DYNAMIC_TEMP to use dynamically allocated buffers
41 in read operations - helps on ECOS */
42 #define SOCKETS_DYNAMIC_TEMP
45 // platform specific stuff
46 #if (defined(__unix__) || defined(unix)) && !defined(USG)
47 #include <sys/param.h>
53 typedef unsigned __int64
uint64_t;
57 # include <sys/types.h>
64 // ----------------------------------------
65 // common unix includes / defines
68 #include <sys/types.h>
69 #include <sys/socket.h>
70 #include <netinet/in.h>
71 #include <arpa/inet.h>
74 // all typedefs in this file will be declared outside the sockets namespace,
75 // because some os's will already have one or more of the type defined.
78 #define StrError strerror
80 #ifdef SOCKETS_NAMESPACE
81 namespace SOCKETS_NAMESPACE
{
86 #define closesocket close
87 #define INVALID_SOCKET -1
88 #define SOCKET_ERROR -1
91 #define INADDR_NONE ((unsigned long) -1)
94 #ifdef SOCKETS_NAMESPACE
101 // ----------------------------------------
104 #define SOL_IP IPPROTO_IP
108 // ----------------------------------------
109 // OS specific adaptions
112 // ----------------------------------------
114 typedef unsigned short port_t
;
115 #ifdef SOCKETS_NAMESPACE
116 namespace SOCKETS_NAMESPACE
{
120 #ifdef SOCKETS_NAMESPACE
124 #define s6_addr16 _S6_un._S6_u8
125 #define MSG_NOSIGNAL 0
127 #elif defined __FreeBSD__
128 // ----------------------------------------
130 # if __FreeBSD_version >= 400014
131 # define s6_addr16 __u6_addr.__u6_addr16
132 # if !defined(MSG_NOSIGNAL)
133 # define MSG_NOSIGNAL 0
135 # include <netinet/in.h>
136 typedef in_addr_t ipaddr_t
;
137 typedef in_port_t port_t
;
138 #ifdef SOCKETS_NAMESPACE
139 namespace SOCKETS_NAMESPACE
{
143 #ifdef SOCKETS_NAMESPACE
147 # define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
148 # define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
150 # error FreeBSD versions prior to 400014 does not support ipv6
154 // ----------------------------------------
157 #include <mach/port.h>
158 typedef unsigned long ipaddr_t
;
159 #ifdef SOCKETS_NAMESPACE
160 namespace SOCKETS_NAMESPACE
{
164 #ifdef SOCKETS_NAMESPACE
168 #define s6_addr16 __u6_addr.__u6_addr16
169 #define MSG_NOSIGNAL 0 // oops - thanks Derek
170 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
171 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
174 // ----------------------------------------
177 #pragma comment(lib, "wsock32.lib")
179 #define strcasecmp _stricmp
181 typedef unsigned long ipaddr_t
;
182 typedef unsigned short port_t
;
183 typedef int socklen_t
;
184 #ifdef SOCKETS_NAMESPACE
185 namespace SOCKETS_NAMESPACE
{
189 #ifdef SOCKETS_NAMESPACE
193 // 1.8.6: define FD_SETSIZE to something bigger than 64 if there are a lot of
194 // simultaneous connections (must be done before including winsock.h)
195 //#define FD_SETSIZE 1024
197 // windows 2000 with ipv6 preview installed:
198 // http://msdn.microsoft.com/downloads/sdks/platform/tpipv6.asp
199 // see the FAQ on how to install
200 #define WIN32_LEAN_AND_MEAN
201 #include <winsock2.h>
202 #include <ws2tcpip.h>
206 #include <tpipv6.h> // For IPv6 Tech Preview.
209 #endif // _MSC_VER < 1200
212 #define MSG_NOSIGNAL 0
213 //#define SHUT_RDWR 2
216 #define Errno WSAGetLastError()
217 const char *StrError(int x
);
219 #ifdef SOCKETS_NAMESPACE
220 namespace SOCKETS_NAMESPACE
{
224 // class WSAInitializer is a part of the Socket class (on win32)
225 // as a static instance - so whenever an application uses a Socket,
226 // winsock is initialized
227 class WSAInitializer
// Winsock Initializer
231 if (WSAStartup(0x101,&m_wsadata
))
243 #ifdef SOCKETS_NAMESPACE
248 // ----------------------------------------
250 typedef unsigned long ipaddr_t
;
251 typedef unsigned short port_t
;
252 #ifdef SOCKETS_NAMESPACE
253 namespace SOCKETS_NAMESPACE
{
257 #ifdef SOCKETS_NAMESPACE
264 #ifdef SOCKETS_NAMESPACE
265 namespace SOCKETS_NAMESPACE
{
267 /** List type containing file descriptors. */
268 typedef std::list
<SOCKET
> socket_v
;
271 #ifdef SOCKETS_NAMESPACE
276 // getaddrinfo / getnameinfo replacements
277 #ifdef NO_GETADDRINFO
278 #ifndef AI_NUMERICHOST
279 #define AI_NUMERICHOST 1
281 #ifndef NI_NUMERICHOST
282 #define NI_NUMERICHOST 1
287 #endif // _SOCKETS_socket_include_H