@@ -179,7 +179,7 @@ pub(crate) use libc::SO_LINGER;
179179) ) ]
180180pub ( crate ) use libc:: SO_LINGER_SEC as SO_LINGER ;
181181#[ cfg( target_os = "linux" ) ]
182- pub ( crate ) use libc:: SO_PASSCRED ;
182+ pub ( crate ) use libc:: { SO_PASSCRED , SOL_UDP , UDP_GRO } ;
183183pub ( crate ) use libc:: {
184184 ip_mreq as IpMreq , linger, IPPROTO_IP , IPPROTO_IPV6 , IPV6_MULTICAST_HOPS , IPV6_MULTICAST_IF ,
185185 IPV6_MULTICAST_LOOP , IPV6_UNICAST_HOPS , IPV6_V6ONLY , IP_ADD_MEMBERSHIP , IP_DROP_MEMBERSHIP ,
@@ -896,6 +896,44 @@ impl SockAddr {
896896 #[ cfg( not( any( target_os = "linux" , target_os = "android" ) ) ) ]
897897 None
898898 }
899+
900+ /// Get the value of the `UDP_GRO` option on this socket.
901+ ///
902+ /// For more information about this option, see [`set_udp_gro`].
903+ ///
904+ /// [`set_udp_gro`]: Socket::set_udp_gro
905+ #[ cfg( all( feature = "all" , any( target_os = "android" , target_os = "linux" ) ) ) ]
906+ #[ cfg_attr(
907+ docsrs,
908+ doc( cfg( all( feature = "all" , any( target_os = "android" , target_os = "linux" ) ) ) )
909+ ) ]
910+ pub fn udp_gro ( & self ) -> io:: Result < bool > {
911+ unsafe {
912+ getsockopt :: < c_int > ( self . as_raw ( ) , sys:: SOL_UDP , sys:: UDP_GRO )
913+ . map ( |reuse| reuse != 0 )
914+ }
915+ }
916+
917+ /// Set value for the `UDP_GRO` option on this socket.
918+ ///
919+ /// This indicates that the kernel can combine multiple datagrams into a
920+ /// single buffer, this needs to be used in combination with [`Self::recvmsg`]
921+ /// to get the number of segments in the buffer from the [`MsgHdr`].
922+ #[ cfg( all( feature = "all" , any( target_os = "android" , target_os = "linux" ) ) ) ]
923+ #[ cfg_attr(
924+ docsrs,
925+ doc( cfg( all( feature = "all" , any( target_os = "android" , target_os = "linux" ) ) ) )
926+ ) ]
927+ pub fn set_udp_gro ( & self , reuse : bool ) -> io:: Result < ( ) > {
928+ unsafe {
929+ setsockopt (
930+ self . as_raw ( ) ,
931+ sys:: SOL_UDP ,
932+ sys:: UDP_GRO ,
933+ reuse as c_int ,
934+ )
935+ }
936+ }
899937}
900938
901939pub ( crate ) type Socket = c_int ;
0 commit comments