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"
36 #pragma warning(disable:4514)
40 // common defines affecting library and applications using library
42 /* Define SOCKETS_DYNAMIC_TEMP to use dynamically allocated buffers
43 in read operations - helps on ECOS */
44 #define SOCKETS_DYNAMIC_TEMP
47 // platform specific stuff
48 #if (defined(__unix__) || defined(unix)) && !defined(USG)
49 #include <sys/param.h>
54 // ----------------------------------------
55 // common unix includes / defines
58 #include <sys/types.h>
59 #include <sys/socket.h>
60 #include <netinet/in.h>
61 #include <arpa/inet.h>
64 // all typedefs in this file will be declared outside the sockets namespace,
65 // because some os's will already have one or more of the type defined.
68 #define StrError strerror
70 #ifdef SOCKETS_NAMESPACE
71 namespace SOCKETS_NAMESPACE
{
76 #define closesocket close
77 #define INVALID_SOCKET -1
78 #define SOCKET_ERROR -1
81 #define INADDR_NONE ((unsigned long) -1)
84 #ifdef SOCKETS_NAMESPACE
91 // ----------------------------------------
94 #define SOL_IP IPPROTO_IP
98 // ----------------------------------------
99 // OS specific adaptions
102 // ----------------------------------------
104 typedef unsigned short port_t
;
105 #ifdef SOCKETS_NAMESPACE
106 namespace SOCKETS_NAMESPACE
{
110 #ifdef SOCKETS_NAMESPACE
114 #define s6_addr16 _S6_un._S6_u8
115 #define MSG_NOSIGNAL 0
117 #elif defined __FreeBSD__
118 // ----------------------------------------
120 # if __FreeBSD_version >= 400014
121 # define s6_addr16 __u6_addr.__u6_addr16
122 # if !defined(MSG_NOSIGNAL)
123 # define MSG_NOSIGNAL 0
125 # include <netinet/in.h>
126 typedef in_addr_t ipaddr_t
;
127 typedef in_port_t port_t
;
128 #ifdef SOCKETS_NAMESPACE
129 namespace SOCKETS_NAMESPACE
{
133 #ifdef SOCKETS_NAMESPACE
137 # define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
138 # define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
140 # error FreeBSD versions prior to 400014 does not support ipv6
144 // ----------------------------------------
147 #include <mach/port.h>
148 typedef unsigned long ipaddr_t
;
149 #ifdef SOCKETS_NAMESPACE
150 namespace SOCKETS_NAMESPACE
{
154 #ifdef SOCKETS_NAMESPACE
158 #define s6_addr16 __u6_addr.__u6_addr16
159 #define MSG_NOSIGNAL 0 // oops - thanks Derek
160 #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP
161 #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP
165 // ----------------------------------------
167 #pragma comment(lib, "wsock32.lib")
169 #define strcasecmp _stricmp
171 typedef unsigned long ipaddr_t
;
172 typedef unsigned short port_t
;
173 typedef int socklen_t
;
174 #ifdef SOCKETS_NAMESPACE
175 namespace SOCKETS_NAMESPACE
{
179 #ifdef SOCKETS_NAMESPACE
183 // 1.8.6: define FD_SETSIZE to something bigger than 64 if there are a lot of
184 // simultaneous connections (must be done before including winsock.h)
185 //#define FD_SETSIZE 1024
187 // windows 2000 with ipv6 preview installed:
188 // http://msdn.microsoft.com/downloads/sdks/platform/tpipv6.asp
189 // see the FAQ on how to install
190 #define WIN32_LEAN_AND_MEAN
191 #include <winsock2.h>
192 #include <ws2tcpip.h>
196 #include <tpipv6.h> // For IPv6 Tech Preview.
199 #endif // MSC_VER < 1200
202 #define MSG_NOSIGNAL 0
203 //#define SHUT_RDWR 2
206 #define Errno WSAGetLastError()
207 const char *StrError(int x
);
209 #ifdef SOCKETS_NAMESPACE
210 namespace SOCKETS_NAMESPACE
{
214 // class WSAInitializer is a part of the Socket class (on win32)
215 // as a static instance - so whenever an application uses a Socket,
216 // winsock is initialized
217 class WSAInitializer
// Winsock Initializer
221 if (WSAStartup(0x101,&m_wsadata
))
233 #ifdef SOCKETS_NAMESPACE
238 // ----------------------------------------
240 typedef unsigned long ipaddr_t
;
241 typedef unsigned short port_t
;
242 #ifdef SOCKETS_NAMESPACE
243 namespace SOCKETS_NAMESPACE
{
247 #ifdef SOCKETS_NAMESPACE
254 #ifdef SOCKETS_NAMESPACE
255 namespace SOCKETS_NAMESPACE
{
257 /** List type containing file descriptors. */
258 typedef std::list
<SOCKET
> socket_v
;
261 #ifdef SOCKETS_NAMESPACE
266 // getaddrinfo / getnameinfo replacements
267 #ifdef NO_GETADDRINFO
268 #ifndef AI_NUMERICHOST
269 #define AI_NUMERICHOST 1
271 #ifndef NI_NUMERICHOST
272 #define NI_NUMERICHOST 1
277 #endif // _SOCKETS_socket_include_H