about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2016-02-11 15:36:10 +0100
committerSimon Sapin <simon.sapin@exyr.org>2016-02-11 15:36:10 +0100
commit3de820ee7912f46761ca4f0c50f67164aaa5f42f (patch)
treedb5756fe7ce41526608cd8cae6e206098638abda /src/libstd
parent5a249abba720b58bbbd23e8b0f532bd7a6ea61de (diff)
downloadrust-3de820ee7912f46761ca4f0c50f67164aaa5f42f.tar.gz
rust-3de820ee7912f46761ca4f0c50f67164aaa5f42f.zip
Add SocketAddrV6::set_flowinfo and set_scope_id
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/net/addr.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libstd/net/addr.rs b/src/libstd/net/addr.rs
index 296cd276ddb..89c51c70843 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<c::sockaddr_in> 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);
+    }
 }