6c1072df4e1184ab644a3c131a1fa5b4a3a4e3be
[senf.git] / Socket / GenericSockAddr.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 /** \file 
24     \brief GenericSockAddr public header */
25
26 /** \defgroup addr_group Socket Addressing
27     
28     To support the core socket functionality we need a collection of classing providing addressing
29     for the different protocols. 
30
31     Every Address Implementation used with the standard policy classes Has to have a set of minimum
32     members. These members are documented in GenericSockAddr. However, these members are \e neither
33     abstract \e nor virtual and other address classes do \e not inherit from GenericSockAddr. The
34     address classes are not usable polymorphically for performance reasons.
35     
36     The interface defined above forces the implementation to be directly based on the corresponding
37     sockaddr data structures provided by the BSD socket API. These structures however are wrapped
38     into more flexible and more easy to use classes. Using the sockaddr representation increases the
39     performance since any intermediarre conversions are skipped.
40  */
41
42 #ifndef HH_GenericSockAddr_
43 #define HH_GenericSockAddr_ 1
44
45 // Custom includes
46 #include <sys/socket.h>
47
48 //#include "GenericSockAddr.mpp"
49 ///////////////////////////////hh.p////////////////////////////////////////
50
51 namespace senf {
52
53     /// \addtogroup addr_group
54     /// @{
55
56     /** \brief Generic protocol-independant socket address
57         
58         This address type does not depend on the protocol of the socket. It does nowever not support
59         any protocol specific API, so access to the address is very limited.
60      */
61     class GenericSockAddr
62     {
63     public:
64         GenericSockAddr();
65
66         /// \name Generic Address Interface
67         /// @{
68
69         struct sockaddr * sockaddr_p(); ///< Return a pointer to sockaddr structure
70                                         /**< The exact structure pointed to depends on the address
71                                              family. The data pointed to must be \e mutable. The
72                                              value must be changeable and any change of the value
73                                              through this pointer must be reflected in the visible
74                                              address interface. 
75                                              \returns non-const (!) pointer to sockaddr structure */
76         struct sockaddr const * sockaddr_p() const; ///< Return a pointer to sockaddr structure
77                                         /**< This member is like sockaddr_p(), hoewever it does not
78                                              allow changing the address.
79                                              \returns const pointer to sockaddr structure */
80         unsigned sockaddr_len() const;  ///< Return size of address
81                                         /**< This meember return the size of the socket address
82                                              structure as returned by sockaddr_p() in bytes. 
83                                              \returns size of respective sockaddr structure in bytes
84                                           */
85         /// @}
86         
87     private:
88         struct ::sockaddr_storage addr_;
89     };
90
91     /// @}
92 }
93
94 ///////////////////////////////hh.e////////////////////////////////////////
95 #include "GenericSockAddr.cci"
96 //#include "GenericSockAddr.ct"
97 //#include "GenericSockAddr.cti"
98 //#include "GenericSockAddr.mpp"
99 #endif
100
101 \f
102 // Local Variables:
103 // mode: c++
104 // c-file-style: "senf"
105 // fill-column: 100
106 // End: