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