-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddressesIterator.cpp
More file actions
61 lines (52 loc) · 1.57 KB
/
AddressesIterator.cpp
File metadata and controls
61 lines (52 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright 2015, The maxSocket Contributors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <maxSocket/IP/AddressesIterator.hpp>
#include <maxSocket/IP/Address.hpp>
#include <maxSocket/IP/AddressVersion4.hpp>
#include <maxSocket/IP/AddressVersion6.hpp>
namespace maxSocket
{
namespace v0
{
namespace IP
{
AddressesIterator & AddressesIterator::operator ++()
{
CurrentEndPoint = CurrentEndPoint->ai_next;
return *this;
}
AddressesIterator AddressesIterator::operator ++( int )
{
AddressesIterator Temp( *this );
operator++();
return Temp;
}
bool AddressesIterator::operator ==( const AddressesIterator & rhs ) const
{
return CurrentEndPoint == rhs.CurrentEndPoint;
}
bool AddressesIterator::operator !=( const AddressesIterator & rhs ) const
{
return CurrentEndPoint != rhs.CurrentEndPoint;
}
maxSocket::v0::IP::Address AddressesIterator::operator *() const
{
switch( CurrentEndPoint->ai_family )
{
case AF_INET:
return maxSocket::v0::IP::Address( maxSocket::v0::IP::AddressVersion4( * reinterpret_cast< sockaddr_in * >( CurrentEndPoint->ai_addr ) ) );
case AF_INET6:
return maxSocket::v0::IP::Address( maxSocket::v0::IP::AddressVersion6( * reinterpret_cast< sockaddr_in6 * >( CurrentEndPoint->ai_addr ) ) );
default:
// We encountered an unknown address family.
throw;
}
}
AddressesIterator::AddressesIterator( addrinfo * const CurrentEndPoint )
: CurrentEndPoint( CurrentEndPoint )
{
}
} // namespace IP
} // namespace v0
} // namespace maxSocket