From 3de820ee7912f46761ca4f0c50f67164aaa5f42f Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Thu, 11 Feb 2016 15:36:10 +0100 Subject: [PATCH] Add SocketAddrV6::set_flowinfo and set_scope_id --- src/libstd/net/addr.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs index 296cd276ddbf..89c51c708435 100644 --- a/src/libstd/net/addr.rs +++ b/src/libstd/net/addr.rs @@ -175,10 +175,22 @@ impl SocketAddrV6 { #[stable(feature = "rust1", since = "1.0.0")] pub fn flowinfo(&self) -> u32 { ntoh(self.inner.sin6_flowinfo) } + /// Change the flow information associated with this socket address. + #[unstable(feature = "sockaddr_setters", reason = "recent addition", issue = "31572")] + pub fn set_flowinfo(&mut self, new_flowinfo: u32) { + self.inner.sin6_flowinfo = hton(new_flowinfo) + } + /// Returns the scope ID associated with this address, /// corresponding to the `sin6_scope_id` field in C. #[stable(feature = "rust1", since = "1.0.0")] pub fn scope_id(&self) -> u32 { ntoh(self.inner.sin6_scope_id) } + + /// Change the scope ID associated with this socket address. + #[unstable(feature = "sockaddr_setters", reason = "recent addition", issue = "31572")] + pub fn set_scope_id(&mut self, new_scope_id: u32) { + self.inner.sin6_scope_id = hton(new_scope_id) + } } impl FromInner for SocketAddrV4 { @@ -593,4 +605,20 @@ mod tests { addr.set_port(8080); assert_eq!(addr.port(), 8080); } + + #[test] + fn set_flowinfo() { + let mut v6 = SocketAddrV6::new(Ipv6Addr::new(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), 80, 10, 0); + assert_eq!(v6.flowinfo(), 10); + v6.set_flowinfo(20); + assert_eq!(v6.flowinfo(), 20); + } + + #[test] + fn set_scope_id() { + let mut v6 = SocketAddrV6::new(Ipv6Addr::new(0x2a02, 0x6b8, 0, 1, 0, 0, 0, 1), 80, 0, 10); + assert_eq!(v6.scope_id(), 10); + v6.set_scope_id(20); + assert_eq!(v6.scope_id(), 20); + } }