Renamed namespaces satcom::lib and satcom::pkf to senf
[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     // TODO: Implement real INet4Address datatype and 
42     // rename this one to INet4SockAddress ...
43
44     class INet4Address
45     {
46     public:
47         INet4Address();
48         INet4Address(char const * address);
49         INet4Address(std::string address);
50         INet4Address(std::string host, unsigned port);
51
52         bool operator==(INet4Address const & other) const;
53
54         std::string str() const;
55         std::string host() const;
56         unsigned port() const;
57
58         // TODO: Interface
59
60         void clear();
61
62         struct sockaddr * sockaddr_p();
63         struct sockaddr const * sockaddr_p() const;
64         unsigned sockaddr_len() const;
65
66     private:
67         void assignString(std::string addr);
68         
69         struct ::sockaddr_in addr_;
70     };
71
72     std::ostream & operator<<(std::ostream & os, INet4Address const & addr);
73
74     class INet6Address
75     {
76         // TODO: Implement
77     };
78     
79     struct INet4AddressingPolicy 
80         : public AddressingPolicyBase,
81           private GenericAddressingPolicy<INet4Address>
82     {
83         typedef INet4Address Address;
84
85         using GenericAddressingPolicy<INet4Address>::peer;
86         using GenericAddressingPolicy<INet4Address>::local;
87         using GenericAddressingPolicy<INet4Address>::connect;
88         using GenericAddressingPolicy<INet4Address>::bind;
89     };
90
91     struct INet6AddressingPolicy : public AddressingPolicyBase
92     {
93         typedef INet6Address Address;
94
95         // TODO: Implement
96     };
97
98     struct InvalidINetAddressException : public std::exception
99     { char const * what() const throw() { return "invalid inet address"; } };
100
101 }
102
103 ///////////////////////////////hh.e////////////////////////////////////////
104 #include "INetAddressing.cci"
105 //#include "INetAddressing.ct"
106 //#include "INetAddressing.cti"
107 //#include "INetAddressing.mpp"
108 #endif
109
110 \f
111 // Local Variables:
112 // mode: c++
113 // c-file-style: "senf"
114 // End: