@@ -442,11 +442,11 @@ impl TcpStream {
442
442
}
443
443
444
444
pub fn peer_addr ( & self ) -> io:: Result < SocketAddr > {
445
- sockname ( |buf, len| unsafe { c:: getpeername ( self . inner . as_raw ( ) , buf, len) } )
445
+ unsafe { sockname ( |buf, len| c:: getpeername ( self . inner . as_raw ( ) , buf, len) ) }
446
446
}
447
447
448
448
pub fn socket_addr ( & self ) -> io:: Result < SocketAddr > {
449
- sockname ( |buf, len| unsafe { c:: getsockname ( self . inner . as_raw ( ) , buf, len) } )
449
+ unsafe { sockname ( |buf, len| c:: getsockname ( self . inner . as_raw ( ) , buf, len) ) }
450
450
}
451
451
452
452
pub fn shutdown ( & self , how : Shutdown ) -> io:: Result < ( ) > {
@@ -474,11 +474,11 @@ impl TcpStream {
474
474
}
475
475
476
476
pub fn set_ttl ( & self , ttl : u32 ) -> io:: Result < ( ) > {
477
- setsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL , ttl as c_int )
477
+ unsafe { setsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL , ttl as c_int ) }
478
478
}
479
479
480
480
pub fn ttl ( & self ) -> io:: Result < u32 > {
481
- let raw: c_int = getsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL ) ?;
481
+ let raw: c_int = unsafe { getsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL ) ? } ;
482
482
Ok ( raw as u32 )
483
483
}
484
484
@@ -545,7 +545,9 @@ impl TcpListener {
545
545
// which allows “socket hijacking”, so we explicitly don't set it here.
546
546
// https://docs.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse
547
547
#[ cfg( not( windows) ) ]
548
- setsockopt ( & sock, c:: SOL_SOCKET , c:: SO_REUSEADDR , 1 as c_int ) ?;
548
+ unsafe {
549
+ setsockopt ( & sock, c:: SOL_SOCKET , c:: SO_REUSEADDR , 1 as c_int ) ?
550
+ } ;
549
551
550
552
// Bind our new socket
551
553
let ( addr, len) = socket_addr_to_c ( addr) ;
@@ -581,7 +583,7 @@ impl TcpListener {
581
583
}
582
584
583
585
pub fn socket_addr ( & self ) -> io:: Result < SocketAddr > {
584
- sockname ( |buf, len| unsafe { c:: getsockname ( self . inner . as_raw ( ) , buf, len) } )
586
+ unsafe { sockname ( |buf, len| c:: getsockname ( self . inner . as_raw ( ) , buf, len) ) }
585
587
}
586
588
587
589
pub fn accept ( & self ) -> io:: Result < ( TcpStream , SocketAddr ) > {
@@ -600,20 +602,20 @@ impl TcpListener {
600
602
}
601
603
602
604
pub fn set_ttl ( & self , ttl : u32 ) -> io:: Result < ( ) > {
603
- setsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL , ttl as c_int )
605
+ unsafe { setsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL , ttl as c_int ) }
604
606
}
605
607
606
608
pub fn ttl ( & self ) -> io:: Result < u32 > {
607
- let raw: c_int = getsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL ) ?;
609
+ let raw: c_int = unsafe { getsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL ) ? } ;
608
610
Ok ( raw as u32 )
609
611
}
610
612
611
613
pub fn set_only_v6 ( & self , only_v6 : bool ) -> io:: Result < ( ) > {
612
- setsockopt ( & self . inner , c:: IPPROTO_IPV6 , c:: IPV6_V6ONLY , only_v6 as c_int )
614
+ unsafe { setsockopt ( & self . inner , c:: IPPROTO_IPV6 , c:: IPV6_V6ONLY , only_v6 as c_int ) }
613
615
}
614
616
615
617
pub fn only_v6 ( & self ) -> io:: Result < bool > {
616
- let raw: c_int = getsockopt ( & self . inner , c:: IPPROTO_IPV6 , c:: IPV6_V6ONLY ) ?;
618
+ let raw: c_int = unsafe { getsockopt ( & self . inner , c:: IPPROTO_IPV6 , c:: IPV6_V6ONLY ) ? } ;
617
619
Ok ( raw != 0 )
618
620
}
619
621
@@ -676,11 +678,11 @@ impl UdpSocket {
676
678
}
677
679
678
680
pub fn peer_addr ( & self ) -> io:: Result < SocketAddr > {
679
- sockname ( |buf, len| unsafe { c:: getpeername ( self . inner . as_raw ( ) , buf, len) } )
681
+ unsafe { sockname ( |buf, len| c:: getpeername ( self . inner . as_raw ( ) , buf, len) ) }
680
682
}
681
683
682
684
pub fn socket_addr ( & self ) -> io:: Result < SocketAddr > {
683
- sockname ( |buf, len| unsafe { c:: getsockname ( self . inner . as_raw ( ) , buf, len) } )
685
+ unsafe { sockname ( |buf, len| c:: getsockname ( self . inner . as_raw ( ) , buf, len) ) }
684
686
}
685
687
686
688
pub fn recv_from ( & self , buf : & mut [ u8 ] ) -> io:: Result < ( usize , SocketAddr ) > {
@@ -728,48 +730,62 @@ impl UdpSocket {
728
730
}
729
731
730
732
pub fn set_broadcast ( & self , broadcast : bool ) -> io:: Result < ( ) > {
731
- setsockopt ( & self . inner , c:: SOL_SOCKET , c:: SO_BROADCAST , broadcast as c_int )
733
+ unsafe { setsockopt ( & self . inner , c:: SOL_SOCKET , c:: SO_BROADCAST , broadcast as c_int ) }
732
734
}
733
735
734
736
pub fn broadcast ( & self ) -> io:: Result < bool > {
735
- let raw: c_int = getsockopt ( & self . inner , c:: SOL_SOCKET , c:: SO_BROADCAST ) ?;
737
+ let raw: c_int = unsafe { getsockopt ( & self . inner , c:: SOL_SOCKET , c:: SO_BROADCAST ) ? } ;
736
738
Ok ( raw != 0 )
737
739
}
738
740
739
741
pub fn set_multicast_loop_v4 ( & self , multicast_loop_v4 : bool ) -> io:: Result < ( ) > {
740
- setsockopt (
741
- & self . inner ,
742
- c:: IPPROTO_IP ,
743
- c:: IP_MULTICAST_LOOP ,
744
- multicast_loop_v4 as IpV4MultiCastType ,
745
- )
742
+ unsafe {
743
+ setsockopt (
744
+ & self . inner ,
745
+ c:: IPPROTO_IP ,
746
+ c:: IP_MULTICAST_LOOP ,
747
+ multicast_loop_v4 as IpV4MultiCastType ,
748
+ )
749
+ }
746
750
}
747
751
748
752
pub fn multicast_loop_v4 ( & self ) -> io:: Result < bool > {
749
- let raw: IpV4MultiCastType = getsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_MULTICAST_LOOP ) ?;
753
+ let raw: IpV4MultiCastType =
754
+ unsafe { getsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_MULTICAST_LOOP ) ? } ;
750
755
Ok ( raw != 0 )
751
756
}
752
757
753
758
pub fn set_multicast_ttl_v4 ( & self , multicast_ttl_v4 : u32 ) -> io:: Result < ( ) > {
754
- setsockopt (
755
- & self . inner ,
756
- c:: IPPROTO_IP ,
757
- c:: IP_MULTICAST_TTL ,
758
- multicast_ttl_v4 as IpV4MultiCastType ,
759
- )
759
+ unsafe {
760
+ setsockopt (
761
+ & self . inner ,
762
+ c:: IPPROTO_IP ,
763
+ c:: IP_MULTICAST_TTL ,
764
+ multicast_ttl_v4 as IpV4MultiCastType ,
765
+ )
766
+ }
760
767
}
761
768
762
769
pub fn multicast_ttl_v4 ( & self ) -> io:: Result < u32 > {
763
- let raw: IpV4MultiCastType = getsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_MULTICAST_TTL ) ?;
770
+ let raw: IpV4MultiCastType =
771
+ unsafe { getsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_MULTICAST_TTL ) ? } ;
764
772
Ok ( raw as u32 )
765
773
}
766
774
767
775
pub fn set_multicast_loop_v6 ( & self , multicast_loop_v6 : bool ) -> io:: Result < ( ) > {
768
- setsockopt ( & self . inner , c:: IPPROTO_IPV6 , c:: IPV6_MULTICAST_LOOP , multicast_loop_v6 as c_int )
776
+ unsafe {
777
+ setsockopt (
778
+ & self . inner ,
779
+ c:: IPPROTO_IPV6 ,
780
+ c:: IPV6_MULTICAST_LOOP ,
781
+ multicast_loop_v6 as c_int ,
782
+ )
783
+ }
769
784
}
770
785
771
786
pub fn multicast_loop_v6 ( & self ) -> io:: Result < bool > {
772
- let raw: c_int = getsockopt ( & self . inner , c:: IPPROTO_IPV6 , c:: IPV6_MULTICAST_LOOP ) ?;
787
+ let raw: c_int =
788
+ unsafe { getsockopt ( & self . inner , c:: IPPROTO_IPV6 , c:: IPV6_MULTICAST_LOOP ) ? } ;
773
789
Ok ( raw != 0 )
774
790
}
775
791
@@ -778,39 +794,39 @@ impl UdpSocket {
778
794
imr_multiaddr : ip_v4_addr_to_c ( multiaddr) ,
779
795
imr_interface : ip_v4_addr_to_c ( interface) ,
780
796
} ;
781
- setsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_ADD_MEMBERSHIP , mreq)
797
+ unsafe { setsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_ADD_MEMBERSHIP , mreq) }
782
798
}
783
799
784
800
pub fn join_multicast_v6 ( & self , multiaddr : & Ipv6Addr , interface : u32 ) -> io:: Result < ( ) > {
785
801
let mreq = c:: ipv6_mreq {
786
802
ipv6mr_multiaddr : ip_v6_addr_to_c ( multiaddr) ,
787
803
ipv6mr_interface : to_ipv6mr_interface ( interface) ,
788
804
} ;
789
- setsockopt ( & self . inner , c:: IPPROTO_IPV6 , IPV6_ADD_MEMBERSHIP , mreq)
805
+ unsafe { setsockopt ( & self . inner , c:: IPPROTO_IPV6 , IPV6_ADD_MEMBERSHIP , mreq) }
790
806
}
791
807
792
808
pub fn leave_multicast_v4 ( & self , multiaddr : & Ipv4Addr , interface : & Ipv4Addr ) -> io:: Result < ( ) > {
793
809
let mreq = c:: ip_mreq {
794
810
imr_multiaddr : ip_v4_addr_to_c ( multiaddr) ,
795
811
imr_interface : ip_v4_addr_to_c ( interface) ,
796
812
} ;
797
- setsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_DROP_MEMBERSHIP , mreq)
813
+ unsafe { setsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_DROP_MEMBERSHIP , mreq) }
798
814
}
799
815
800
816
pub fn leave_multicast_v6 ( & self , multiaddr : & Ipv6Addr , interface : u32 ) -> io:: Result < ( ) > {
801
817
let mreq = c:: ipv6_mreq {
802
818
ipv6mr_multiaddr : ip_v6_addr_to_c ( multiaddr) ,
803
819
ipv6mr_interface : to_ipv6mr_interface ( interface) ,
804
820
} ;
805
- setsockopt ( & self . inner , c:: IPPROTO_IPV6 , IPV6_DROP_MEMBERSHIP , mreq)
821
+ unsafe { setsockopt ( & self . inner , c:: IPPROTO_IPV6 , IPV6_DROP_MEMBERSHIP , mreq) }
806
822
}
807
823
808
824
pub fn set_ttl ( & self , ttl : u32 ) -> io:: Result < ( ) > {
809
- setsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL , ttl as c_int )
825
+ unsafe { setsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL , ttl as c_int ) }
810
826
}
811
827
812
828
pub fn ttl ( & self ) -> io:: Result < u32 > {
813
- let raw: c_int = getsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL ) ?;
829
+ let raw: c_int = unsafe { getsockopt ( & self . inner , c:: IPPROTO_IP , c:: IP_TTL ) ? } ;
814
830
Ok ( raw as u32 )
815
831
}
816
832
0 commit comments