<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hamza  Ammar on Medium]]></title>
        <description><![CDATA[Stories by Hamza  Ammar on Medium]]></description>
        <link>https://medium.com/@hamza.99.ammar?source=rss-95845c28c21d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2erPwcEF069YWPovYzsfhA.png</url>
            <title>Stories by Hamza  Ammar on Medium</title>
            <link>https://medium.com/@hamza.99.ammar?source=rss-95845c28c21d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 05:40:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hamza.99.ammar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Why Most Mac Network Monitors Lie to You — And How I Fixed It With Swift]]></title>
            <link>https://medium.com/@hamza.99.ammar/why-most-mac-network-monitors-lie-to-you-and-how-i-fixed-it-with-swift-339b1d0fe894?source=rss-95845c28c21d------2</link>
            <guid isPermaLink="false">https://medium.com/p/339b1d0fe894</guid>
            <category><![CDATA[control-center]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[network-monitoring]]></category>
            <dc:creator><![CDATA[Hamza  Ammar]]></dc:creator>
            <pubDate>Wed, 23 Sep 2026 12:49:56 GMT</pubDate>
            <atom:updated>2026-09-23T12:49:56.176Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Solving the VPN double-counting problem with a lightweight, zero-permission macOS menu bar app.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Ob494qhoM3YYUpEQ.png" /><figcaption><em>NetHUD: Lightweight menu bar network speed readout for macOS</em></figcaption></figure><p>Like many developers and Mac power users, I like keeping an eye on my active bandwidth in real time. Whether downloading a massive Docker image, pushing a Git branch, streaming video, or debugging an unstable connection, knowing immediately whether your network is stalling or saturated is essential.</p><p>However, nearly all existing macOS network monitors have one of three major drawbacks:</p><ul><li><strong>1. Heavy Footprint &amp; Telemetry:</strong> Many are packed with background daemons, closed-source analytics, or bundled with heavy Electron runtimes that chew through RAM and battery.</li><li><strong>2. Invasive Permissions:</strong> Requiring root/sudo privileges or full Network Extension access just to read basic hardware packet counters.</li><li><strong>3. The VPN Double-Counting Flaw:</strong> When connecting to a VPN (WireGuard, OpenVPN, Tailscale), naive monitors blindly sum up all interfaces. This counts both your physical Wi-Fi (en0) and your virtual tunnel (utun*), reporting double your actual speed!</li></ul><p>I wanted something clean, native, battery-friendly, and unobtrusive that lives quietly in the menu bar. So, I built and open-sourced <strong>NetHUD</strong>.</p><h3>✨ What Makes NetHUD Different?</h3><ul><li><strong>Always Visible:</strong> Displays live upload and download speeds directly in your menu bar (e.g. ↑12 KB/s ↓1.2 MB/s).</li><li><strong>Zero Permissions:</strong> Reads operating system byte counters via BSD’s getifaddrs(). No root permissions, no Network Extensions, and zero external dependencies.</li><li><strong>Smart Primary Interface Tracking:</strong> Follows the kernel routing table’s default gateway. When a VPN is active, it tracks the tunnel interface, preventing traffic from being counted twice.</li><li><strong>Sleep &amp; Wake Aware:</strong> Automatically re-baselines counters when your Mac wakes from sleep, eliminating fake multi-gigabyte speed spikes.</li><li><strong>Rollover Resilient:</strong> Properly accounts for Darwin’s 32-bit unsigned counter rollover at the 4.29 GB boundary.</li><li><strong>100% Private:</strong> Zero telemetry, zero analytics, completely offline, and licensed under the MIT license.</li></ul><h3>🎨 Five Menu Bar Themes (Notch-Friendly)</h3><p>Mac menu bars can get crowded quickly, especially on modern MacBooks with the camera notch. NetHUD ships with five built-in themes to fit any setup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1ocqtDK5dVIneyyB.png" /><figcaption>Five built-in menu bar themes for NetHUD</figcaption></figure><ul><li><strong>Classic:</strong> ↑12 KB/s ↓1.2 MB/s — standard balanced layout.</li><li><strong>Compact:</strong> ↑12K ↓1.2M — ultra-compact units designed specifically to save space around the MacBook notch.</li><li><strong>Vivid:</strong> Classic layout with distinctive green upload (↑) and blue download (↓) directional arrows.</li><li><strong>Vivid Compact:</strong> Minified units combined with colored arrows.</li><li><strong>Zen:</strong> ↓1.2M — download speed only, ideal for minimalists.</li></ul><h3>Zero-Jitter Typography</h3><p>A common annoyance with menu bar indicators is jitter: when speeds alternate between 9 KB/s and 999 KB/s, adjacent menu bar icons shift left and right repeatedly. NetHUD uses fixed-width monospaced formatting so your menu bar layout stays perfectly stable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/860/0*2iIgObDotjE1tJ-k.png" /><figcaption>NetHUD in the macOS Menu Bar (Dark Mode)</figcaption></figure><h3>🔍 Deep Inspection Popover</h3><p>Clicking the menu bar item opens a clean SwiftUI popover detailing current interface statistics:</p><ul><li>Shows the current primary interface (e.g. en0 on Wi-Fi, utun3 on VPN).</li><li>Per-interface speed breakdown across all physical and virtual interfaces.</li><li>Session totals: cumulative downloaded and uploaded data since app launch.</li><li>Configurable refresh rate: switch between 0.5s, 1.0s, or 2.0s polling.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/0*kwDHdOyI-vVgmI0p.png" /><figcaption>Detailed interface breakdown and settings popover</figcaption></figure><h3>🛠 Under the Hood: Solving the Hard macOS Edge Cases</h3><h3>1. The VPN Routing &amp; Double-Counting Problem</h3><p>When you connect to a VPN on macOS, your operating system creates a virtual tunnel interface (such as utun3). If you download a 100 MB file, two things occur:</p><ul><li>The unencrypted payload flows through utun3.</li><li>The encrypted UDP packets flow out of en0 (Wi-Fi).</li></ul><p>If an application simply iterates over all network interfaces and sums their speeds, it reports 200 MB/s! NetHUD avoids this by resolving the BSD routing socket via /sbin/route -n get default asynchronously on a background utility queue:</p><pre>/// /sbin/route runs off the main thread so its ~5–20 ms never hitches the UI.<br>private let routeQueue = DispatchQueue(label: &quot;personal.hamza.nethud.route&quot;, qos: .utility)</pre><pre>// When a VPN tunnel owns the default gateway, NetHUD locks onto it as primary.<br>// Loopback &amp; peer-to-peer interfaces (lo0, awdl0, llw0, anpi0) are ignored.</pre><h3>2. Handling Darwin’s 32-Bit Counter Rollover</h3><p>macOS network byte counters provided through if_data in getifaddrs() are 32-bit unsigned integers. This means they roll over to zero every 4,294,967,296 bytes (~4.29 GB). Without explicit rollover handling, high-speed downloads cause sudden negative deltas or absurd spike values. NetHUD gracefully detects and corrects for this:</p><pre>private let counterWrap = UInt64(UInt32.max) + 1</pre><pre>if current &lt; previous {<br>    // Counter wrapped around 32-bit boundary<br>    delta = (current + counterWrap) - previous<br>} else {<br>    delta = current - previous<br>}</pre><h3>3. Sleep &amp; Wake Re-baselining</h3><p>If a user closes their MacBook lid for several hours, the time delta becomes thousands of seconds, which could corrupt the rate calculation or cause a false speed spike immediately upon wake. NetHUD listens for NSWorkspace.didWakeNotification and resets its sample baseline, ensuring the first post-sleep reading is 100% accurate.</p><h3>🚀 Installing NetHUD</h3><p>NetHUD is 100% free, lightweight, and open source under the MIT license.</p><h3>Method 1: Install via Homebrew</h3><pre>brew install --cask HamzaSamirAmmar/tap/nethud<br>xattr -d com.apple.quarantine /Applications/NetHUD.app</pre><h3>Method 2: Download Direct Binary</h3><p>Head over to the <a href="https://github.com/HamzaSamirAmmar/nethud/releases">GitHub Releases</a> page, download NetHUD.zip, extract it, and drag NetHUD.app into your /Applications folder.</p><h3>Method 3: Build from Source</h3><pre>git clone https://github.com/HamzaSamirAmmar/nethud.git<br>cd nethud<br>xcodegen generate<br>xcodebuild -project NetHUD.xcodeproj -scheme NetHUD -configuration Release   -derivedDataPath build SYMROOT=build/Release build<br>cp -R build/Release/Release/NetHUD.app /Applications/</pre><h3>🤝 Getting Involved</h3><p>NetHUD is written in pure Swift 5.9 and supports macOS 13+ (Ventura, Sonoma, and Sequoia). If you enjoy native macOS utilities or want to suggest new themes, feel free to submit issues, pull requests, or star the project on GitHub!</p><p>🔗 <strong>GitHub Repository:</strong> <a href="https://github.com/HamzaSamirAmmar/nethud">https://github.com/HamzaSamirAmmar/nethud</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=339b1d0fe894" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>