Repository navigation
Estimate macOS TCP segments sent from IP packets sent, not delivered - #3822
Conversation
Without elevated permissions net.inet.tcp.stats reads as zeros on macOS, so getTCPv4Stats() estimates from the IP and UDP totals. The segments-sent estimate subtracted the UDP datagrams sent from ips_delivered, "datagrams delivered to upper level", which counts inbound packets. Use ips_localout, "total ip packets generated here", instead. The offsets come from the macOS SDK's netinet/ip_var.h: ips_delivered is at 56 and ips_localout at 60. Both twins now read offset 60, and require 64 bytes rather than 60. On macOS 26.6.2, unprivileged, the estimate is 252453848: netstat's 258570565 packets sent from this host less 6116717 UDP datagrams output. The old one would have been about 214.7 million.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📜 Recent review details
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3822 +/- ##
============================================
- Coverage 80.99% 80.93% -0.06%
- Complexity 661 722 +61
============================================
Files 725 725
Lines 26148 26148
Branches 4444 4444
============================================
- Hits 21178 21163 -15
- Misses 2758 2771 +13
- Partials 2212 2214 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Follow-up to a finding raised in #3801.
Without elevated permissions, macOS returns zeros from
net.inet.tcp.stats, sogetTCPv4Stats()estimates its counts from the IP and UDP totals. The segments-sent estimate subtracted the UDP datagrams sent fromips_delivered. That field is "datagrams delivered to upper level", an inbound count.Change
The estimate now uses
ips_localout, "total ip packets generated here", instead ofips_delivered. The offsets come from the macOS SDK'snetinet/ip_var.h:ips_deliveredis at 56 andips_localoutat 60. Both twins now read offset 60, and require a 64-byte buffer instead of 60.Verification
On macOS 26.6.2, as an unprivileged user:
netstat: packets sent from this hostnetstat: UDP datagrams outputgetSegmentsSent(), aftergetSegmentsSent(), before (delivered less UDP output)There's no TCP figure to compare against directly, because unprivileged
netstat -s -p tcpreports zeros as well.MacInternetProtocolStatsTestruns these counters through the unprivileged path. The full-Paggregate-coveragegate passes on this Mac, including the JNA-vs-FFM comparison tests.Not changed
ips_total) rather than those delivered to this host. On this machine the two differ by about 4,000 in 220 million.getUDPv4Stats()counts both IPv4 and IPv6 datagrams. macOS keeps no per-family UDP datagram counter, so there's nothing to fix there.Summary by CodeRabbit