@@ -175,10 +175,22 @@ impl SocketAddrV6 {
175175 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
176176 pub fn flowinfo ( & self ) -> u32 { ntoh ( self . inner . sin6_flowinfo ) }
177177
178+ /// Change the flow information associated with this socket address.
179+ #[ unstable( feature = "sockaddr_setters" , reason = "recent addition" , issue = "31572" ) ]
180+ pub fn set_flowinfo ( & mut self , new_flowinfo : u32 ) {
181+ self . inner . sin6_flowinfo = hton ( new_flowinfo)
182+ }
183+
178184 /// Returns the scope ID associated with this address,
179185 /// corresponding to the `sin6_scope_id` field in C.
180186 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
181187 pub fn scope_id ( & self ) -> u32 { ntoh ( self . inner . sin6_scope_id ) }
188+
189+ /// Change the scope ID associated with this socket address.
190+ #[ unstable( feature = "sockaddr_setters" , reason = "recent addition" , issue = "31572" ) ]
191+ pub fn set_scope_id ( & mut self , new_scope_id : u32 ) {
192+ self . inner . sin6_scope_id = hton ( new_scope_id)
193+ }
182194}
183195
184196impl FromInner < c:: sockaddr_in > for SocketAddrV4 {
@@ -593,4 +605,20 @@ mod tests {
593605 addr. set_port ( 8080 ) ;
594606 assert_eq ! ( addr. port( ) , 8080 ) ;
595607 }
608+
609+ #[ test]
610+ fn set_flowinfo ( ) {
611+ let mut v6 = SocketAddrV6 :: new ( Ipv6Addr :: new ( 0x2a02 , 0x6b8 , 0 , 1 , 0 , 0 , 0 , 1 ) , 80 , 10 , 0 ) ;
612+ assert_eq ! ( v6. flowinfo( ) , 10 ) ;
613+ v6. set_flowinfo ( 20 ) ;
614+ assert_eq ! ( v6. flowinfo( ) , 20 ) ;
615+ }
616+
617+ #[ test]
618+ fn set_scope_id ( ) {
619+ let mut v6 = SocketAddrV6 :: new ( Ipv6Addr :: new ( 0x2a02 , 0x6b8 , 0 , 1 , 0 , 0 , 0 , 1 ) , 80 , 0 , 10 ) ;
620+ assert_eq ! ( v6. scope_id( ) , 10 ) ;
621+ v6. set_scope_id ( 20 ) ;
622+ assert_eq ! ( v6. scope_id( ) , 20 ) ;
623+ }
596624}
0 commit comments