90f74e79d54e26d9c923e8d4380338d54bf3cfcc
[senf.git] / Socket / Protocols / INet / MulticastSocketProtocol.hh
1 // $Id$
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.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 MulticastSocketProtocol public header */
25
26 #ifndef HH_MulticastSocketProtocol_
27 #define HH_MulticastSocketProtocol_ 1
28
29 // Custom includes
30 #include "../../../Socket/SocketProtocol.hh"
31 #include "INet4Address.hh"
32 #include "INet6Address.hh"
33
34 //#include "MulticastSocketProtocol.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf {
38
39     ///\addtogroup protocol_facets_group
40     ///\{
41    
42     /** \brief Generic addressing type independent multicast protocol facet
43
44         \todo implement complete new multicast API from RFC3678 (as far as supported by linux)
45         \bug mcLeaveSSMSource fails with EADDRNOTAVAIL
46      */
47     class MulticastSocketProtocol 
48         : public virtual SocketProtocol
49     {
50     public:
51         void broadcastEnabled(bool v) const; ///< Enable broadcast send/receive
52                                         /**< If this option is enabled, broadcast UDP messages will
53                                              be received on the socket and the socket will be
54                                              allowed to send out broadcast UDP messages
55                                              \param[in] v \c true to enable broadcast send/receive,
56                                                  \c false to disable */
57
58         bool broadcastEnabled() const;  ///< Get broadcast send/receive state
59                                         /**< \returns Current state of the broadcastEnabled()
60                                              option. */
61
62
63         unsigned mcTTL() const;         ///< Return current multicast TTL
64         void mcTTL(unsigned value) const; ///< Set multicast TTL
65
66         bool mcLoop() const;            ///< Return current multicast loopback state. 
67         void mcLoop(bool value) const;  ///< Set multicast loopback state
68         /**< If set to false via \c mcLoop(value) multicast messages will not be looped back  to local sockets. Default value is \c true (1).   */
69
70         void mcIface(std::string const & iface = std::string()) const;
71                                         ///< Set multicast send interface of the socket
72                                         /**< \param[in] iface name of interface to send multicast
73                                              data from */
74     };
75
76     /** \brief Multicast protocol facet for INet4 addressable multicast enabled sockets
77      */
78     class INet4MulticastSocketProtocol
79         : public MulticastSocketProtocol
80     {
81     public:
82         void mcAddMembership(INet4Address const & mcAddr) const;
83                                         ///< Join multicast group on default interface
84                                         /**< This member will add \a mcAddr to the list of multicast
85                                              groups received. The group is joined on the default
86                                              interface.
87                                              \param[in] mcAddr address of group to join */
88         void mcAddMembership(INet4Address const & mcAddr, INet4Address const & localAddr) 
89             const;
90                                         ///< join multicast group on a specific interface
91                                         /**< This member will add \a mcAddr to the list of multicast
92                                              groups received. The group is joined on the interface
93                                              with the given local address.
94                                              \deprecated Use \link mcAddMembership(INet4Address const & mcAddr, std::string const & iface) const mcAddMembership( \a mcAddr , \a iface )\endlink 
95                                                  for compatibility with the IPv6 API.
96                                              \param[in] mcAddr address of group to join
97                                              \param[in] localAddr address of interface to join on */
98         void mcAddMembership(INet4Address const & mcAddr, std::string const & iface) const;
99                                         ///< join multicast group on a specific interface
100                                         /**< This member will add \a mcAddr to the list of multicast
101                                              groups received. The group is joined on the given
102                                              interface.
103                                              \param[in] mcAddr address of group to join
104                                              \param[in] iface interface name */
105
106         void mcDropMembership(INet4Address const & mcAddr) const;
107                                         ///< Leave multicast group
108                                         /**< This member will remove \a mcAddr from the list of
109                                              multicast groups received. The group is left from the
110                                              default interface.
111                                              \param[in] mcAddr address of group to leave */
112         void mcDropMembership(INet4Address const & mcAddr, INet4Address const & localAddr) 
113             const;
114                                         ///< leave multicast group on a specific interface
115                                         /**< This member will remove \a mcAddr from the list of
116                                              multicast groups received. The group is left from the
117                                              interface with the given local address.
118                                              \deprecated Use \link mcDropMembership(INet4Address const & mcAddr, std::string const & iface) const mcDropMembership( \a mcAddr , \a iface )\endlink 
119                                                  for compatibility with the IPv6 API.
120                                              \param[in] mcAddr address of group to leave
121                                              \param[in] localAddr address of interface to leave
122                                                  from */
123         void mcDropMembership(INet4Address const & mcAddr, std::string const & iface) 
124             const;
125                                         ///< leave multicast group on a specific interface
126                                         /**< This member will remove \a mcAddr from the list of
127                                              multicast groups received. The group is left from the
128                                              interface with the given local address.
129                                              \param[in] mcAddr address of group to leave
130                                              \param[in] iface interface name */
131
132         void mcJoinSSMSource(INet4Address const & group, INet4Address const & source, 
133                              std::string const & iface) const;
134                                         ///< join SSM multicast group
135                                         /**< This call will join the multicast group \a group for
136                                              traffic from \a source. A single group may be joined
137                                              multiple times on different sources.
138                                              \param[in] group multicast group to join
139                                              \param[in] source SSM multicast source to join the
140                                                  group on
141                                              \param[in] iface interface to join the group on */
142         void mcLeaveSSMSource(INet4Address const & group, INet4Address const & source,
143                               std::string const & iface) const;
144                                         ///< leave SSM multicast group
145                                         /**< This call will leave the multicast group \a group for
146                                              traffic from \a source.
147                                              \param[in] group multicast group to leave
148                                              \param[in] source SSM multicast source to leave the
149                                                  group from
150                                              \param[in] iface interface to leave the group on */
151     };
152
153     /** \brief Multicast protocol facet for INet6 addressable multicast enabled sockets
154
155         This implementation supports INet6 mapped INet4 multicast addresses. This is a linux
156         specific extension and NOT part of the relevant RFCs.
157      */
158     class INet6MulticastSocketProtocol
159         : public MulticastSocketProtocol
160     {
161     public:
162         void mcAddMembership(INet6Address const & mcAddr) const;
163                                         ///< Join multicast group on default interface
164                                         /**< This member will add \a mcAddr to the list of multicast
165                                              groups received. The group is joined on the default
166                                              interface.
167                                              \param[in] mcAddr address of group to join */
168         void mcAddMembership(INet6Address const & mcAddr, std::string const & iface);
169                                         ///< join multicast group on a specific interface
170                                         /**< This member will add \a mcAddr to the list of multicast
171                                              groups received. The group is joined on the given
172                                              interface.
173                                              \param[in] mcAddr address of group to join
174                                              \param[in] iface interface name */
175
176         void mcDropMembership(INet6Address const & mcAddr) const;
177                                         ///< Leave multicast group
178                                         /**< This member will remove \a mcAddr from the list of
179                                              multicast groups received. The group is left from the
180                                              default interface.
181                                              \param[in] mcAddr address of group to leave */
182         void mcDropMembership(INet6Address const & mcAddr, std::string const & iface) const;
183                                         ///< leave multicast group on a specific interface
184                                         /**< This member will remove \a mcAddr from the list of
185                                              multicast groups received. The group is left from the
186                                              interface with the given local address.
187                                              \param[in] mcAddr address of group to leave
188                                              \param[in] iface interface name */
189
190         void mcJoinSSMSource(INet6Address const & group, INet6Address const & source, 
191                              std::string const & iface) const;
192                                         ///< join SSM multicast group
193                                         /**< This call will join the multicast group \a group for
194                                              traffic from \a source. A single group may be joined
195                                              multiple times on different sources.
196                                              \param[in] group multicast group to join
197                                              \param[in] source SSM multicast source to join the
198                                                  group on
199                                              \param[in] iface interface to join the group on */
200         void mcJoinSSMSource(INet6Address const & group, INet6Address const & source, 
201                              int ifacei) const;
202                                         ///< join SSM multicast group
203                                         /**< This call will join the multicast group \a group for
204                                              traffic from \a source. A single group may be joined
205                                              multiple times on different sources.
206                                              \param[in] group multicast group to join
207                                              \param[in] source SSM multicast source to join the
208                                                  group on
209                                              \param[in] ifacei interface index to join the group on */
210         void mcJoinSSMSource(INet6Address const & group, INet6Address const & source) const;
211                                         ///< join SSM multicast group
212                                         /**< This call will join the multicast group \a group for
213                                              traffic from \a source. A single group may be joined
214                                              multiple times on different sources.
215                                              \param[in] group multicast group to join
216                                              \param[in] source SSM multicast source to join the
217                                                  group on */
218         void mcLeaveSSMSource(INet6Address const & group, INet6Address const & source,
219                               std::string const & iface) const;
220                                         ///< leave SSM multicast group
221                                         /**< This call will leave the multicast group \a group for
222                                              traffic from \a source.
223                                              \param[in] group multicast group to leave
224                                              \param[in] source SSM multicast source to leave the
225                                                  group from
226                                              \param[in] iface interface to leave the group on */
227     };
228
229     ///\}
230 }
231
232 ///////////////////////////////hh.e////////////////////////////////////////
233 //#include "MulticastSocketProtocol.cci"
234 //#include "MulticastSocketProtocol.ct"
235 //#include "MulticastSocketProtocol.cti"
236 #endif
237
238 \f
239 // Local Variables:
240 // mode: c++
241 // fill-column: 100
242 // comment-column: 40
243 // c-file-style: "senf"
244 // indent-tabs-mode: nil
245 // ispell-local-dictionary: "american"
246 // compile-command: "scons -u test"
247 // End: