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 {
1932
1932
///
1933
1933
/// [`set_only_v6`]: Socket::set_only_v6
1934
1934
pub fn only_v6 ( & self ) -> io:: Result < bool > {
1935
+ #[ cfg( not( windows) ) ]
1935
1936
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 )
1937
1938
. map ( |only_v6| only_v6 != 0 )
1938
1939
}
1940
+ #[ cfg( windows) ]
1941
+ sys:: only_v6 ( self . as_raw ( ) )
1939
1942
}
1940
1943
1941
1944
/// 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(
892
892
}
893
893
}
894
894
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
+
895
915
#[ cfg( feature = "all" ) ]
896
916
pub ( crate ) fn original_dst_v4 ( socket : RawSocket ) -> io:: Result < SockAddr > {
897
917
unsafe {
You can’t perform that action at this time.
0 commit comments