mn_basic_multicast_ip_socket.hpp
Go to the documentation of this file.
1 /*
2 *This file is part of the Mini Thread Library (https://github.com/RoseLeBlood/MiniThread ).
3 *Copyright (c) 2018 Amber-Sophia Schroeck
4 *
5 *The Mini Thread Library is free software; you can redistribute it and/or modify
6 *it under the terms of the GNU Lesser General Public License as published by
7 *the Free Software Foundation, version 3, or (at your option) any later version.
8 
9 *The Mini Thread Library is distributed in the hope that it will be useful, but
10 *WITHOUT ANY WARRANTY; without even the implied warranty of
11 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 *General Public License for more details.
13 *
14 *You should have received a copy of the GNU Lesser General Public
15 *License along with the Mini Thread Library; if not, see
16 *<https://www.gnu.org/licenses/>.
17 */
18 #ifndef __MINILIB_BASIC_MULTICAST_IP_SOCKET_H__
19 #define __MINILIB_BASIC_MULTICAST_IP_SOCKET_H__
20 
21 #include "../mn_config.hpp"
23 
24 namespace mn {
25  namespace net {
31  public:
34 
38 
43  : base_type() { }
44 
48  int join_group(const ipaddress_type& groupAddress,
49  const ipaddress_type& infAddress = MNNET_IPV4_ADDRESS_ANY);
50 
54  int leave_group();
55 
59  int leave_group(const ipaddress_type& groupAddress,
60  const ipaddress_type& infAddress = MNNET_IPV4_ADDRESS_ANY);
61 
66  void set_loopback(bool flag);
67 
72  void set_time_to_live(int value);
73 
78  void set_interface(const ipaddress_type& infAddress);
79 
84  bool get_loopback();
85 
90  int get_time_to_live();
91 
97 
98  virtual void swap(self_typ& rhs) noexcept {
99  base_type::swap(rhs);
100  m_ipMulticast.swap(rhs.m_ipMulticast);
101  }
102  protected:
104  : base_type(hndl, endp) { }
106  : base_type(protocol) { }
107  private:
109  };
110 
111  #if MN_THREAD_CONFIG_NET_IPADDRESS6_ENABLE == MN_THREAD_CONFIG_YES
117  public:
120 
124 
129  : base_type() { }
130 
134  int join_group(const ipaddress_type& groupAddress, const uint8_t& uiInterface);
135 
139  int leave_group();
140 
144  int leave_group(const ipaddress_type& groupAddress, const uint8_t& uiInterface);
145 
150  void set_loopback(bool flag);
151 
156  void set_time_to_live(int value);
157 
162  void set_interface(const uint8_t& infAddress);
163 
168  bool get_loopback();
169 
174  int get_time_to_live();
175 
180  uint8_t get_interface();
181 
182  virtual void swap(self_typ& rhs) noexcept {
183  base_type::swap(rhs);
184  m_ipMulticast.swap(rhs.m_ipMulticast);
185  }
186  protected:
188  : base_type(hndl, endp) { }
190  : base_type(protocol) { }
191  private:
193  };
194  #endif // MN_THREAD_CONFIG_NET_IPADDRESS6_ENABLE
195 
196 
197 
198 
199  #if LWIP_UDP && LWIP_UDPLITE
204  class basic_multicast_lite_ip_socket : public basic_multicast_ip_socket {
205  public:
206  using self_typ = basic_multicast_lite_ip_socket;
207  using base_type = basic_multicast_ip_socket;
208 
209  using endpoint_type = typename base_type::endpoint_type;
210  using ipaddress_type = typename base_type::ipaddress_type;
211  using handle_type = typename base_type::handle_type;
212 
213  basic_dgramlite_ip_socket() : base_type(protocol_type::udp_lite) { }
214 
215  virtual void swap(self_typ& rhs) noexcept {
216  base_type::swap(rhs);
217  }
218  };
219  #endif
220  }
221 }
222 
223 #endif // __MINILIB_BASIC_MULTICAST_IP_SOCKET_H__
Basic dram socket class.
Definition: mn_basic_dgram_socket.hpp:121
typename base_type::endpoint_type endpoint_type
Definition: mn_basic_dgram_socket.hpp:126
typename base_type::handle_type handle_type
Definition: mn_basic_dgram_socket.hpp:128
typename base_type::ipaddress_type ipaddress_type
Definition: mn_basic_dgram_socket.hpp:127
basic_dgram_ip6_socket()
Definition: mn_basic_dgram_socket.hpp:130
Basic dram socket class.
Definition: mn_basic_dgram_socket.hpp:32
typename base_type::ipaddress_type ipaddress_type
Definition: mn_basic_dgram_socket.hpp:38
typename base_type::handle_type handle_type
Definition: mn_basic_dgram_socket.hpp:39
typename base_type::endpoint_type endpoint_type
Definition: mn_basic_dgram_socket.hpp:37
basic_dgram_ip_socket()
Construt.
Definition: mn_basic_dgram_socket.hpp:44
This class represents an internet (IP) version 4 host socket.
Definition: mn_basic_ip4_socket.hpp:31
virtual void swap(basic_ip4_socket &rhs) noexcept
Definition: mn_basic_ip4_socket.hpp:134
This class represents an internet (IP) version 6 host socket.
Definition: mn_basic_ip6_socket.hpp:33
virtual void swap(basic_ip6_socket &rhs) noexcept
Definition: mn_basic_ip6_socket.hpp:136
A basic_multicast_ip6_socket is a special dgram_ip6_socket that can be used to send packets to and re...
Definition: mn_basic_multicast_ip_socket.hpp:116
void set_loopback(bool flag)
Set the option socket_option_name::loopback.
Definition: mn_basic_multicast_ip_socket.cpp:169
bool get_loopback()
Get the value from option socket_option_name::multicast_loop.
Definition: mn_basic_multicast_ip_socket.cpp:191
int join_group(const ipaddress_type &groupAddress, const uint8_t &uiInterface)
Joins the specified multicast group.
Definition: mn_basic_multicast_ip_socket.cpp:124
ipaddress_type m_ipMulticast
Definition: mn_basic_multicast_ip_socket.hpp:192
basic_multicast_ip6_socket()
Construt an unconnected, unbound multicast socket.
Definition: mn_basic_multicast_ip_socket.hpp:128
void set_time_to_live(int value)
Set the option socket_option_name::ttl.
Definition: mn_basic_multicast_ip_socket.cpp:177
virtual void swap(self_typ &rhs) noexcept
Definition: mn_basic_multicast_ip_socket.hpp:182
int leave_group()
Leaves the specified multicast group.
Definition: mn_basic_multicast_ip_socket.cpp:143
void set_interface(const uint8_t &infAddress)
Set the option IP_MULTICAST_IF.
Definition: mn_basic_multicast_ip_socket.cpp:184
typename base_type::ipaddress_type ipaddress_type
Definition: mn_basic_multicast_ip_socket.hpp:122
basic_multicast_ip6_socket(const protocol_type &protocol)
Definition: mn_basic_multicast_ip_socket.hpp:189
int get_time_to_live()
Get the option IP_MULTICAST_TTL.
Definition: mn_basic_multicast_ip_socket.cpp:203
basic_multicast_ip6_socket(handle_type &hndl, endpoint_type *endp=nullptr)
Definition: mn_basic_multicast_ip_socket.hpp:187
uint8_t get_interface()
Get the option IP_MULTICAST_IF.
Definition: mn_basic_multicast_ip_socket.cpp:215
A multicast_ip_socket is a special dgram_ip_socket that can be used to send packets to and receive pa...
Definition: mn_basic_multicast_ip_socket.hpp:30
bool get_loopback()
Get the value from option socket_option_name::multicast_loop.
Definition: mn_basic_multicast_ip_socket.cpp:100
int leave_group()
Leaves the specified multicast group.
Definition: mn_basic_multicast_ip_socket.cpp:54
void set_loopback(bool flag)
Set the option socket_option_name::loopback.
Definition: mn_basic_multicast_ip_socket.cpp:79
basic_multicast_ip_socket(handle_type &hndl, endpoint_type *endp=nullptr)
Definition: mn_basic_multicast_ip_socket.hpp:103
void set_interface(const ipaddress_type &infAddress)
Set the option IP_MULTICAST_IF.
Definition: mn_basic_multicast_ip_socket.cpp:93
ipaddress_type m_ipMulticast
Definition: mn_basic_multicast_ip_socket.hpp:108
int join_group(const ipaddress_type &groupAddress, const ipaddress_type &infAddress=MNNET_IPV4_ADDRESS_ANY)
Joins the specified multicast group.
Definition: mn_basic_multicast_ip_socket.cpp:34
basic_multicast_ip_socket()
Construt an unconnected, unbound multicast socket.
Definition: mn_basic_multicast_ip_socket.hpp:42
void set_time_to_live(int value)
Set the option socket_option_name::ttl.
Definition: mn_basic_multicast_ip_socket.cpp:86
typename base_type::ipaddress_type ipaddress_type
Definition: mn_basic_multicast_ip_socket.hpp:36
basic_multicast_ip_socket(const protocol_type &protocol)
Definition: mn_basic_multicast_ip_socket.hpp:105
ipaddress_type get_interface()
Get the option IP_MULTICAST_IF.
Definition: mn_basic_multicast_ip_socket.cpp:114
int get_time_to_live()
Get the option IP_MULTICAST_TTL.
Definition: mn_basic_multicast_ip_socket.cpp:107
virtual void swap(self_typ &rhs) noexcept
Definition: mn_basic_multicast_ip_socket.hpp:98
#define MNNET_IPV4_ADDRESS_ANY
Definition: mn_basic_ip4_address.hpp:25
void swap(basic_any &x, basic_any &y) noexcept
Definition: mn_any.hpp:272
protocol_type
Defines socket protoco types for creating.
Definition: mn_net_types.hpp:60
@ udp_lite
This is an implementation of the Lightweight User Datagram Protocol (UDP-Lite), as described in RFC 3...
Definition: mn_allocator_typetraits.hpp:25
void swap(TAssignable &a, TAssignable &b)
Definition: mn_algorithm.hpp:312