Line data Source code
1 : // Network Address -- classes functions to ease handling IP addresses
2 : // Copyright (C) 2012-2017 Made to Order Software Corp.
3 : //
4 : // http://snapwebsites.org/project/libaddr
5 : //
6 : // This program is free software; you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation; either version 2 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License
17 : // along with this program; if not, write to the Free Software
18 : // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 : #pragma once
20 :
21 : /** \file
22 : * \brief The addr_range class.
23 : *
24 : * This header defines the addr_range class used to handle one range of
25 : * addresses (with a 'from' and a 'to' pair of addresses.)
26 : *
27 : * Also we support CIDR, a CIDR is not a range. A range can define anything
28 : * that is not a perfect CIDR match. For example, you could have a start
29 : * address of 192.168.10.5 and an end address of 192.168.10.10.
30 : */
31 :
32 : // self
33 : //
34 : #include "addr.h"
35 :
36 : // C++ lib
37 : //
38 : #include <memory>
39 : #include <cstring>
40 :
41 : // C lib
42 : //
43 : #include <arpa/inet.h>
44 :
45 :
46 :
47 : namespace addr
48 : {
49 :
50 :
51 :
52 :
53 528258 : class addr_range
54 : {
55 : public:
56 : typedef std::shared_ptr<addr_range> pointer_t;
57 : typedef std::vector<addr_range> vector_t;
58 :
59 : bool has_from() const;
60 : bool has_to() const;
61 : bool is_range() const;
62 : bool is_empty() const;
63 : bool is_in(addr const & rhs) const;
64 :
65 : void set_from(addr const & from);
66 : addr & get_from();
67 : addr const & get_from() const;
68 : void set_to(addr const & to);
69 : addr & get_to();
70 : addr const & get_to() const;
71 :
72 : addr_range intersection(addr_range const & rhs) const;
73 : bool match(addr const & address) const;
74 :
75 : private:
76 : bool f_has_from = false;
77 : bool f_has_to = false;
78 : addr f_from;
79 : addr f_to;
80 : };
81 :
82 :
83 : bool address_match_ranges(addr_range::vector_t ranges, addr const & address);
84 :
85 :
86 :
87 :
88 : }
89 : // addr namespace
90 : // vim: ts=4 sw=4 et
|