Open ksa-real opened 10 months ago
Mac doesn't have TCP_INFO defined so this would need to use TCP_CONNECTION_INFO. I have tested with just that modification and while it will now compile, the test exists immediately. I am probably still missing something, but i'm optimistic i'm on the right track because you can see in the output below that the test did report the tcp information before exiting.
I accomplished this by changing the cfg attribute for fn tcp_info on tcp.rs:320 to target the os specifically instead of just unix family and provided a new implementation for mac.
#[cfg(target_os = "linux")]
pub fn tcp_info(sck: &Socket) -> io::Result<TcpInfo> {
let mut payload = TcpInfo::default();
let payload_ptr: *mut TcpInfo = &mut payload;
let mut len = size_of::<TcpInfo>() as libc::socklen_t;
syscall!(getsockopt(
sck.as_raw_fd(),
libc::IPPROTO_TCP,
libc::TCP_INFO,
payload_ptr.cast(),
&mut len,
))
.map(|_| payload.clone())
}
#[cfg(target_os = "macos")]
pub fn tcp_info(sck: &Socket) -> io::Result<TcpInfo> {
let mut payload = TcpInfo::default();
let payload_ptr: *mut TcpInfo = &mut payload;
let mut len = size_of::<TcpInfo>() as libc::socklen_t;
syscall!(getsockopt(
sck.as_raw_fd(),
libc::IPPROTO_TCP,
libc::TCP_CONNECTION_INFO,
payload_ptr.cast(),
&mut len,
))
.map(|_| payload.clone())
}
==========================================
Server listening on 127.0.0.1:8080
==========================================
Accepted ctrl connection from 127.0.0.1:54953
[ 7] local 127.0.0.1:8080, peer 127.0.0.1:54954 sndbuf 146988 rcvbuf 408300 mss 16332
Starting Test: protocol: TCP, 1 streams, 131072 byte blocks, 10 seconds test
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[ FD] Time Transfer Rate
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - Results Per Stream- - - - - - - - - - - - - - - -
[ 7] 0s 0.0 bits/sec receiver
- - - - - - - - - - - - - - - All Streams - - - - - - - - - - - - - - - - -
[Sum] 0s 0.0 bits/sec receiver
Not sure if this is expected but I failed to install nparse on MacOS (Sonoma 14.2.1, M1 Max)
Fresh rust / cargo install with
curl https://sh.rustup.rs -sSf | sh