@@ -41,7 +41,7 @@ const TCP_CA_NAME_MAX: usize = 16;
4141/// `libc::IP_ADD_MEMBERSHIP` and others. Will be passed as the third argument (`option_name`)
4242/// to the `setsockopt` call.
4343/// * Type of the value that you are going to set.
44- /// * Type that implements the `Set` trait for the type from the previous item
44+ /// * Type that implements the `Set` trait for the type from the previous item
4545/// (like `SetBool` for `bool`, `SetUsize` for `usize`, etc.).
4646#[ macro_export]
4747macro_rules! setsockopt_impl {
@@ -248,6 +248,13 @@ macro_rules! sockopt_impl {
248248 $crate:: sys:: socket:: sockopt:: SetOsString ) ;
249249 } ;
250250
251+ ( $( #[ $attr: meta] ) * $name: ident, GetOnly , $level: expr, $flag: path,
252+ OsString <$array: ty>) =>
253+ {
254+ sockopt_impl!( $( #[ $attr] ) *
255+ $name, GetOnly , $level, $flag, std:: ffi:: OsString , $crate:: sys:: socket:: sockopt:: GetOsString <$array>) ;
256+ } ;
257+
251258 /*
252259 * Matchers with generic getter types must be placed at the end, so
253260 * they'll only match _after_ specialized matchers fail
@@ -364,9 +371,9 @@ sockopt_impl!(
364371sockopt_impl ! (
365372 #[ cfg_attr( docsrs, doc( cfg( feature = "net" ) ) ) ]
366373 /// Used to disable Nagle's algorithm.
367- ///
374+ ///
368375 /// Nagle's algorithm:
369- ///
376+ ///
370377 /// Under most circumstances, TCP sends data when it is presented; when
371378 /// outstanding data has not yet been acknowledged, it gathers small amounts
372379 /// of output to be sent in a single packet once an acknowledgement is
@@ -762,6 +769,40 @@ sockopt_impl!(
762769 libc:: TCP_REPAIR ,
763770 u32
764771) ;
772+ #[ cfg( linux_android) ]
773+ #[ cfg( feature = "net" ) ]
774+ sockopt_impl ! (
775+ #[ cfg_attr( docsrs, doc( cfg( all( feature = "net" , target_os = "linux" ) ) ) ) ]
776+ /// If enabled, the kernel saves a copy of the SYN packet for each
777+ /// accepted connection. The saved packet can be retrieved on the
778+ /// accepted socket via [`TcpSavedSyn`]. Must be set on the listening
779+ /// socket before `accept()` is called.
780+ ///
781+ /// See `tcp(7)` and `TCP_SAVE_SYN` in the Linux kernel documentation.
782+ TcpSaveSyn ,
783+ Both ,
784+ libc:: IPPROTO_TCP ,
785+ libc:: TCP_SAVE_SYN ,
786+ bool
787+ ) ;
788+ /// Maximum size of a saved SYN packet retrieved via [`TcpSavedSyn`]:
789+ /// IPv4/IPv6 header (up to 60 bytes) + TCP header (up to 60 bytes).
790+ #[ cfg( linux_android) ]
791+ pub const TCP_SAVED_SYN_MAX : usize = 120 ;
792+
793+ #[ cfg( linux_android) ]
794+ #[ cfg( feature = "net" ) ]
795+ sockopt_impl ! (
796+ #[ cfg_attr( docsrs, doc( cfg( all( feature = "net" , target_os = "linux" ) ) ) ) ]
797+ /// Retrieves the SYN packet saved by [`TcpSaveSyn`] on the listening
798+ /// socket. Returns the raw IP + TCP headers from the client's initial SYN
799+ /// as bytes. Returns an empty value if no SYN was saved.
800+ TcpSavedSyn ,
801+ GetOnly ,
802+ libc:: IPPROTO_TCP ,
803+ libc:: TCP_SAVED_SYN ,
804+ OsString <[ u8 ; TCP_SAVED_SYN_MAX ] >
805+ ) ;
765806#[ cfg( not( any(
766807 target_os = "openbsd" ,
767808 target_os = "haiku" ,
@@ -1216,7 +1257,7 @@ sockopt_impl!(
12161257#[ cfg( any( linux_android, target_os = "freebsd" ) ) ]
12171258#[ cfg( feature = "net" ) ]
12181259sockopt_impl ! (
1219- /// Enables a receiving socket to retrieve the Time-to-Live (TTL) field
1260+ /// Enables a receiving socket to retrieve the Time-to-Live (TTL) field
12201261 /// from incoming IPv4 packets.
12211262 Ipv4RecvTtl ,
12221263 Both ,
@@ -1236,7 +1277,7 @@ sockopt_impl!(
12361277#[ cfg( any( linux_android, target_os = "freebsd" ) ) ]
12371278#[ cfg( feature = "net" ) ]
12381279sockopt_impl ! (
1239- /// Enables a receiving socket to retrieve the Hop Limit field
1280+ /// Enables a receiving socket to retrieve the Hop Limit field
12401281 /// (similar to TTL in IPv4) from incoming IPv6 packets.
12411282 Ipv6RecvHopLimit ,
12421283 Both ,
@@ -1268,10 +1309,7 @@ sockopt_impl!(
12681309 libc:: IP_DONTFRAG ,
12691310 bool
12701311) ;
1271- #[ cfg( any(
1272- all( linux_android, not( target_env = "uclibc" ) ) ,
1273- apple_targets
1274- ) ) ]
1312+ #[ cfg( any( all( linux_android, not( target_env = "uclibc" ) ) , apple_targets) ) ]
12751313sockopt_impl ! (
12761314 /// Set "don't fragment packet" flag on the IPv6 packet.
12771315 Ipv6DontFrag ,
@@ -1850,7 +1888,6 @@ impl<'a> Set<'a, usize> for SetUsize {
18501888 }
18511889}
18521890
1853-
18541891/// Getter for a `OwnedFd` value.
18551892// Hide the docs, because it's an implementation detail of `sockopt_impl!`
18561893#[ doc( hidden) ]
@@ -1900,7 +1937,9 @@ impl<'a> Set<'a, OwnedFd> for SetOwnedFd {
19001937 fn new ( val : & ' a OwnedFd ) -> SetOwnedFd {
19011938 use std:: os:: fd:: AsRawFd ;
19021939
1903- SetOwnedFd { val : val. as_raw_fd ( ) as c_int }
1940+ SetOwnedFd {
1941+ val : val. as_raw_fd ( ) as c_int ,
1942+ }
19041943 }
19051944
19061945 fn ffi_ptr ( & self ) -> * const c_void {
0 commit comments