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

« back to all changes in this revision

Viewing changes to src/ip_filter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Cristian Greco
  • Date: 2008-07-02 10:46:21 UTC
  • Revision ID: james.westby@ubuntu.com-20080702104621-jzx3pfke9lkcxfxn
Tags: upstream-0.13.1
ImportĀ upstreamĀ versionĀ 0.13.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright (c) 2005, Arvid Norberg
 
4
All rights reserved.
 
5
 
 
6
Redistribution and use in source and binary forms, with or without
 
7
modification, are permitted provided that the following conditions
 
8
are met:
 
9
 
 
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.
 
18
 
 
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.
 
30
 
 
31
*/
 
32
 
 
33
#include "libtorrent/pch.hpp"
 
34
 
 
35
#include "libtorrent/ip_filter.hpp"
 
36
#include <boost/utility.hpp>
 
37
//#include <iostream>
 
38
 
 
39
 
 
40
namespace libtorrent
 
41
{
 
42
        void ip_filter::add_rule(address first, address last, int flags)
 
43
        {
 
44
                if (first.is_v4())
 
45
                {
 
46
                        TORRENT_ASSERT(last.is_v4());
 
47
                        m_filter4.add_rule(first.to_v4().to_bytes(), last.to_v4().to_bytes(), flags);
 
48
                }
 
49
                else if (first.is_v6())
 
50
                {
 
51
                        TORRENT_ASSERT(last.is_v6());
 
52
                        m_filter6.add_rule(first.to_v6().to_bytes(), last.to_v6().to_bytes(), flags);
 
53
                }
 
54
                else
 
55
                        TORRENT_ASSERT(false);
 
56
        }
 
57
 
 
58
        int ip_filter::access(address const& addr) const
 
59
        {
 
60
                if (addr.is_v4())
 
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());
 
64
        }
 
65
 
 
66
        ip_filter::filter_tuple_t ip_filter::export_filter() const
 
67
        {
 
68
                return boost::make_tuple(m_filter4.export_filter<address_v4>()
 
69
                        , m_filter6.export_filter<address_v6>());
 
70
        }
 
71
        
 
72
        void port_filter::add_rule(boost::uint16_t first, boost::uint16_t last, int flags)
 
73
        {
 
74
                m_filter.add_rule(first, last, flags);
 
75
        }
 
76
 
 
77
        int port_filter::access(boost::uint16_t port) const
 
78
        {
 
79
                return m_filter.access(port);
 
80
        }
 
81
/*
 
82
        void ip_filter::print() const
 
83
        {
 
84
                for (range_t::iterator i =  m_access_list.begin(); i != m_access_list.end(); ++i)
 
85
                {
 
86
                        std::cout << i->start.as_string() << " " << i->access << "\n";
 
87
                }
 
88
        }
 
89
*/
 
90
}
 
91