21 Internet protocol [internet]

21.2 Requirements [internet.reqmts]

21.2.1 Internet protocol requirements [internet.reqmts.protocol]

A type X meets the InternetProtocol requirements if it satisfies the requirements of AcceptableProtocol ([socket.reqmts.acceptableprotocol]), as well as the additional requirements listed below.

In the table below, a and b denote (possibly const) values of type X.

Table 35 — InternetProtocol requirements
expressionreturn typeassertion/note pre/post-conditions
X::resolver ip::basic_resolver<X> The type of a resolver for the protocol.
X::v4() X Returns an object representing the IP version 4 protocol.
X::v6() X Returns an object representing the IP version 6 protocol.
a == b convertible to bool Returns true if a and b represent the same IP protocol version, otherwise false.
a != b convertible to bool Returns !(a == b).

21.2.2 Multicast group socket options [internet.reqmts.opt.mcast]

A type X meets the MulticastGroupSocketOption requirements if it satisfies the requirements of Destructible (C++ 2014 [destructible]), CopyConstructible (C++ 2014 [copyconstructible]), CopyAssignable (C++ 2014 [copyassignable]), and SettableSocketOption ([socket.reqmts.settablesocketoption]), as well as the additional requirements listed below.

In the table below, a denotes a (possibly const) value of type address, b and c denote (possibly const) values of type address_v4, d denotes a (possibly const) value of type address_v6, e denotes a (possibly const) value of type unsigned int, and u denotes an identifier.

Table 36 — MulticastGroupSocketOption requirements
expressiontypeassertion/note pre/post-conditions
X u(a); Constructs a multicast group socket option to join the group with the specified version-independent address.
X u(b, c); Constructs a multicast group socket option to join the specified IPv4 address on a specified network interface.
X u(d, e); Constructs a multicast group socket option to join the specified IPv6 address on a specified network interface.

In this document, types that satisfy the MulticastGroupSocketOption requirements are defined as follows.

class C{
public:
  // constructors:
  explicit C(const address& multicast_group) noexcept;
  explicit C(const address_v4& multicast_group,
             const address_v4& network_interface = address_v4::any()) noexcept;
  explicit C(const address_v6& multicast_group,
             unsigned int network_interface = 0) noexcept;
};

Extensible implementations provide the following member functions:

class C{
public:
  template<class Protocol> int level(const Protocol& p) const noexcept;
  template<class Protocol> int name(const Protocol& p) const noexcept;
  template<class Protocol> const void* data(const Protocol& p) const noexcept;
  template<class Protocol> size_t size(const Protocol& p) const noexcept;
  // remainder unchanged
private:
  ip_mreq v4_value_; // exposition only
  ipv6_mreq v6_value_; // exposition only
};

Let L and N identify the POSIX macros to be passed as the level and option_name arguments, respectively, to POSIX setsockopt and getsockopt.

explicit C(const address& multicast_group) noexcept;

Effects: If multicast_group.is_v6() is true, calls C(multicast_group.to_v6()); otherwise, calls C(multicast_group.to_v4()).

explicit C(const address_v4& multicast_group, const address_v4& network_interface = address_v4::any()) noexcept;

Effects: For extensible implementations, v4_value_.imr_multiaddr is initialized to correspond to the address multicast_group, v4_value_.imr_interface is initialized to correspond to address network_interface, and v6_value_ is zero-initialized.

explicit C(const address_v6& multicast_group, unsigned int network_interface = 0) noexcept;

Effects: For extensible implementations, v6_value_.ipv6mr_multiaddr is initialized to correspond to the address multicast_group, v6_value_.ipv6mr_interface is initialized to network_interface, and v4_value_ is zero-initialized.

template<class Protocol> int level(const Protocol& p) const noexcept;

Returns: L.

template<class Protocol> int name(const Protocol& p) const noexcept;

Returns: N.

template<class Protocol> const void* data(const Protocol& p) const noexcept;

Returns: addressof(v6_value_) if p.family() == AF_INET6, otherwise addressof(v4_value_).

template<class Protocol> size_t size(const Protocol& p) const noexcept;

Returns: sizeof(v6_value_) if p.family() == AF_INET6, otherwise sizeof(v4_value_).