3 Copyright (c) 2005, Arvid Norberg
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the distribution.
15 * Neither the name of the author nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
33 #include "libtorrent/pch.hpp"
35 #include "libtorrent/ip_filter.hpp"
36 #include <boost/utility.hpp>
42 void ip_filter::add_rule(address first
, address last
, int flags
)
46 TORRENT_ASSERT(last
.is_v4());
47 m_filter4
.add_rule(first
.to_v4().to_bytes(), last
.to_v4().to_bytes(), flags
);
49 else if (first
.is_v6())
51 TORRENT_ASSERT(last
.is_v6());
52 m_filter6
.add_rule(first
.to_v6().to_bytes(), last
.to_v6().to_bytes(), flags
);
55 TORRENT_ASSERT(false);
58 int ip_filter::access(address
const& addr
) const
61 return m_filter4
.access(addr
.to_v4().to_bytes());
62 TORRENT_ASSERT(addr
.is_v6());
63 return m_filter6
.access(addr
.to_v6().to_bytes());
66 ip_filter::filter_tuple_t
ip_filter::export_filter() const
68 return boost::make_tuple(m_filter4
.export_filter
<address_v4
>()
69 , m_filter6
.export_filter
<address_v6
>());
72 void port_filter::add_rule(boost::uint16_t first
, boost::uint16_t last
, int flags
)
74 m_filter
.add_rule(first
, last
, flags
);
77 int port_filter::access(boost::uint16_t port
) const
79 return m_filter
.access(port
);
82 void ip_filter::print() const
84 for (range_t::iterator i = m_access_list.begin(); i != m_access_list.end(); ++i)
86 std::cout << i->start.as_string() << " " << i->access << "\n";