d55b229e7e9e82aa0a1f665189206c6a6a8e7c02
[senf.git] / senf / 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_SENF_Socket_Protocols_INet_MulticastSocketProtocol_
27 #define HH_SENF_Socket_Protocols_INet_MulticastSocketProtocol_ 1
28
29 // Custom includes
30 #include <senf/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
69                                              will not be looped back to local sockets. Default value
70                                              is \c true. */
71
72         void mcIface(std::string const & iface = std::string()) const;
73                                         ///< Set multicast send interface of the socket
74                                         /**< \param[in] iface name of interface to send multicast
75                                              data from
76
77                                              Under current linux versions this option is broken at
78                                              best. Don't use. */
79     };
80
81     /** \brief Multicast protocol facet for INet4 addressable multicast enabled sockets
82      */
83     class INet4MulticastSocketProtocol
84         : public MulticastSocketProtocol
85     {
86     public:
87         void mcAddMembership(INet4Address const & mcAddr) const;
88                                         ///< Join multicast group on default interface
89                                         /**< This member will add \a mcAddr to the list of multicast
90                                              groups received. The group is joined on the default
91                                              interface.
92                                              \param[in] mcAddr address of group to join */
93         void mcAddMembership(INet4Address const & mcAddr, INet4Address const & localAddr) const;
94                                         ///< join multicast group on a specific interface
95                                         /**< This member will add \a mcAddr to the list of multicast
96                                              groups received. The group is joined on the interface
97                                              with the given local address.
98                                              \deprecated Use \link mcAddMembership(INet4Address const & mcAddr, std::string const & iface) const mcAddMembership( \a mcAddr , \a iface )\endlink
99                                                  for compatibility with the IPv6 API.
100                                              \param[in] mcAddr address of group to join
101                                              \param[in] localAddr address of interface to join on */
102         void mcAddMembership(INet4Address const & mcAddr, std::string const & iface) const;
103                                         ///< join multicast group on a specific interface
104                                         /**< This member will add \a mcAddr to the list of multicast
105                                              groups received. The group is joined on the given
106                                              interface.
107                                              \param[in] mcAddr address of group to join
108                                              \param[in] iface interface name */
109
110         void mcDropMembership(INet4Address const & mcAddr) const;
111                                         ///< Leave multicast group
112                                         /**< This member will remove \a mcAddr from the list of
113                                              multicast groups received. The group is left from the
114                                              default interface.
115                                              \param[in] mcAddr address of group to leave */
116         void mcDropMembership(INet4Address const & mcAddr, INet4Address const & localAddr)
117             const;
118                                         ///< leave multicast group on a specific interface
119                                         /**< This member will remove \a mcAddr from the list of
120                                              multicast groups received. The group is left from the
121                                              interface with the given local address.
122                                              \deprecated Use \link mcDropMembership(INet4Address const & mcAddr, std::string const & iface) const mcDropMembership( \a mcAddr , \a iface )\endlink
123                                                  for compatibility with the IPv6 API.
124                                              \param[in] mcAddr address of group to leave
125                                              \param[in] localAddr address of interface to leave
126                                                  from */
127         void mcDropMembership(INet4Address const & mcAddr, std::string const & iface)
128             const;
129                                         ///< leave multicast group on a specific interface
130                                         /**< This member will remove \a mcAddr from the list of
131                                              multicast groups received. The group is left from the
132                                              interface with the given local address.
133                                              \param[in] mcAddr address of group to leave
134                                              \param[in] iface interface name */
135
136         void mcJoinSSMSource(INet4Address const & group, INet4Address const & source,
137                              std::string const & iface) const;
138                                         ///< join SSM multicast group
139                                         /**< This call will join the multicast group \a group for
140                                              traffic from \a source. A single group may be joined
141                                              multiple times on different sources.
142                                              \param[in] group multicast group to join
143                                              \param[in] source SSM multicast source to join the
144                                                  group on
145                                              \param[in] iface interface to join the group on */
146         void mcLeaveSSMSource(INet4Address const & group, INet4Address const & source,
147                               std::string const & iface) const;
148                                         ///< leave SSM multicast group
149                                         /**< This call will leave the multicast group \a group for
150                                              traffic from \a source.
151                                              \param[in] group multicast group to leave
152                                              \param[in] source SSM multicast source to leave the
153                                                  group from
154                                              \param[in] iface interface to leave the group on */
155     };
156
157     /** \brief Multicast protocol facet for INet6 addressable multicast enabled sockets
158
159         This implementation supports INet6 mapped INet4 multicast addresses. This is a linux
160         specific extension and NOT part of the relevant RFCs.
161      */
162     class INet6MulticastSocketProtocol
163         : public MulticastSocketProtocol
164     {
165     public:
166         void mcAddMembership(INet6Address const & mcAddr) const;
167                                         ///< Join multicast group on default interface
168                                         /**< This member will add \a mcAddr to the list of multicast
169                                              groups received. The group is joined on the default
170                                              interface.
171                                              \param[in] mcAddr address of group to join */
172         void mcAddMembership(INet6Address const & mcAddr, std::string const & iface) const;
173                                         ///< join multicast group on a specific interface
174                                         /**< This member will add \a mcAddr to the list of multicast
175                                              groups received. The group is joined on the given
176                                              interface.
177                                              \param[in] mcAddr address of group to join
178                                              \param[in] iface interface name */
179
180         void mcDropMembership(INet6Address const & mcAddr) const;
181                                         ///< Leave multicast group
182                                         /**< This member will remove \a mcAddr from the list of
183                                              multicast groups received. The group is left from the
184                                              default interface.
185                                              \param[in] mcAddr address of group to leave */
186         void mcDropMembership(INet6Address const & mcAddr, std::string const & iface) const;
187                                         ///< leave multicast group on a specific interface
188                                         /**< This member will remove \a mcAddr from the list of
189                                              multicast groups received. The group is left from the
190                                              interface with the given local address.
191                                              \param[in] mcAddr address of group to leave
192                                              \param[in] iface interface name */
193
194         void mcJoinSSMSource(INet6Address const & group, INet6Address const & source,
195                              std::string const & iface) const;
196                                         ///< join SSM multicast group
197                                         /**< This call will join the multicast group \a group for
198                                              traffic from \a source. A single group may be joined
199                                              multiple times on different sources.
200                                              \param[in] group multicast group to join
201                                              \param[in] source SSM multicast source to join the
202                                                  group on
203                                              \param[in] iface interface to join the group on. If set
204                                                  to the empty string, use the default interface. */
205         void mcJoinSSMSource(INet6Address const & group, INet6Address const & source,
206                              int ifacei = 0) const;
207                                         ///< join SSM multicast group
208                                         /**< This call will join the multicast group \a group for
209                                              traffic from \a source. A single group may be joined
210                                              multiple times on different sources.
211                                              \param[in] group multicast group to join
212                                              \param[in] source SSM multicast source to join the
213                                                  group on
214                                              \param[in] ifacei optional interface index to join the
215                                                  group on */
216         void mcLeaveSSMSource(INet6Address const & group, INet6Address const & source,
217                               std::string const & iface) const;
218                                         ///< leave SSM multicast group
219                                         /**< This call will leave the multicast group \a group for
220                                              traffic from \a source.
221                                              \param[in] group multicast group to leave
222                                              \param[in] source SSM multicast source to leave the
223                                                  group from
224                                              \param[in] iface interface to leave the group on */
225     };
226
227     ///\}
228 }
229
230 ///////////////////////////////hh.e////////////////////////////////////////
231 //#include "MulticastSocketProtocol.cci"
232 //#include "MulticastSocketProtocol.ct"
233 //#include "MulticastSocketProtocol.cti"
234 #endif
235
236 \f
237 // Local Variables:
238 // mode: c++
239 // fill-column: 100
240 // comment-column: 40
241 // c-file-style: "senf"
242 // indent-tabs-mode: nil
243 // ispell-local-dictionary: "american"
244 // compile-command: "scons -u test"
245 // End: