multicast.hpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. //
  2. // ip/multicast.hpp
  3. // ~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2021 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. #ifndef BOOST_ASIO_IP_MULTICAST_HPP
  11. #define BOOST_ASIO_IP_MULTICAST_HPP
  12. #if defined(_MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
  15. #include <boost/asio/detail/config.hpp>
  16. #include <cstddef>
  17. #include <boost/asio/ip/detail/socket_option.hpp>
  18. #include <boost/asio/detail/push_options.hpp>
  19. namespace boost {
  20. namespace asio {
  21. namespace ip {
  22. namespace multicast {
  23. /// Socket option to join a multicast group on a specified interface.
  24. /**
  25. * Implements the IPPROTO_IP/IP_ADD_MEMBERSHIP socket option.
  26. *
  27. * @par Examples
  28. * Setting the option to join a multicast group:
  29. * @code
  30. * boost::asio::ip::udp::socket socket(my_context);
  31. * ...
  32. * boost::asio::ip::address multicast_address =
  33. * boost::asio::ip::address::from_string("225.0.0.1");
  34. * boost::asio::ip::multicast::join_group option(multicast_address);
  35. * socket.set_option(option);
  36. * @endcode
  37. *
  38. * @par Concepts:
  39. * SettableSocketOption.
  40. */
  41. #if defined(GENERATING_DOCUMENTATION)
  42. typedef implementation_defined join_group;
  43. #else
  44. typedef boost::asio::ip::detail::socket_option::multicast_request<
  45. BOOST_ASIO_OS_DEF(IPPROTO_IP),
  46. BOOST_ASIO_OS_DEF(IP_ADD_MEMBERSHIP),
  47. BOOST_ASIO_OS_DEF(IPPROTO_IPV6),
  48. BOOST_ASIO_OS_DEF(IPV6_JOIN_GROUP)> join_group;
  49. #endif
  50. /// Socket option to leave a multicast group on a specified interface.
  51. /**
  52. * Implements the IPPROTO_IP/IP_DROP_MEMBERSHIP socket option.
  53. *
  54. * @par Examples
  55. * Setting the option to leave a multicast group:
  56. * @code
  57. * boost::asio::ip::udp::socket socket(my_context);
  58. * ...
  59. * boost::asio::ip::address multicast_address =
  60. * boost::asio::ip::address::from_string("225.0.0.1");
  61. * boost::asio::ip::multicast::leave_group option(multicast_address);
  62. * socket.set_option(option);
  63. * @endcode
  64. *
  65. * @par Concepts:
  66. * SettableSocketOption.
  67. */
  68. #if defined(GENERATING_DOCUMENTATION)
  69. typedef implementation_defined leave_group;
  70. #else
  71. typedef boost::asio::ip::detail::socket_option::multicast_request<
  72. BOOST_ASIO_OS_DEF(IPPROTO_IP),
  73. BOOST_ASIO_OS_DEF(IP_DROP_MEMBERSHIP),
  74. BOOST_ASIO_OS_DEF(IPPROTO_IPV6),
  75. BOOST_ASIO_OS_DEF(IPV6_LEAVE_GROUP)> leave_group;
  76. #endif
  77. /// Socket option for local interface to use for outgoing multicast packets.
  78. /**
  79. * Implements the IPPROTO_IP/IP_MULTICAST_IF socket option.
  80. *
  81. * @par Examples
  82. * Setting the option:
  83. * @code
  84. * boost::asio::ip::udp::socket socket(my_context);
  85. * ...
  86. * boost::asio::ip::address_v4 local_interface =
  87. * boost::asio::ip::address_v4::from_string("1.2.3.4");
  88. * boost::asio::ip::multicast::outbound_interface option(local_interface);
  89. * socket.set_option(option);
  90. * @endcode
  91. *
  92. * @par Concepts:
  93. * SettableSocketOption.
  94. */
  95. #if defined(GENERATING_DOCUMENTATION)
  96. typedef implementation_defined outbound_interface;
  97. #else
  98. typedef boost::asio::ip::detail::socket_option::network_interface<
  99. BOOST_ASIO_OS_DEF(IPPROTO_IP),
  100. BOOST_ASIO_OS_DEF(IP_MULTICAST_IF),
  101. BOOST_ASIO_OS_DEF(IPPROTO_IPV6),
  102. BOOST_ASIO_OS_DEF(IPV6_MULTICAST_IF)> outbound_interface;
  103. #endif
  104. /// Socket option for time-to-live associated with outgoing multicast packets.
  105. /**
  106. * Implements the IPPROTO_IP/IP_MULTICAST_TTL socket option.
  107. *
  108. * @par Examples
  109. * Setting the option:
  110. * @code
  111. * boost::asio::ip::udp::socket socket(my_context);
  112. * ...
  113. * boost::asio::ip::multicast::hops option(4);
  114. * socket.set_option(option);
  115. * @endcode
  116. *
  117. * @par
  118. * Getting the current option value:
  119. * @code
  120. * boost::asio::ip::udp::socket socket(my_context);
  121. * ...
  122. * boost::asio::ip::multicast::hops option;
  123. * socket.get_option(option);
  124. * int ttl = option.value();
  125. * @endcode
  126. *
  127. * @par Concepts:
  128. * GettableSocketOption, SettableSocketOption.
  129. */
  130. #if defined(GENERATING_DOCUMENTATION)
  131. typedef implementation_defined hops;
  132. #else
  133. typedef boost::asio::ip::detail::socket_option::multicast_hops<
  134. BOOST_ASIO_OS_DEF(IPPROTO_IP),
  135. BOOST_ASIO_OS_DEF(IP_MULTICAST_TTL),
  136. BOOST_ASIO_OS_DEF(IPPROTO_IPV6),
  137. BOOST_ASIO_OS_DEF(IPV6_MULTICAST_HOPS)> hops;
  138. #endif
  139. /// Socket option determining whether outgoing multicast packets will be
  140. /// received on the same socket if it is a member of the multicast group.
  141. /**
  142. * Implements the IPPROTO_IP/IP_MULTICAST_LOOP socket option.
  143. *
  144. * @par Examples
  145. * Setting the option:
  146. * @code
  147. * boost::asio::ip::udp::socket socket(my_context);
  148. * ...
  149. * boost::asio::ip::multicast::enable_loopback option(true);
  150. * socket.set_option(option);
  151. * @endcode
  152. *
  153. * @par
  154. * Getting the current option value:
  155. * @code
  156. * boost::asio::ip::udp::socket socket(my_context);
  157. * ...
  158. * boost::asio::ip::multicast::enable_loopback option;
  159. * socket.get_option(option);
  160. * bool is_set = option.value();
  161. * @endcode
  162. *
  163. * @par Concepts:
  164. * GettableSocketOption, SettableSocketOption.
  165. */
  166. #if defined(GENERATING_DOCUMENTATION)
  167. typedef implementation_defined enable_loopback;
  168. #else
  169. typedef boost::asio::ip::detail::socket_option::multicast_enable_loopback<
  170. BOOST_ASIO_OS_DEF(IPPROTO_IP),
  171. BOOST_ASIO_OS_DEF(IP_MULTICAST_LOOP),
  172. BOOST_ASIO_OS_DEF(IPPROTO_IPV6),
  173. BOOST_ASIO_OS_DEF(IPV6_MULTICAST_LOOP)> enable_loopback;
  174. #endif
  175. } // namespace multicast
  176. } // namespace ip
  177. } // namespace asio
  178. } // namespace boost
  179. #include <boost/asio/detail/pop_options.hpp>
  180. #endif // BOOST_ASIO_IP_MULTICAST_HPP