~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to include/libtorrent/asio/detail/old_win_sdk_compat.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// old_win_sdk_compat.hpp
3
 
// ~~~~~~~~~~~~~~~~~~~~~~
4
 
//
5
 
// Copyright (c) 2003-2008 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6
 
//
7
 
// Distributed under the Boost Software License, Version 1.0. (See accompanying
8
 
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9
 
//
10
 
 
11
 
#ifndef ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP
12
 
#define ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP
13
 
 
14
 
#if defined(_MSC_VER) && (_MSC_VER >= 1200)
15
 
# pragma once
16
 
#endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17
 
 
18
 
#include "asio/detail/push_options.hpp"
19
 
 
20
 
#include "asio/detail/push_options.hpp"
21
 
#include <boost/config.hpp>
22
 
#include "asio/detail/pop_options.hpp"
23
 
 
24
 
#if defined(BOOST_WINDOWS) || defined(__CYGWIN__)
25
 
 
26
 
// Guess whether we are building against on old Platform SDK.
27
 
#if !defined(IN6ADDR_ANY_INIT)
28
 
#define ASIO_HAS_OLD_WIN_SDK 1
29
 
#endif // !defined(IN6ADDR_ANY_INIT)
30
 
 
31
 
#if defined(ASIO_HAS_OLD_WIN_SDK)
32
 
 
33
 
// Emulation of types that are missing from old Platform SDKs.
34
 
//
35
 
// N.B. this emulation is also used if building for a Windows 2000 target with
36
 
// a recent (i.e. Vista or later) SDK, as the SDK does not provide IPv6 support
37
 
// in that case.
38
 
 
39
 
