Line data Source code
1 : // Copyright (c) 2012-2021 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/libaddr
4 : //
5 : // Permission is hereby granted, free of charge, to any person obtaining a
6 : // copy of this software and associated documentation files (the
7 : // "Software"), to deal in the Software without restriction, including
8 : // without limitation the rights to use, copy, modify, merge, publish,
9 : // distribute, sublicense, and/or sell copies of the Software, and to
10 : // permit persons to whom the Software is furnished to do so, subject to
11 : // the following conditions:
12 : //
13 : // The above copyright notice and this permission notice shall be included
14 : // in all copies or substantial portions of the Software.
15 : //
16 : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 : // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 : // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 : // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 : // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 : // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 : // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 : #pragma once
24 :
25 : /** \file
26 : * \brief The addr_range class.
27 : *
28 : * This header defines the addr_range class used to handle one range of
29 : * addresses (with a 'from' and a 'to' pair of addresses.)
30 : *
31 : * Also we support CIDR, a CIDR is not a range. A range can define anything
32 : * that is not a perfect CIDR match. For example, you could have a start
33 : * address of 192.168.10.5 and an end address of 192.168.10.10.
34 : */
35 :
36 : // self
37 : //
38 : #include "libaddr/addr.h"
39 :
40 :
41 :
42 : namespace addr
43 : {
44 :
45 :
46 :
47 :
48 131868 : class addr_range
49 : {
50 : public:
51 : typedef std::shared_ptr<addr_range> pointer_t;
52 : typedef std::vector<addr_range> vector_t;
53 :
54 : bool has_from() const;
55 : bool has_to() const;
56 : bool is_range() const;
57 : bool is_empty() const;
58 : bool is_in(addr const & rhs) const;
59 :
60 : void set_from(addr const & from);
61 : addr & get_from();
62 : addr const & get_from() const;
63 : void set_to(addr const & to);
64 : addr & get_to();
65 : addr const & get_to() const;
66 :
67 : addr_range intersection(addr_range const & rhs) const;
68 : bool match(addr const & address) const;
69 :
70 : private:
71 : bool f_has_from = false;
72 : bool f_has_to = false;
73 : addr f_from = addr();
74 : addr f_to = addr();
75 : };
76 :
77 :
78 : bool address_match_ranges(addr_range::vector_t ranges, addr const & address);
79 :
80 :
81 :
82 :
83 : }
84 : // namespace addr
85 : // vim: ts=4 sw=4 et
|