File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -1932,10 +1932,13 @@ impl Socket {
19321932 ///
19331933 /// [`set_only_v6`]: Socket::set_only_v6
19341934 pub fn only_v6 ( & self ) -> io:: Result < bool > {
1935+ #[ cfg( not( windows) ) ]
19351936 unsafe {
1936- getsockopt :: < c_int > ( self . as_raw ( ) , sys:: IPPROTO_IPV6 , sys:: IPV6_V6ONLY )
1937+ getsockopt :: < Bool > ( self . as_raw ( ) , sys:: IPPROTO_IPV6 , sys:: IPV6_V6ONLY )
19371938 . map ( |only_v6| only_v6 != 0 )
19381939 }
1940+ #[ cfg( windows) ]
1941+ sys:: only_v6 ( self . as_raw ( ) )
19391942 }
19401943
19411944 /// Set the value for the `IPV6_V6ONLY` option on this socket.
Original file line number Diff line number Diff line change @@ -892,6 +892,26 @@ pub(crate) fn to_mreqn(
892892 }
893893}
894894
895+ pub ( crate ) fn only_v6 ( socket : RawSocket ) -> io:: Result < bool > {
896+ let mut optval: c_int = 0 ; // input must be 4 bytes (DWORD)
897+ let mut optlen = mem:: size_of_val ( & optval) as c_int ;
898+ syscall ! (
899+ getsockopt(
900+ socket,
901+ IPPROTO_IPV6 as i32 ,
902+ IPV6_V6ONLY ,
903+ ptr:: from( & mut optval) . cast( ) ,
904+ & mut optlen,
905+ ) ,
906+ PartialEq :: eq,
907+ SOCKET_ERROR
908+ )
909+ . map ( |_| {
910+ // optlen may be 1, which won't match the input size of optval
911+ optval != 0
912+ } )
913+ }
914+
895915#[ cfg( feature = "all" ) ]
896916pub ( crate ) fn original_dst_v4 ( socket : RawSocket ) -> io:: Result < SockAddr > {
897917 unsafe {
You can’t perform that action at this time.
0 commit comments