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 528464 : class addr_range
47 : {
48 : public:
49 : typedef std::shared_ptr<addr_range> pointer_t;
50 : typedef std::vector<addr_range> vector_t;
51 :
52 : bool has_from() const;
53 : bool has_to() const;
54 : bool is_range() const;
55 : bool is_empty() const;
56 : bool is_in(addr const & rhs) const;
57 : bool is_ipv4() const;
58 :
59 : void set_from(addr const & from);
60 : addr & get_from();
61 : addr const & get_from() const;
62 : void set_to(addr const & to);
63 : addr & get_to();
64 : addr const & get_to() const;
65 : void from_cidr(addr const & range);
66 :
67 : addr_range intersection(addr_range const & rhs) const;
68 : addr_range union_if_possible(addr_range const & rhs) const;
69 : bool match(addr const & address) const;
70 : compare_t compare(addr_range const & rhs) const;
71 :
72 : private:
73 : bool f_has_from = false;
74 : bool f_has_to = false;
75 : addr f_from = addr();
76 : addr f_to = addr();
77 : };
78 :
79 :
80 : bool address_match_ranges(addr_range::vector_t ranges, addr const & address);
81 :
82 :
83 :
84 :
85 : }
86 : // namespace addr
87 : // vim: ts=4 sw=4 et
|