namespace asio {
40
 
namespace detail {
41
 
 
42
 
enum
43
 
{
44
 
  sockaddr_storage_maxsize = 128, // Maximum size.
45
 
  sockaddr_storage_alignsize = (sizeof(__int64)), // Desired alignment.
46
 
  sockaddr_storage_pad1size = (sockaddr_storage_alignsize - sizeof(short)),
47
 
  sockaddr_storage_pad2size = (sockaddr_storage_maxsize -
48
 
      (sizeof(short) + sockaddr_storage_pad1size + sockaddr_storage_alignsize))
49
 
};
50
 
 
51
 
struct sockaddr_storage_emulation
52
 
{
53
 
  short ss_family;
54
 
  char __ss_pad1[sockaddr_storage_pad1size];
55
 
  __int64 __ss_align;
56
 
  char __ss_pad2[sockaddr_storage_pad2size];
57
 
};
58
 
 
59
 
struct in6_addr_emulation
60
 
{
61
 
  union
62
 
  {
63
 
    u_char Byte[16];
64
 
    u_short Word[8];
65
 
  } u;
66
 
};
67
 
 
68
 
#if !defined(s6_addr)
69
 
# define _S6_un u
70
 
# define _S6_u8 Byte
71
 
# define s6_addr _S6_un._S6_u8
72
 
#endif // !defined(s6_addr)
73
 
 
74
 
struct sockaddr_in6_emulation
75
 
{
76
 
  short sin6_family;
77
 
  u_short sin6_port;
78
 
  u_long sin6_flowinfo;
79
 
  in6_addr_emulation sin6_addr;
80
 
  u_long sin6_scope_id;
81
 
};
82
 
 
83
 
struct ipv6_mreq_emulation
84
 
{
85
 
  in6_addr_emulation ipv6mr_multiaddr;
86
 
  unsigned int ipv6mr_interface;
87
 
};
88
 
 
89
 
#if !defined(IN6ADDR_ANY_INIT)
90
 
# define IN6ADDR_ANY_INIT { 0 }
91
 
#endif
92
 
 
93
 
#if !defined(IN6ADDR_LOOPBACK_INIT)
94
 
# define IN6ADDR_LOOPBACK_INIT { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 }
95
 
#endif
96
 
 
97
 
struct addrinfo_emulation
98
 
{
99
 
  int ai_flags;
100
 
  int ai_family;
101
 
  int ai_socktype;
102
 
  int ai_protocol;
103
 
  size_t ai_addrlen;
104
 
  char* ai_canonname;
105
 
  sockaddr* ai_addr;
106
 
  addrinfo_emulation* ai_next;
107
 
};
108
 
 
109
 
#if !defined(AI_PASSIVE)
110
 
# define AI_PASSIVE 0x1
111
 
#endif
112
 
 
113
 
#if !defined(AI_CANONNAME)
114
 
# define AI_CANONNAME 0x2
115
 
#endif
116
 
 
117
 
#if !defined(AI_NUMERICHOST)
118
 
# define AI_NUMERICHOST 0x4
119
 
#endif
120
 
 
121
 
#if !defined(EAI_AGAIN)
122
 
# define EAI_AGAIN WSATRY_AGAIN
123
 
#endif
124
 
 
125
 
#if !defined(EAI_BADFLAGS)
126
 
# define EAI_BADFLAGS WSAEINVAL
127
 
#endif
128
 
 
129
 
#if !defined(EAI_FAIL)
130
 
# define EAI_FAIL WSANO_RECOVERY
131
 
#endif
132
 
 
133
 
#if !defined(EAI_FAMILY)
134
 
# define EAI_FAMILY WSAEAFNOSUPPORT
135
 
#endif
136
 
 
137
 
#if !defined(EAI_MEMORY)
138
 
# define EAI_MEMORY WSA_NOT_ENOUGH_MEMORY
139
 
#endif
140
 
 
141
 
#if !defined(EAI_NODATA)
142
 
# define EAI_NODATA WSANO_DATA
143
 
#endif
144
 
 
145
 
#if !defined(EAI_NONAME)
146
 
# define EAI_NONAME WSAHOST_NOT_FOUND
147
 
#endif
148
 
 
149
 
#if !defined(EAI_SERVICE)
150
 
# define EAI_SERVICE WSATYPE_NOT_FOUND
151
 
#endif
152
 
 
153
 
#if !defined(EAI_SOCKTYPE)
154
 
# define EAI_SOCKTYPE WSAESOCKTNOSUPPORT
155
 
#endif
156
 
 
157
 
#if !defined(NI_NOFQDN)
158
 
# define NI_NOFQDN 0x01
159
 
#endif
160
 
 
161
 
#if !defined(NI_NUMERICHOST)
162
 
# define NI_NUMERICHOST 0x02
163
 
#endif
164
 
 
165
 
#if !defined(NI_NAMEREQD)
166
 
# define NI_NAMEREQD 0x04
167
 
#endif
168
 
 
169
 
#if !defined(NI_NUMERICSERV)
170
 
# define NI_NUMERICSERV 0x08
171
 
#endif
172
 
 
173
 
#if !defined(NI_DGRAM)
174
 
# define NI_DGRAM 0x10
175
 
#endif
176
 
 
177
 
#if !defined(IPPROTO_IPV6)
178
 
# define IPPROTO_IPV6 41
179
 
#endif
180
 
 
181
 
#if !defined(IPV6_UNICAST_HOPS)
182
 
# define IPV6_UNICAST_HOPS 4
183
 
#endif
184
 
 
185
 
#if !defined(IPV6_MULTICAST_IF)
186
 
# define IPV6_MULTICAST_IF 9
187
 
#endif
188
 
 
189
 
#if !defined(IPV6_MULTICAST_HOPS)
190
 
# define IPV6_MULTICAST_HOPS 10
191
 
#endif
192
 
 
193
 
#if !defined(IPV6_MULTICAST_LOOP)
194
 
# define IPV6_MULTICAST_LOOP 11
195
 
#endif
196
 
 
197
 
#if !defined(IPV6_JOIN_GROUP)
198
 
# define IPV6_JOIN_GROUP 12
199
 
#endif
200
 
 
201
 
#if !defined(IPV6_LEAVE_GROUP)
202
 
# define IPV6_LEAVE_GROUP 13
203
 
#endif
204
 
 
205
 
inline int IN6_IS_ADDR_UNSPECIFIED(const in6_addr_emulation* a)
206
 
{
207
 
  return ((a->s6_addr[0] == 0)
208
 
      && (a->s6_addr[1] == 0)
209
 
      && (a->s6_addr[2] == 0)
210
 
      && (a->s6_addr[3] == 0)
211
 
      && (a->s6_addr[4] == 0)
212
 
      && (a->s6_addr[5] == 0)
213
 
      && (a->s6_addr[6] == 0)
214
 
      && (a->s6_addr[7] == 0)
215
 
      && (a->s6_addr[8] == 0)
216
 
      && (a->s6_addr[9] == 0)
217
 
      && (a->s6_addr[10] == 0)
218
 
      && (a->s6_addr[11] == 0)
219
 
      && (a->s6_addr[12] == 0)
220
 
      && (a->s6_addr[13] == 0)
221
 
      && (a->s6_addr[14] == 0)
222
 
      && (a->s6_addr[15] == 0));
223
 
}
224
 
 
225
 
inline int IN6_IS_ADDR_LOOPBACK(const in6_addr_emulation* a)
226
 
{
227
 
  return ((a->s6_addr[0] == 0)
228
 
      && (a->s6_addr[1] == 0)
229
 
      && (a->s6_addr[2] == 0)
230
 
      && (a->s6_addr[3] == 0)
231
 
      && (a->s6_addr[4] == 0)
232
 
      && (a->s6_addr[5] == 0)
233
 
      && (a->s6_addr[6] == 0)
234
 
      && (a->s6_addr[7] == 0)
235
 
      && (a->s6_addr[8] == 0)
236
 
      && (a->s6_addr[9] == 0)
237
 
      && (a->s6_addr[10] == 0)
238
 
      && (a->s6_addr[11] == 0)
239
 
      && (a->s6_addr[12] == 0)
240
 
      && (a->s6_addr[13] == 0)
241
 
      && (a->s6_addr[14] == 0)
242
 
      && (a->s6_addr[15] == 1));
243
 
}
244
 
 
245
 
inline int IN6_IS_ADDR_MULTICAST(const in6_addr_emulation* a)
246
 
{
247
 
  return (a->s6_addr[0] == 0xff);
248
 
}
249
 
 
250
 
inline int IN6_IS_ADDR_LINKLOCAL(const in6_addr_emulation* a)
251
 
{
252
 
  return ((a->s6_addr[0] == 0xfe) && ((a->s6_addr[1] & 0xc0) == 0x80));
253
 
}
254
 
 
255
 
inline int IN6_IS_ADDR_SITELOCAL(const in6_addr_emulation* a)
256
 
{
257
 
  return ((a->s6_addr[0] == 0xfe) && ((a->s6_addr[1] & 0xc0) == 0xc0));
258
 
}
259
 
 
260
 
inline int IN6_IS_ADDR_V4MAPPED(const in6_addr_emulation* a)
261
 
{
262
 
  return ((a->s6_addr[0] == 0)
263
 
      && (a->s6_addr[1] == 0)
264
 
      && (a->s6_addr[2] == 0)
265
 
      && (a->s6_addr[3] == 0)
266
 
      && (a->s6_addr[4] == 0)
267
 
      && (a->s6_addr[5] == 0)
268
 
      && (a->s6_addr[6] == 0)
269
 
      && (a->s6_addr[7] == 0)
270
 
      && (a->s6_addr[8] == 0)
271
 
      && (a->s6_addr[9] == 0)
272
 
      && (a->s6_addr[10] == 0xff)
273
 
      && (a->s6_addr[11] == 0xff));
274
 
}
275
 
 
276
 
inline int IN6_IS_ADDR_V4COMPAT(const in6_addr_emulation* a)
277
 
{
278
 
  return ((a->s6_addr[0] == 0)
279
 
      && (a->s6_addr[1] == 0)
280
 
      && (a->s6_addr[2] == 0)
281
 
      && (a->s6_addr[3] == 0)
282
 
      && (a->s6_addr[4] == 0)
283
 
      && (a->s6_addr[5] == 0)
284
 
      && (a->s6_addr[6] == 0)
285
 
      && (a->s6_addr[7] == 0)
286
 
      && (a->s6_addr[8] == 0)
287
 
      && (a->s6_addr[9] == 0)
288
 
      && (a->s6_addr[10] == 0xff)
289
 
      && (a->s6_addr[11] == 0xff)
290
 
      && !((a->s6_addr[12] == 0)
291
 
        && (a->s6_addr[13] == 0)
292
 
        && (a->s6_addr[14] == 0)
293
 
        && ((a->s6_addr[15] == 0) || (a->s6_addr[15] == 1))));
294
 
}
295
 
 
296
 
inline int IN6_IS_ADDR_MC_NODELOCAL(const in6_addr_emulation* a)
297
 
{
298
 
  return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 1);
299
 
}
300
 
 
301
 
inline int IN6_IS_ADDR_MC_LINKLOCAL(const in6_addr_emulation* a)
302
 
{
303
 
  return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 2);
304
 
}
305
 
 
306
 
