diff --git a/2691.added.md b/2691.added.md new file mode 100644 index 0000000000..24d42c1669 --- /dev/null +++ b/2691.added.md @@ -0,0 +1 @@ +Added TCP_INFO for `getsockopt` diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index 49b305920f..193a93a5b0 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -1308,6 +1308,15 @@ sockopt_impl!( libc::SO_ATTACH_REUSEPORT_CBPF, libc::sock_fprog ); +#[cfg(target_os = "linux")] +sockopt_impl!( + /// Used to collect information about this socket. + TcpInfo, + GetOnly, + libc::SOL_TCP, + libc::TCP_INFO, + libc::tcp_info +); #[allow(missing_docs)] // Not documented by Linux! diff --git a/test/sys/test_sockopt.rs b/test/sys/test_sockopt.rs index 87ad72a953..c9094b275e 100644 --- a/test/sys/test_sockopt.rs +++ b/test/sys/test_sockopt.rs @@ -1270,3 +1270,16 @@ pub fn test_so_attach_reuseport_cbpf() { assert_eq!(e, nix::errno::Errno::ENOPROTOOPT); }); } + +#[cfg(target_os = "linux")] +#[test] +pub fn test_so_tcp_info() { + let fd = socket( + AddressFamily::Inet6, + SockType::Stream, + SockFlag::empty(), + SockProtocol::Tcp, + ) + .unwrap(); + getsockopt(&fd, sockopt::TcpInfo).unwrap(); +}