Skip to content
Merged
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 src/iperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ struct iperf_interval_results
#if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) && \
defined(TCP_INFO)
struct tcp_info tcpInfo; /* getsockopt(TCP_INFO) for Linux, {Free,Net,Open}BSD */
#elif (defined(__APPLE__) && defined(__MACH__)) && defined(TCP_CONNECTION_INFO)
Comment thread
bucweat marked this conversation as resolved.
struct tcp_connection_info tcpConnInfo;
#else
/* Just placeholders, never accessed. */
char *tcpInfo;
Expand Down
30 changes: 30 additions & 0 deletions src/tcp_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ has_tcpinfo(void)
#if (defined(linux) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)) \
&& defined(TCP_INFO)
return 1;
#elif (defined(__APPLE__) && defined(__MACH__)) && defined(TCP_CONNECTION_INFO)
return 1;
#else
return 0;
#endif
Expand All @@ -84,6 +86,8 @@ has_tcpinfo_retransmits(void)
return 1; /* Should work now */
#elif (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(TCP_INFO)
return 1;
#elif (defined(__APPLE__) && defined(__MACH__)) && defined(TCP_CONNECTION_INFO)
return 1;
#else
return 0;
#endif
Expand All @@ -107,6 +111,19 @@ save_tcpinfo(struct iperf_stream *sp, struct iperf_interval_results *irp)
irp->tcpInfo.tcpi_rtt);
}

#elif (defined(__APPLE__) && defined(__MACH__)) && defined(TCP_CONNECTION_INFO)
struct tcp_connection_info conn_info;
socklen_t tcp_info_length = sizeof(conn_info );

if (getsockopt(sp->socket, IPPROTO_TCP, TCP_CONNECTION_INFO, (void *)&irp->tcpConnInfo, &tcp_info_length) < 0)
iperf_err(sp->test, "getsockopt - %s", strerror(errno));

if (sp->test->debug) {
printf("tcpi_snd_cwnd %u tcpi_snd_cwnd %u tcpi_srtt %u\n",
irp->tcpConnInfo.tcpi_snd_cwnd, irp->tcpConnInfo.tcpi_snd_cwnd,
irp->tcpConnInfo.tcpi_srtt);
}

#endif
}

Expand All @@ -120,6 +137,8 @@ get_total_retransmits(struct iperf_interval_results *irp)
return irp->tcpInfo.tcpi_snd_rexmitpack;
#elif (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(TCP_INFO)
return irp->tcpInfo.tcpi_snd_rexmitpack;
#elif (defined(__APPLE__) && defined(__MACH__)) && defined(TCP_CONNECTION_INFO)
return irp->tcpConnInfo.tcpi_txretransmitpackets;
#else
return -1;
#endif
Expand All @@ -140,6 +159,8 @@ get_snd_cwnd(struct iperf_interval_results *irp)
return (long)irp->tcpInfo.tcpi_snd_cwnd * irp->tcpInfo.tcpi_snd_mss;
#elif defined(__OpenBSD__) && defined(TCP_INFO)
return irp->tcpInfo.tcpi_snd_cwnd;
#elif (defined(__APPLE__) && defined(__MACH__)) && defined(TCP_CONNECTION_INFO)
return irp->tcpConnInfo.tcpi_snd_cwnd;
#else
return -1;
#endif
Expand All @@ -162,6 +183,8 @@ get_snd_wnd(struct iperf_interval_results *irp)
return (long)irp->tcpInfo.tcpi_snd_wnd * irp->tcpInfo.tcpi_snd_mss;
#elif defined(__OpenBSD__) && defined(TCP_INFO)
return irp->tcpInfo.tcpi_snd_wnd;
#elif (defined(__APPLE__) && defined(__MACH__)) && defined(TCP_CONNECTION_INFO)
return irp->tcpConnInfo.tcpi_snd_wnd;
#else
return -1;
#endif
Expand All @@ -180,6 +203,11 @@ get_rtt(struct iperf_interval_results *irp)
return irp->tcpInfo.tcpi_rtt;
#elif (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(TCP_INFO)
return irp->tcpInfo.tcpi_rtt;
#elif (defined(__APPLE__) && defined(__MACH__)) && defined(TCP_CONNECTION_INFO)
// Linux's tcpi_rtt is a smoothed average,
// macOS's tcp_connection_info explicitly separates the smoothed average (tcpi_srtt)
// from the most recently measured RTT (tcpi_rttcur).
return irp->tcpConnInfo.tcpi_srtt;
#else
return -1;
#endif
Expand All @@ -198,6 +226,8 @@ get_rttvar(struct iperf_interval_results *irp)
return irp->tcpInfo.tcpi_rttvar;
#elif (defined(__NetBSD__) || defined(__OpenBSD__)) && defined(TCP_INFO)
return irp->tcpInfo.tcpi_rttvar;
#elif (defined(__APPLE__) && defined(__MACH__)) && defined(TCP_CONNECTION_INFO)
return irp->tcpConnInfo.tcpi_rttvar;
#else
return -1;
#endif
Expand Down