9b8b160aaae7f1d067a2d6ee63ac7e36ac80adac
[senf.git] / Socket / INetAddressing.hh
1 // $Id$
2 //
3 // Copyright (C) 2006 
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 #ifndef HH_INetAddressing_
24 #define HH_INetAddressing_ 1
25
26 // Custom includes
27 #include <string>
28 #include <exception>
29 #include <netinet/in.h>
30 #include "SocketPolicy.hh"
31 #include "ClientSocketHandle.hh"
32 #include "CommunicationPolicy.hh"
33 #include "GenericAddressingPolicy.hh"
34
35 //#include "INetAddressing.mpp"
36 ///////////////////////////////hh.p////////////////////////////////////////
37
38 namespace senf {
39
40
41     /** \brief
42         
43         \todo Implement real INet4Address datatype and 
44         rename this one to INet4SockAddress ... 
45
46         \todo Implement more complete interface
47      */
48     class INet4Address
49     {
50     public:
51         INet4Address();
52         INet4Address(char const * address);
53         INet4Address(std::string address);
54         INet4Address(std::string host, unsigned port);
55
56         bool operator==(INet4Address const & other) const;
57
58         std::string str() const;
59         std::string host() const;
60         unsigned port() const;
61
62         void clear();
63
64         struct sockaddr * sockaddr_p();
65         struct sockaddr const * sockaddr_p() const;
66         unsigned sockaddr_len() const;
67
68     private:
69         void assignString(std::string addr);
70         
71         struct ::sockaddr_in addr_;
72     };
73
74     std::ostream & operator<<(std::ostream & os, INet4Address const & addr);
75
76     /** \brief
77
78         \todo Implement
79      */
80     class INet6Address
81     {
82     };
83     
84     struct INet4AddressingPolicy 
85         : public AddressingPolicyBase,
86           private GenericAddressingPolicy<INet4Address>
87     {
88         typedef INet4Address Address;
89
90         using GenericAddressingPolicy<INet4Address>::peer;
91         using GenericAddressingPolicy<INet4Address>::local;
92         using GenericAddressingPolicy<INet4Address>::connect;
93         using GenericAddressingPolicy<INet4Address>::bind;
94     };
95
96     /** \brief
97
98         \todo Implement
99      */
100     struct INet6AddressingPolicy : public AddressingPolicyBase
101     {
102         typedef INet6Address Address;
103     };
104
105     struct InvalidINetAddressException : public std::exception
106     { char const * what() const throw() { return "invalid inet address"; } };
107
108 }
109
110 ///////////////////////////////hh.e////////////////////////////////////////
111 #include "INetAddressing.cci"
112 //#include "INetAddressing.ct"
113 //#include "INetAddressing.cti"
114 //#include "INetAddressing.mpp"
115 #endif
116
117 \f
118 // Local Variables:
119 // mode: c++
120 // c-file-style: "senf"
121 // End: