Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: Get tcp_info structure #2615

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
- Added `SIGINFO` in `::nix::sys::signal` for the _macos_ target as well as
`SIGPWR` and `SIGSTKFLT` in `::nix::sys::signal` for non-_macos_ targets.
([#361](https://github.com/nix-rust/nix/pull/361))
- Added `TCP_INFO` sockopt to read TCP socket information on _linux_.
([#2615](https://github.com/nix-rust/nix/pull/2615))
Comment on lines +1963 to +1964
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


### Changed
- Changed the structure `IoVec` in `::nix::sys::uio`.
Expand Down
11 changes: 11 additions & 0 deletions src/sys/socket/sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,17 @@ sockopt_impl!(
libc::SO_EXCLBIND,
bool
);
#[cfg(target_os = "linux")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there

However, I'd like advice on how to resolve the latter.

If uClibc has that symbol, you can add it to the libc crate. Otherwise, we need to filter it out:

Suggested change
#[cfg(target_os = "linux")]
#[cfg(all(target_os = "linux", not(target_env = "uclibc")))]

#[cfg(feature = "net")]
sockopt_impl!(
#[cfg_attr(docsrs, doc(cfg(feature = "net")))]
/// Get tcp_info structure.
TcpInfo,
GetOnly,
libc::SOL_TCP,
libc::TCP_INFO,
libc::tcp_info
);

#[allow(missing_docs)]
// Not documented by Linux!
Expand Down
17 changes: 17 additions & 0 deletions test/sys/test_sockopt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,23 @@ fn test_ipv6_tclass() {
assert_eq!(getsockopt(&fd, sockopt::Ipv6TClass).unwrap(), class);
}

#[test]
#[cfg(target_os = "linux")]
fn test_tcp_info() {
let fd = socket(
AddressFamily::Inet6,
SockType::Stream,
SockFlag::empty(),
SockProtocol::Tcp,
)
.unwrap();
let tcp_info = getsockopt(&fd, sockopt::TcpInfo).unwrap();
// Silly assert for the sake of having one in the test.
// There should be no retransmits because nothing is sent through the
// socket in the first place.
assert_eq!(tcp_info.tcpi_retransmits, 0);
}

#[test]
#[cfg(target_os = "freebsd")]
fn test_receive_timestamp() {
Expand Down
Loading