~ubuntu-branches/ubuntu/oneiric/libtorrent/oneiric

« back to all changes in this revision

Viewing changes to rak/socket_address.h

  • Committer: Bazaar Package Importer
  • Author(s): Rogério Brito
  • Date: 2011-03-20 01:06:18 UTC
  • mfrom: (1.1.13 upstream) (4.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110320010618-g3wyylccqzqko73c
Tags: 0.12.7-5
* Use Steinar's "real" patch for IPv6. Addresses #490277, #618275,
  and Closes: #617791.
* Adapt libtorrent-0.12.6-ipv6-07.patch. It FTBFS otherwise.
* Add proper attibution to the IPv6 patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// rak - Rakshasa's toolbox
 
2
// Copyright (C) 2005-2007, Jari Sundell
 
3
//
 
4
// This program is free software; you can redistribute it and/or modify
 
5
// it under the terms of the GNU General Public License as published by
 
6
// the Free Software Foundation; either version 2 of the License, or
 
7
// (at your option) any later version.
 
8
// 
 
9
// This program is distributed in the hope that it will be useful,
 
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
// GNU General Public License for more details.
 
13
// 
 
14
// You should have received a copy of the GNU General Public License
 
15
// along with this program; if not, write to the Free Software
 
16
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
//
 
18
// In addition, as a special exception, the copyright holders give
 
19
// permission to link the code of portions of this program with the
 
20
// OpenSSL library under certain conditions as described in each
 
21
// individual source file, and distribute linked combinations
 
22
// including the two.
 
23
//
 
24
// You must obey the GNU General Public License in all respects for
 
25
// all of the code used other than OpenSSL.  If you modify file(s)
 
26
// with this exception, you may extend this exception to your version
 
27
// of the file(s), but you are not obligated to do so.  If you do not
 
28
// wish to do so, delete this exception statement from your version.
 
29
// If you delete this exception statement from all source files in the
 
30
// program, then also delete it here.
 
31
//
 
32
// Contact:  Jari Sundell <jaris@ifi.uio.no>
 
33
//
 
34
//           Skomakerveien 33
 
35
//           3185 Skoppum, NORWAY
 
36
 
 
37
// Wrappers for the various sockaddr types with focus on zero-copy
 
38
// casting between the original type and the wrapper class.
 
39
//
 
40
// The default ctor does not initialize any data.
 
41
//
 
42
// _n suffixes indicate that the argument or return value is in
 
43
// network byte order, _h that they are in hardware byte order.
 
44
 
 
45
// Add define for inet6 scope id?
 
46
 
 
47
#ifndef RAK_SOCKET_ADDRESS_H
 
48
#define RAK_SOCKET_ADDRESS_H
 
49
 
 
50
#include <cstring>
 
51
#include <string>
 
52
#include <stdexcept>
 
53
#include <arpa/inet.h>
 
54
#include <netinet/in.h>
 
55
#include <sys/types.h>
 
56
#include <sys/socket.h>
 
57
 
 
58
namespace rak {
 
59
 
 
60
class socket_address_inet;
 
61
class socket_address_inet6;
 
62
 
 
63
class socket_address {
 
64
public:
 
65
  static const sa_family_t af_inet   = AF_INET;
 
66
  static const int         pf_inet   = PF_INET;
 
67
  static const sa_family_t af_inet6  = AF_INET6;
 
68
  static const int         pf_inet6  = PF_INET6;
 
69
  static const sa_family_t af_unspec = AF_UNSPEC;
 
70
  static const int         pf_unspec = PF_UNSPEC;
 
71
 
 
72
#ifdef AF_LOCAL
 
73
  static const sa_family_t af_local  = AF_LOCAL;
 
74
  static const int         pf_local  = PF_LOCAL;
 
75
#else
 
76
  static const sa_family_t af_local  = AF_UNIX;
 
77
  static const int         pf_local  = PF_UNIX;
 
78
#endif
 
79
 
 
80
  bool                is_valid() const;
 
81
  bool                is_bindable() const;
 
82
  bool                is_address_any() const;
 
83
 
 
84
  // Should we need to set AF_UNSPEC?
 
85
  void                clear()                                 { std::memset(this, 0, sizeof(socket_address)); set_family(); }
 
86
 
 
87
  sa_family_t         family() const                          { return m_sockaddr.sa_family; }
 
88
  void                set_family()                            { m_sockaddr.sa_family = af_unspec; }
 
89
 
 
90
  uint16_t            port() const;
 
91
  void                set_port(uint16_t p);
 
92
 
 
93
  std::string         address_str() const;
 
94
  bool                address_c_str(char* buf, socklen_t size) const;
 
95
 
 
96
  // Attemts to set it as an inet, then an inet6 address. It will
 
97
  // never set anything but net addresses, no local/unix.
 
98
  bool                set_address_str(const std::string& a)   { return set_address_c_str(a.c_str()); }
 
99
  bool                set_address_c_str(const char* a);
 
100
 
 
101
  uint32_t            length() const;
 
102
 
 
103
  socket_address_inet*        sa_inet()                       { return reinterpret_cast<socket_address_inet*>(this); }
 
104
  const socket_address_inet*  sa_inet() const                 { return reinterpret_cast<const socket_address_inet*>(this); }
 
105
 
 
106
  sockaddr*           c_sockaddr()                            { return &m_sockaddr; }
 
107
  sockaddr_in*        c_sockaddr_inet()                       { return &m_sockaddrInet; }
 
108
 
 
109
  const sockaddr*     c_sockaddr() const                      { return &m_sockaddr; }
 
110
  const sockaddr_in*  c_sockaddr_inet() const                 { return &m_sockaddrInet; }
 
111
 
 
112
#ifdef RAK_USE_INET6
 
113
  socket_address_inet6*       sa_inet6()                      { return reinterpret_cast<socket_address_inet6*>(this); }
 
114
  const socket_address_inet6* sa_inet6() const                { return reinterpret_cast<const socket_address_inet6*>(this); }
 
115
 
 
116
  sockaddr_in6*       c_sockaddr_inet6()                      { return &m_sockaddrInet6; }
 
117
  const sockaddr_in6* c_sockaddr_inet6() const                { return &m_sockaddrInet6; }
 
118
#endif
 
119
 
 
120
  // Copy a socket address which has the length 'length. Zero out any
 
121
  // extranous bytes and ensure it does not go beyond the size of this
 
122
  // struct.
 
123
  void                copy(const socket_address& src, size_t length);
 
124
 
 
125
  static socket_address*       cast_from(sockaddr* sa)        { return reinterpret_cast<socket_address*>(sa); }
 
126
  static const socket_address* cast_from(const sockaddr* sa)  { return reinterpret_cast<const socket_address*>(sa); }
 
127
 
 
128
  // The different families will be sorted according to the
 
129
  // sa_family_t's numeric value.
 
130
  bool                operator == (const socket_address& rhs) const;
 
131
  bool                operator  < (const socket_address& rhs) const;
 
132
 
 
133
  bool                operator == (const sockaddr& rhs) const { return *this == *cast_from(&rhs); }
 
134
  bool                operator == (const sockaddr* rhs) const { return *this == *cast_from(rhs); }
 
135
  bool                operator  < (const sockaddr& rhs) const { return *this == *cast_from(&rhs); }
 
136
  bool                operator  < (const sockaddr* rhs) const { return *this == *cast_from(rhs); }
 
137
 
 
138
private:
 
139
  union {
 
140
    sockaddr            m_sockaddr;
 
141
    sockaddr_in         m_sockaddrInet;
 
142
#ifdef RAK_USE_INET6
 
143
    sockaddr_in6        m_sockaddrInet6;
 
144
#endif
 
145
  };
 
146
};
 
147
 
 
148
// Remember to set the AF_INET.
 
149
 
 
150
class socket_address_inet {
 
151
public:
 
152
  bool                is_any() const                          { return is_port_any() && is_address_any(); }
 
153
  bool                is_valid() const                        { return !is_port_any() && !is_address_any(); }
 
154
  bool                is_port_any() const                     { return port() == 0; }
 
155
  bool                is_address_any() const                  { return m_sockaddr.sin_addr.s_addr == htonl(INADDR_ANY); }
 
156
 
 
157
  void                clear()                                 { std::memset(this, 0, sizeof(socket_address_inet)); set_family(); }
 
158
 
 
159
  uint16_t            port() const                            { return ntohs(m_sockaddr.sin_port); }
 
160
  uint16_t            port_n() const                          { return m_sockaddr.sin_port; }
 
161
  void                set_port(uint16_t p)                    { m_sockaddr.sin_port = htons(p); }
 
162
  void                set_port_n(uint16_t p)                  { m_sockaddr.sin_port = p; }
 
163
 
 
164
  // Should address() return the uint32_t?
 
165
  in_addr             address() const                         { return m_sockaddr.sin_addr; }
 
166
  uint32_t            address_h() const                       { return ntohl(m_sockaddr.sin_addr.s_addr); }
 
167
  uint32_t            address_n() const                       { return m_sockaddr.sin_addr.s_addr; }
 
168
  std::string         address_str() const;
 
169
  bool                address_c_str(char* buf, socklen_t size) const;
 
170
 
 
171
  void                set_address(in_addr a)                  { m_sockaddr.sin_addr = a; }
 
172
  void                set_address_h(uint32_t a)               { m_sockaddr.sin_addr.s_addr = htonl(a); }
 
173
  void                set_address_n(uint32_t a)               { m_sockaddr.sin_addr.s_addr = a; }
 
174
  bool                set_address_str(const std::string& a)   { return set_address_c_str(a.c_str()); }
 
175
  bool                set_address_c_str(const char* a);
 
176
 
 
177
  void                set_address_any()                       { set_port(0); set_address_h(INADDR_ANY); }
 
178
 
 
179
  sa_family_t         family() const                          { return m_sockaddr.sin_family; }
 
180
  void                set_family()                            { m_sockaddr.sin_family = AF_INET; }
 
181
 
 
182
  sockaddr*           c_sockaddr()                            { return reinterpret_cast<sockaddr*>(&m_sockaddr); }
 
183
  sockaddr_in*        c_sockaddr_inet()                       { return &m_sockaddr; }
 
184
 
 
185
  const sockaddr*     c_sockaddr() const                      { return reinterpret_cast<const sockaddr*>(&m_sockaddr); }
 
186
  const sockaddr_in*  c_sockaddr_inet() const                 { return &m_sockaddr; }
 
187
  
 
188
#ifdef RAK_USE_INET6
 
189
  socket_address_inet6 to_mapped_address() const;
 
190
#endif
 
191
 
 
192
  bool                operator == (const socket_address_inet& rhs) const;
 
193
  bool                operator < (const socket_address_inet& rhs) const;
 
194
 
 
195
private:
 
196
  struct sockaddr_in  m_sockaddr;
 
197
};
 
198
 
 
199
#ifdef RAK_USE_INET6
 
200
// Remember to set the AF_INET6.
 
201
 
 
202
class socket_address_inet6 {
 
203
public:
 
204
  bool                is_any() const                          { return is_port_any() && is_address_any(); }
 
205
  bool                is_valid() const                        { return !is_port_any() && !is_address_any(); }
 
206
  bool                is_port_any() const                     { return port() == 0; }
 
207
  bool                is_address_any() const                  { return std::memcmp(&m_sockaddr.sin6_addr, &in6addr_any, sizeof(in6_addr)) == 0; }
 
208
 
 
209
  void                clear()                                 { std::memset(this, 0, sizeof(socket_address_inet6)); set_family(); }
 
210
 
 
211
  uint16_t            port() const                            { return ntohs(m_sockaddr.sin6_port); }
 
212
  uint16_t            port_n() const                          { return m_sockaddr.sin6_port; }
 
213
  void                set_port(uint16_t p)                    { m_sockaddr.sin6_port = htons(p); }
 
214
  void                set_port_n(uint16_t p)                  { m_sockaddr.sin6_port = p; }
 
215
 
 
216
  in6_addr            address() const                         { return m_sockaddr.sin6_addr; }
 
217
  std::string         address_str() const;
 
218
  bool                address_c_str(char* buf, socklen_t size) const;
 
219
 
 
220
  void                set_address(in6_addr a)                 { m_sockaddr.sin6_addr = a; }
 
221
  bool                set_address_str(const std::string& a)   { return set_address_c_str(a.c_str()); }
 
222
  bool                set_address_c_str(const char* a);
 
223
 
 
224
  void                set_address_any()                       { set_port(0); set_address(in6addr_any); }
 
225
 
 
226
  sa_family_t         family() const                          { return m_sockaddr.sin6_family; }
 
227
  void                set_family()                            { m_sockaddr.sin6_family = AF_INET6; }
 
228
 
 
229
  sockaddr*           c_sockaddr()                            { return reinterpret_cast<sockaddr*>(&m_sockaddr); }
 
230
  sockaddr_in6*       c_sockaddr_inet6()                      { return &m_sockaddr; }
 
231
 
 
232
  const sockaddr*     c_sockaddr() const                      { return reinterpret_cast<const sockaddr*>(&m_sockaddr); }
 
233
  const sockaddr_in6* c_sockaddr_inet6() const                { return &m_sockaddr; }
 
234
 
 
235
  socket_address      normalize_address() const;
 
236
 
 
237
  bool                operator == (const socket_address_inet6& rhs) const;
 
238
  bool                operator < (const socket_address_inet6& rhs) const;
 
239
 
 
240
private:
 
241
  struct sockaddr_in6 m_sockaddr;
 
242
};
 
243
#endif
 
244
 
 
245
// Unique key for the address, excluding port numbers etc.
 
246
class socket_address_key {
 
247
public:
 
248
//   socket_address_host_key() {}
 
249
 
 
250
  socket_address_key(const socket_address& sa) {
 
251
    *this = sa;
 
252
  }
 
253
 
 
254
  socket_address_key& operator = (const socket_address& sa) {
 
255
    if (sa.family() == 0) {
 
256
      std::memset(this, 0, sizeof(socket_address_key));
 
257
 
 
258
    } else if (sa.family() == socket_address::af_inet) {
 
259
      // Using hardware order as we use operator < to compare when
 
260
      // using inet only.
 
261
      m_addr.s_addr = sa.sa_inet()->address_h();
 
262
 
 
263
    } else {
 
264
      // When we implement INET6 handling, embed the ipv4 address in
 
265
      // the ipv6 address.
 
266
      throw std::logic_error("socket_address_key(...) received an unsupported protocol family.");
 
267
    }
 
268
 
 
269
    return *this;
 
270
  }
 
271
 
 
272
//   socket_address_key& operator = (const socket_address_key& sa) {
 
273
//   }
 
274
 
 
275
  bool operator < (const socket_address_key& sa) const {
 
276
    // Compare the memory area instead.
 
277
    return m_addr.s_addr < sa.m_addr.s_addr;
 
278
  }    
 
279
 
 
280
private:
 
281
  union {
 
282
    in_addr m_addr;
 
283
// #ifdef RAK_USE_INET6
 
284
//     in_addr6 m_addr6;
 
285
// #endif
 
286
  };
 
287
};
 
288
 
 
289
inline bool
 
290
socket_address::is_valid() const {
 
291
  switch (family()) {
 
292
  case af_inet:
 
293
    return sa_inet()->is_valid();
 
294
#ifdef RAK_USE_INET6
 
295
  case af_inet6:
 
296
    return sa_inet6()->is_valid();
 
297
#endif
 
298
  default:
 
299
    return false;
 
300
  }
 
301
}
 
302
 
 
303
inline bool
 
304
socket_address::is_bindable() const {
 
305
  switch (family()) {
 
306
  case af_inet:
 
307
    return !sa_inet()->is_address_any();
 
308
#ifdef RAK_USE_INET6
 
309
  case af_inet6:
 
310
    return !sa_inet6()->is_address_any();
 
311
#endif
 
312
  default:
 
313
    return false;
 
314
  }
 
315
}
 
316
 
 
317
inline bool
 
318
socket_address::is_address_any() const {
 
319
  switch (family()) {
 
320
  case af_inet:
 
321
    return sa_inet()->is_address_any();
 
322
#ifdef RAK_USE_INET6
 
323
  case af_inet6:
 
324
    return sa_inet6()->is_address_any();
 
325
#endif
 
326
  default:
 
327
    return true;
 
328
  }
 
329
}
 
330
 
 
331
inline uint16_t
 
332
socket_address::port() const {
 
333
  switch (family()) {
 
334
  case af_inet:
 
335
    return sa_inet()->port();
 
336
#ifdef RAK_USE_INET6
 
337
  case af_inet6:
 
338
    return sa_inet6()->port();
 
339
#endif
 
340
  default:
 
341
    return 0;
 
342
  }
 
343
}
 
344
 
 
345
inline void
 
346
socket_address::set_port(uint16_t p) {
 
347
  switch (family()) {
 
348
  case af_inet:
 
349
    return sa_inet()->set_port(p);
 
350
#ifdef RAK_USE_INET6
 
351
  case af_inet6:
 
352
    return sa_inet6()->set_port(p);
 
353
#endif
 
354
  default:
 
355
    break;
 
356
  }
 
357
}
 
358
 
 
359
inline std::string
 
360
socket_address::address_str() const {
 
361
  switch (family()) {
 
362
  case af_inet:
 
363
    return sa_inet()->address_str();
 
364
#ifdef RAK_USE_INET6
 
365
  case af_inet6:
 
366
    return sa_inet6()->address_str();
 
367
#endif
 
368
  default:
 
369
    return std::string();
 
370
  }
 
371
}
 
372
 
 
373
inline bool
 
374
socket_address::address_c_str(char* buf, socklen_t size) const {
 
375
  switch (family()) {
 
376
  case af_inet:
 
377
    return sa_inet()->address_c_str(buf, size);
 
378
#ifdef RAK_USE_INET6
 
379
  case af_inet6:
 
380
    return sa_inet6()->address_c_str(buf, size);
 
381
#endif
 
382
  default:
 
383
    return false;
 
384
  }
 
385
}
 
386
 
 
387
inline bool
 
388
socket_address::set_address_c_str(const char* a) {
 
389
  if (sa_inet()->set_address_c_str(a)) {
 
390
    sa_inet()->set_family();
 
391
    return true;
 
392
 
 
393
#ifdef RAK_USE_INET6
 
394
  } else if (sa_inet6()->set_address_c_str(a)) {
 
395
    sa_inet6()->set_family();
 
396
    return true;
 
397
#endif
 
398
 
 
399
  } else {
 
400
    return false;
 
401
  }
 
402
}
 
403
 
 
404
// Is the zero length really needed, should we require some length?
 
405
inline uint32_t
 
406
socket_address::length() const {
 
407
  switch(family()) {
 
408
  case af_inet:
 
409
    return sizeof(sockaddr_in);
 
410
#ifdef RAK_USE_INET6
 
411
  case af_inet6:
 
412
    return sizeof(sockaddr_in6);
 
413
#endif
 
414
  default:
 
415
    return 0;
 
416
  }      
 
417
}
 
418
 
 
419
inline void
 
420
socket_address::copy(const socket_address& src, size_t length) {
 
421
  length = std::min(length, sizeof(socket_address));
 
422
  
 
423
  // Does this get properly optimized?
 
424
  std::memset(this, 0, sizeof(socket_address));
 
425
  std::memcpy(this, &src, length);
 
426
}
 
427
 
 
428
// Should we be able to compare af_unspec?
 
429
 
 
430
inline bool
 
431
socket_address::operator == (const socket_address& rhs) const {
 
432
  if (family() != rhs.family())
 
433
    return false;
 
434
 
 
435
  switch (family()) {
 
436
  case af_inet:
 
437
    return *sa_inet() == *rhs.sa_inet();
 
438
#ifdef RAK_USE_INET6
 
439
  case af_inet6:
 
440
    return *sa_inet6() == *rhs.sa_inet6();
 
441
#endif
 
442
  default:
 
443
    throw std::logic_error("socket_address::operator == (rhs) invalid type comparison.");
 
444
  }
 
445
}
 
446
 
 
447
inline bool
 
448
socket_address::operator < (const socket_address& rhs) const {
 
449
  if (family() != rhs.family())
 
450
    return family() < rhs.family();
 
451
 
 
452
  switch (family()) {
 
453
  case af_inet:
 
454
    return *sa_inet() < *rhs.sa_inet();
 
455
#ifdef RAK_USE_INET6
 
456
  case af_inet6:
 
457
    return *sa_inet6() < *rhs.sa_inet6();
 
458
#endif
 
459
  default:
 
460
    throw std::logic_error("socket_address::operator < (rhs) invalid type comparison.");
 
461
  }
 
462
}
 
463
 
 
464
inline std::string
 
465
socket_address_inet::address_str() const {
 
466
  char buf[INET_ADDRSTRLEN];
 
467
 
 
468
  if (!address_c_str(buf, INET_ADDRSTRLEN))
 
469
    return std::string();
 
470
 
 
471
  return std::string(buf);
 
472
}
 
473
 
 
474
inline bool
 
475
socket_address_inet::address_c_str(char* buf, socklen_t size) const {
 
476
  return inet_ntop(family(), &m_sockaddr.sin_addr, buf, size);
 
477
}
 
478
 
 
479
inline bool
 
480
socket_address_inet::set_address_c_str(const char* a) {
 
481
  return inet_pton(AF_INET, a, &m_sockaddr.sin_addr);
 
482
}
 
483
 
 
484
#ifdef RAK_USE_INET6
 
485
inline socket_address_inet6
 
486
socket_address_inet::to_mapped_address() const {
 
487
  uint32_t addr32[4];
 
488
  addr32[0] = 0;
 
489
  addr32[1] = 0;
 
490
  addr32[2] = htonl(0xffff);
 
491
  addr32[3] = m_sockaddr.sin_addr.s_addr;
 
492
  
 
493
  socket_address_inet6 sa;
 
494
  sa.clear();
 
495
  sa.set_address(*reinterpret_cast<in6_addr *>(addr32));
 
496
  sa.set_port_n(m_sockaddr.sin_port);
 
497
  return sa;
 
498
}
 
499
#endif
 
500
 
 
501
inline bool
 
502
socket_address_inet::operator == (const socket_address_inet& rhs) const {
 
503
  return
 
504
    m_sockaddr.sin_addr.s_addr == rhs.m_sockaddr.sin_addr.s_addr &&
 
505
    m_sockaddr.sin_port == rhs.m_sockaddr.sin_port;
 
506
}
 
507
 
 
508
inline bool
 
509
socket_address_inet::operator < (const socket_address_inet& rhs) const {
 
510
  return
 
511
    m_sockaddr.sin_addr.s_addr < rhs.m_sockaddr.sin_addr.s_addr ||
 
512
    (m_sockaddr.sin_addr.s_addr == rhs.m_sockaddr.sin_addr.s_addr &&
 
513
     m_sockaddr.sin_port < rhs.m_sockaddr.sin_port);
 
514
}
 
515
 
 
516
#ifdef RAK_USE_INET6
 
517
 
 
518
inline std::string
 
519
socket_address_inet6::address_str() const {
 
520
  char buf[INET6_ADDRSTRLEN];
 
521
 
 
522
  if (!address_c_str(buf, INET6_ADDRSTRLEN))
 
523
    return std::string();
 
524
 
 
525
  return std::string(buf);
 
526
}
 
527
 
 
528
inline bool
 
529
socket_address_inet6::address_c_str(char* buf, socklen_t size) const {
 
530
  return inet_ntop(family(), &m_sockaddr.sin6_addr, buf, size);
 
531
}
 
532
 
 
533
inline bool
 
534
socket_address_inet6::set_address_c_str(const char* a) {
 
535
  return inet_pton(AF_INET6, a, &m_sockaddr.sin6_addr);
 
536
}
 
537
 
 
538
inline socket_address
 
539
socket_address_inet6::normalize_address() const {
 
540
  const uint32_t *addr32 = reinterpret_cast<const uint32_t *>(m_sockaddr.sin6_addr.s6_addr);
 
541
  if (addr32[0] == 0 && addr32[1] == 0 && addr32[2] == htonl(0xffff)) {
 
542
    socket_address addr4;
 
543
    addr4.sa_inet()->set_family();
 
544
    addr4.sa_inet()->set_address_n(addr32[3]);
 
545
    addr4.sa_inet()->set_port_n(m_sockaddr.sin6_port);
 
546
    return addr4;
 
547
  }
 
548
  return *reinterpret_cast<const socket_address*>(this);
 
549
}
 
550
 
 
551
inline bool
 
552
socket_address_inet6::operator == (const socket_address_inet6& rhs) const {
 
553
  return
 
554
    memcmp(&m_sockaddr.sin6_addr, &rhs.m_sockaddr.sin6_addr, sizeof(in6_addr)) == 0 &&
 
555
    m_sockaddr.sin6_port == rhs.m_sockaddr.sin6_port;
 
556
}
 
557
 
 
558
inline bool
 
559
socket_address_inet6::operator < (const socket_address_inet6& rhs) const {
 
560
  int addr_comp = memcmp(&m_sockaddr.sin6_addr, &rhs.m_sockaddr.sin6_addr, sizeof(in6_addr));
 
561
  return
 
562
    addr_comp < 0 ||
 
563
    (addr_comp == 0 ||
 
564
     m_sockaddr.sin6_port < rhs.m_sockaddr.sin6_port);
 
565
}
 
566
 
 
567
#endif
 
568
 
 
569
}
 
570
 
 
571
#endif