From 8004900ce94474498f2f1b5136a16499bd6e28f6 Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sun, 25 Jun 2017 22:56:52 -0700 Subject: [PATCH] Expose only_v6 option for UDP sockets --- src/net/udp/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs index 9befb33fc..50ad8b9a6 100644 --- a/src/net/udp/mod.rs +++ b/src/net/udp/mod.rs @@ -322,6 +322,27 @@ impl UdpSocket { interface: u32) -> io::Result<()> { self.io.get_ref().leave_multicast_v6(multiaddr, interface) } + + /// Sets the value for the `IPV6_V6ONLY` option on this socket. + /// + /// If this is set to `true` then the socket is restricted to sending and + /// receiving IPv6 packets only. In this case two IPv4 and IPv6 applications + /// can bind the same port at the same time. + /// + /// If this is set to `false` then the socket can be used to send and + /// receive packets from an IPv4-mapped IPv6 address. + pub fn set_only_v6(&self, only_v6: bool) -> io::Result<()> { + self.io.get_ref().set_only_v6(only_v6) + } + + /// Gets the value of the `IPV6_V6ONLY` option for this socket. + /// + /// For more information about this option, see [`set_only_v6`][link]. + /// + /// [link]: #method.set_only_v6 + pub fn only_v6(&self) -> io::Result { + self.io.get_ref().only_v6() + } } impl fmt::Debug for UdpSocket {