@@ -442,11 +442,11 @@ impl TcpStream {
442442 }
443443
444444 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) ) }
446446 }
447447
448448 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) ) }
450450 }
451451
452452 pub fn shutdown ( & self , how : Shutdown ) -> io:: Result < ( ) > {
@@ -474,11 +474,11 @@ impl TcpStream {
474474 }
475475
476476 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 ) }
478478 }
479479
480480 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 ) ? } ;
482482 Ok ( raw as u32 )
483483 }
484484
@@ -545,7 +545,9 @@ impl TcpListener {
545545 // which allows “socket hijacking”, so we explicitly don't set it here.
546546 // https://docs.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse
547547 #[ 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+ } ;
549551
550552 // Bind our new socket
551553 let ( addr, len) = socket_addr_to_c ( addr) ;
@@ -581,7 +583,7 @@ impl TcpListener {
581583 }
582584
583585 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) ) }
585587 }
586588
587589 pub fn accept ( & self ) -> io:: Result < ( TcpStream , SocketAddr ) > {
@@ -600,20 +602,20 @@ impl TcpListener {
600602 }
601603
602604 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 ) }
604606 }
605607
606608 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 ) ? } ;
608610 Ok ( raw as u32 )
609611 }
610612
611613 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 ) }
613615 }
614616
615617 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 ) ? } ;
617619 Ok ( raw != 0 )
618620 }
619621
@@ -676,11 +678,11 @@ impl UdpSocket {
676678 }
677679
678680 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) ) }
680682 }
681683
682684 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) ) }
684686 }
685687
686688 pub fn recv_from ( & self , buf : & mut [ u8 ] ) -> io:: Result < ( usize , SocketAddr ) > {
@@ -728,48 +730,62 @@ impl UdpSocket {
728730 }
729731
730732 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 ) }
732734 }
733735
734736 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 ) ? } ;
736738 Ok ( raw != 0 )
737739 }
738740
739741 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+ }
746750 }
747751
748752 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 ) ? } ;
750755 Ok ( raw != 0 )
751756 }
752757
753758 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+ }
760767 }
761768
762769 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 ) ? } ;
764772 Ok ( raw as u32 )
765773 }
766774
767775 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+ }
769784 }
770785
771786 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 ) ? } ;
773789 Ok ( raw != 0 )
774790 }
775791
@@ -778,39 +794,39 @@ impl UdpSocket {
778794 imr_multiaddr : ip_v4_addr_to_c ( multiaddr) ,
779795 imr_interface : ip_v4_addr_to_c ( interface) ,
780796 } ;
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) }
782798 }
783799
784800 pub fn join_multicast_v6 ( & self , multiaddr : & Ipv6Addr , interface : u32 ) -> io:: Result < ( ) > {
785801 let mreq = c:: ipv6_mreq {
786802 ipv6mr_multiaddr : ip_v6_addr_to_c ( multiaddr) ,
787803 ipv6mr_interface : to_ipv6mr_interface ( interface) ,
788804 } ;
789- setsockopt ( & self . inner , c:: IPPROTO_IPV6 , IPV6_ADD_MEMBERSHIP , mreq)
805+ unsafe { setsockopt ( & self . inner , c:: IPPROTO_IPV6 , IPV6_ADD_MEMBERSHIP , mreq) }
790806 }
791807
792808 pub fn leave_multicast_v4 ( & self , multiaddr : & Ipv4Addr , interface : & Ipv4Addr ) -> io:: Result < ( ) > {
793809 let mreq = c:: ip_mreq {
794810 imr_multiaddr : ip_v4_addr_to_c ( multiaddr) ,
795811 imr_interface : ip_v4_addr_to_c ( interface) ,
796812 } ;
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) }
798814 }
799815
800816 pub fn leave_multicast_v6 ( & self , multiaddr : & Ipv6Addr , interface : u32 ) -> io:: Result < ( ) > {
801817 let mreq = c:: ipv6_mreq {
802818 ipv6mr_multiaddr : ip_v6_addr_to_c ( multiaddr) ,
803819 ipv6mr_interface : to_ipv6mr_interface ( interface) ,
804820 } ;
805- setsockopt ( & self . inner , c:: IPPROTO_IPV6 , IPV6_DROP_MEMBERSHIP , mreq)
821+ unsafe { setsockopt ( & self . inner , c:: IPPROTO_IPV6 , IPV6_DROP_MEMBERSHIP , mreq) }
806822 }
807823
808824 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 ) }
810826 }
811827
812828 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 ) ? } ;
814830 Ok ( raw as u32 )
815831 }
816832
0 commit comments