303ea4b0c96ce4b45dcc896dcebe28a0f4975a0b
[senf.git] / Socket / Protocols / INet / INet4Address.hh
1 // Copyright (C) 2007 
2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
4 //     Stefan Bund <g0dil@berlios.de>
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
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20
21 /** \file
22     \brief INet4Address public header */
23
24 #ifndef HH_INet4Address_
25 #define HH_INet4Address_ 1
26
27 // Custom includes
28 #include <iostream>
29 #include <string>
30 #include <boost/cstdint.hpp>
31 #include "Utils/SafeBool.hh"
32
33 //#include "INet4Address.mpp"
34 ///////////////////////////////hh.p////////////////////////////////////////
35
36 namespace senf {
37     
38     /** \brief
39       */
40     class INet4Address
41         : public ComparableSafeBool<INet4Address>
42     {
43     public:
44         typedef uint32_t address_type;
45
46         static INet4Address const None;
47         static INet4Address const Loopback;
48         static INet4Address const Broadcast;
49
50         INet4Address();
51         explicit INet4Address(address_type value);
52
53         static INet4Address from_string(std::string const & s);
54         template <class InputIterator> 
55         static INet4Address from_data(InputIterator i);
56         static INet4Address from_inaddr(unsigned long v);
57
58         bool local() const;
59         bool loopback() const;
60         bool multicast() const;
61         bool broadcast() const;
62         bool boolean_test() const;
63
64         unsigned long raw() const;
65
66         struct SyntaxException : public std::exception
67         { virtual char const * what() const throw() { return "invalid INet4 address syntax"; } };
68
69     private:
70         // Hmm ... address_type or unsigned long? I'd use address_type but the man pages for in_addr
71         // have sa_addr as unsigned long
72         unsigned long addr_;
73     };
74
75     std::ostream & operator<<(std::ostream & os, INet4Address const & addr);
76
77 }
78
79 ///////////////////////////////hh.e////////////////////////////////////////
80 #include "INet4Address.cci"
81 //#include "INet4Address.ct"
82 #include "INet4Address.cti"
83 #endif
84
85 \f
86 // Local Variables:
87 // mode: c++
88 // fill-column: 100
89 // comment-column: 40
90 // c-file-style: "senf"
91 // indent-tabs-mode: nil
92 // ispell-local-dictionary: "american"
93 // compile-command: "scons -u test"
94 // End: