11 #ifndef ASIO_IP_DETAIL_SOCKET_OPTION_HPP 12 #define ASIO_IP_DETAIL_SOCKET_OPTION_HPP 14 #if defined(_MSC_VER) && (_MSC_VER >= 1200) 16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200) 32 namespace socket_option {
35 template <
int IPv4_Level,
int IPv4_Name,
int IPv6_Level,
int IPv6_Name>
39 #if defined(__sun) || defined(__osf__) 42 #elif defined(_AIX) || defined(__hpux) || defined(__QNXNTO__) 59 : ipv4_value_(v ? 1 : 0),
60 ipv6_value_(v ? 1 : 0)
67 ipv4_value_ = v ? 1 : 0;
68 ipv6_value_ = v ? 1 : 0;
91 template <
typename Protocol>
92 int level(
const Protocol& protocol)
const 94 if (protocol.family() == PF_INET6)
100 template <
typename Protocol>
101 int name(
const Protocol& protocol)
const 103 if (protocol.family() == PF_INET6)
109 template <
typename Protocol>
110 void*
data(
const Protocol& protocol)
112 if (protocol.family() == PF_INET6)
118 template <
typename Protocol>
119 const void*
data(
const Protocol& protocol)
const 121 if (protocol.family() == PF_INET6)
127 template <
typename Protocol>
128 std::size_t
size(
const Protocol& protocol)
const 130 if (protocol.family() == PF_INET6)
131 return sizeof(ipv6_value_);
132 return sizeof(ipv4_value_);
136 template <
typename Protocol>
137 void resize(
const Protocol& protocol, std::size_t
s)
139 if (protocol.family() == PF_INET6)
141 if (s !=
sizeof(ipv6_value_))
143 std::length_error ex(
"multicast_enable_loopback socket option resize");
146 ipv4_value_ = ipv6_value_ ? 1 : 0;
150 if (s !=
sizeof(ipv4_value_))
152 std::length_error ex(
"multicast_enable_loopback socket option resize");
155 ipv6_value_ = ipv4_value_ ? 1 : 0;
160 ipv4_value_type ipv4_value_;
161 ipv6_value_type ipv6_value_;
165 template <
int IPv4_Level,
int IPv4_Name,
int IPv6_Level,
int IPv6_Name>
195 template <
typename Protocol>
196 int level(
const Protocol& protocol)
const 198 if (protocol.family() == PF_INET6)
204 template <
typename Protocol>
205 int name(
const Protocol& protocol)
const 207 if (protocol.family() == PF_INET6)
213 template <
typename Protocol>
220 template <
typename Protocol>
221 const int*
data(
const Protocol&)
const 227 template <
typename Protocol>
228 std::size_t
size(
const Protocol&)
const 230 return sizeof(value_);
234 template <
typename Protocol>
237 if (s !=
sizeof(value_))
239 std::length_error ex(
"unicast hops socket option resize");
244 value_ = value_ & 0xFF;
253 template <
int IPv4_Level,
int IPv4_Name,
int IPv6_Level,
int IPv6_Name>
257 #if defined(ASIO_WINDOWS) && defined(UNDER_CE) 274 if (v < 0 || v > 255)
276 std::out_of_range ex(
"multicast hops value out of range");
286 if (v < 0 || v > 255)
288 std::out_of_range ex(
"multicast hops value out of range");
303 template <
typename Protocol>
304 int level(
const Protocol& protocol)
const 306 if (protocol.family() == PF_INET6)
312 template <
typename Protocol>
313 int name(
const Protocol& protocol)
const 315 if (protocol.family() == PF_INET6)
321 template <
typename Protocol>
322 void*
data(
const Protocol& protocol)
324 if (protocol.family() == PF_INET6)
330 template <
typename Protocol>
331 const void*
data(
const Protocol& protocol)
const 333 if (protocol.family() == PF_INET6)
339 template <
typename Protocol>
340 std::size_t
size(
const Protocol& protocol)
const 342 if (protocol.family() == PF_INET6)
343 return sizeof(ipv6_value_);
344 return sizeof(ipv4_value_);
348 template <
typename Protocol>
349 void resize(
const Protocol& protocol, std::size_t
s)
351 if (protocol.family() == PF_INET6)
353 if (s !=
sizeof(ipv6_value_))
355 std::length_error ex(
"multicast hops socket option resize");
360 else if (ipv6_value_ > 255)
367 if (s !=
sizeof(ipv4_value_))
369 std::length_error ex(
"multicast hops socket option resize");
372 ipv6_value_ = ipv4_value_;
377 ipv4_value_type ipv4_value_;
378 ipv6_value_type ipv6_value_;
382 template <
int IPv4_Level,
int IPv4_Name,
int IPv6_Level,
int IPv6_Name>
398 if (multicast_address.
is_v6())
403 memcpy(ipv6_value_.ipv6mr_multiaddr.s6_addr, bytes.data(), 16);
404 ipv6_value_.ipv6mr_interface = ipv6_address.
scope_id();
408 ipv4_value_.imr_multiaddr.s_addr =
411 ipv4_value_.imr_interface.s_addr =
424 ipv4_value_.imr_multiaddr.s_addr =
427 ipv4_value_.imr_interface.s_addr =
441 memcpy(ipv6_value_.ipv6mr_multiaddr.s6_addr, bytes.data(), 16);
445 ipv6_value_.ipv6mr_interface = multicast_address.
scope_id();
449 template <
typename Protocol>
450 int level(
const Protocol& protocol)
const 452 if (protocol.family() == PF_INET6)
458 template <
typename Protocol>
459 int name(
const Protocol& protocol)
const 461 if (protocol.family() == PF_INET6)
467 template <
typename Protocol>
468 const void*
data(
const Protocol& protocol)
const 470 if (protocol.family() == PF_INET6)
476 template <
typename Protocol>
477 std::size_t
size(
const Protocol& protocol)
const 479 if (protocol.family() == PF_INET6)
480 return sizeof(ipv6_value_);
481 return sizeof(ipv4_value_);
490 template <
int IPv4_Level,
int IPv4_Name,
int IPv6_Level,
int IPv6_Name>
518 ipv6_value_ = ipv6_interface;
522 template <
typename Protocol>
523 int level(
const Protocol& protocol)
const 525 if (protocol.family() == PF_INET6)
531 template <
typename Protocol>
532 int name(
const Protocol& protocol)
const 534 if (protocol.family() == PF_INET6)
540 template <
typename Protocol>
541 const void*
data(
const Protocol& protocol)
const 543 if (protocol.family() == PF_INET6)
549 template <
typename Protocol>
550 std::size_t
size(
const Protocol& protocol)
const 552 if (protocol.family() == PF_INET6)
553 return sizeof(ipv6_value_);
554 return sizeof(ipv4_value_);
559 unsigned int ipv6_value_;
569 #endif // ASIO_IP_DETAIL_SOCKET_OPTION_HPP
multicast_request(const asio::ip::address &multicast_address)
multicast_enable_loopback()
int name(const Protocol &protocol) const
int * data(const Protocol &)
void * data(const Protocol &protocol)
multicast_request(const asio::ip::address_v6 &multicast_address, unsigned long network_interface=0)
std::size_t size(const Protocol &) const
const void * data(const Protocol &protocol) const
const void * data(const Protocol &protocol) const
multicast_enable_loopback & operator=(bool v)
unicast_hops & operator=(int v)
ASIO_DECL unsigned long to_ulong() const
Get the address as an unsigned long in host byte order.
int name(const Protocol &protocol) const
int level(const Protocol &protocol) const
std::size_t size(const Protocol &protocol) const
Implements IP version 4 style addresses.
const int * data(const Protocol &) const
int level(const Protocol &protocol) const
void resize(const Protocol &protocol, std::size_t s)
int name(const Protocol &protocol) const
int level(const Protocol &protocol) const
network_interface(const asio::ip::address_v4 &ipv4_interface)
unsigned char ipv4_value_type
void resize(const Protocol &, std::size_t s)
ASIO_DECL asio::ip::address_v6 to_v6() const
Get the address as an IP version 6 address.
multicast_hops & operator=(int v)
ASIO_DECL bytes_type to_bytes() const
Get the address in bytes, in network byte order.
ASIO_DECL asio::ip::address_v4 to_v4() const
Get the address as an IP version 4 address.
const void * data(const Protocol &protocol) const
void resize(const Protocol &protocol, std::size_t s)
u_long_type host_to_network_long(u_long_type value)
std::size_t size(const Protocol &protocol) const
Implements version-independent IP addresses.
multicast_enable_loopback(bool v)
unsigned long scope_id() const
The scope ID of the address.
int name(const Protocol &protocol) const
Implements IP version 6 style addresses.
network_interface(unsigned int ipv6_interface)
std::size_t size(const Protocol &protocol) const
const void * data(const Protocol &protocol) const
bool is_v6() const
Get whether the address is an IP version 6 address.
multicast_request(const asio::ip::address_v4 &multicast_address, const asio::ip::address_v4 &network_interface=asio::ip::address_v4::any())
int level(const Protocol &protocol) const
int name(const Protocol &protocol) const
static address_v4 any()
Obtain an address object that represents any address.
void throw_exception(const Exception &e)
std::size_t size(const Protocol &protocol) const
void * data(const Protocol &protocol)
int level(const Protocol &protocol) const