inline int IN6_IS_ADDR_MC_SITELOCAL(const in6_addr_emulation* a)
307
 
{
308
 
  return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 5);
309
 
}
310
 
 
311
 
inline int IN6_IS_ADDR_MC_ORGLOCAL(const in6_addr_emulation* a)
312
 
{
313
 
  return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 8);
314
 
}
315
 
 
316
 
inline int IN6_IS_ADDR_MC_GLOBAL(const in6_addr_emulation* a)
317
 
{
318
 
  return IN6_IS_ADDR_MULTICAST(a) && ((a->s6_addr[1] & 0xf) == 0xe);
319
 
}
320
 
 
321
 
} // namespace detail
322
 
} // namespace asio
323
 
 
324
 
#endif // defined(ASIO_HAS_OLD_WIN_SDK)
325
 
 
326
 
// Even newer Platform SDKs that support IPv6 may not define IPV6_V6ONLY.
327
 
#if !defined(IPV6_V6ONLY)
328
 
# define IPV6_V6ONLY 27
329
 
#endif
330
 
 
331
 
// Some SDKs (e.g. Windows CE) don't define IPPROTO_ICMPV6.
332
 
#if !defined(IPPROTO_ICMPV6)
333
 
# define IPPROTO_ICMPV6 58
334
 
#endif
335
 
 
336
 
#endif // defined(BOOST_WINDOWS) || defined(__CYGWIN__)
337
 
 
338
 
#include "asio/detail/pop_options.hpp"
339
 
 
340
 
#endif // ASIO_DETAIL_OLD_WIN_SDK_COMPAT_HPP