# How Does Fastfetch Detect WiFi Networks? A Deep Dive into the Source Code

> Explore how Fastfetch detects WiFi networks by delving into its source code. Learn about sysfs enumeration, iw command parsing, ioctl calls, and NetworkManager DBus APIs.

- Repository: [fastfetch-cli/fastfetch](https://github.com/fastfetch-cli/fastfetch)
- Tags: deep-dive
- Published: 2026-03-30

---

**Fastfetch detects WiFi networks by enumerating wireless interfaces via sysfs, parsing the `iw` command output or falling back to ioctl calls, and optionally enriching data through NetworkManager DBus APIs.**

The fastfetch-cli/fastfetch repository implements a multi-stage, platform-specific detection pipeline for WiFi information. On Linux systems—the primary implementation—this process involves kernel interface checks, external command parsing, and optional DBus integration to populate the `FFWifiResult` structure.

## Linux WiFi Detection Pipeline

The Linux implementation in [`src/detection/wifi/wifi_linux.c`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/detection/wifi/wifi_linux.c) follows a rigorous detection order: interface validation, operational state verification, primary data extraction, fallback mechanisms, and optional enrichment.

### Interface Enumeration and Validation

The detection process begins in `ffDetectWifi`, which calls `if_nameindex()` to enumerate all network interfaces. For each interface, Fastfetch checks for the presence of `/sys/class/net/<if>/phy80211/`. This directory exists only for wireless interfaces, serving as the definitive hardware classifier.

After identifying a wireless interface, Fastfetch reads `/sys/class/net/<if>/operstate` to verify the interface is administratively up. If the state character is not `'u'`, the interface is recorded as disconnected and excluded from further processing.

### Primary Data Collection with `iw`

For active interfaces, Fastfetch first attempts to gather detailed connection data by executing `iw dev <if> link`. The function `detectWifiWithIw` parses this output for:

- **BSSID**: Extracted from the `"Connected to "` line
- **SSID**: Parsed from `"SSID: "` lines with hex-escaped sequences decoded
- **Signal quality**: Converted from dBm to percentage using the `"signal: "` value
- **Bitrate**: Rx/Tx rates from `"rx bitrate: "` and `"tx bitrate: "` lines to infer WiFi protocol versions (e.g., 802.11ac mapping to WiFi 5)
- **Frequency**: Extracted from `"freq: "` and converted to channel numbers via `ffWifiFreqToChannel`

### Kernel Fallback via ioctl

When the `iw` command fails or is unavailable, Fastfetch falls back to Linux wireless extensions through `detectWifiWithIoctls`. This method requires compilation with `FF_HAVE_LINUX_WIRELESS` and queries the kernel directly via `ioctl` calls to retrieve SSID, BSSID, protocol, bitrate, frequency, signal level, and security information without external dependencies.

### NetworkManager Enrichment via DBus

If Fastfetch is compiled with `FF_HAVE_DBUS`, the `detectWifiWithNm` function queries NetworkManager to supplement or verify the collected data. This enrichment process:

- Retrieves the active access-point object path
- Reads SSID, BSSID, frequency, signal strength, and bitrate if not already populated
- Determines security protocols (WEP, WPA, WPA2, WPA3, OWE, 802.1X) by analyzing NM's `Flags`, `WpaFlags`, and `RsnFlags` properties

## Cross-Platform Implementation Strategy

While the Linux implementation is the most complex, Fastfetch maintains platform-specific detectors that adhere to the same `FFWifiResult` contract:

- **BSD systems**: Implemented in [`src/detection/wifi/wifi_bsd.c`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/detection/wifi/wifi_bsd.c)
- **macOS**: Implemented in `src/detection/wifi/wifi_apple.m` using native Apple APIs
- **Android**: Implemented in [`src/detection/wifi/wifi_android.c`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/detection/wifi/wifi_android.c)

The public API defined in [`src/detection/wifi/wifi.h`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/detection/wifi/wifi.h) declares `ffDetectWifi(FFlist *result)` and the helper `ffWifiFreqToChannel`, ensuring consistent behavior across operating systems.

## Practical Usage Examples

### Display WiFi Information with Default Formatting

```bash
fastfetch

```

Typical output when connected:

```

 Wi-Fi: MyNetwork (WPA2) - 73% ▓▓▓▓▓▓░░░░ 5 GHz

```

### Export WiFi Details to JSON

```bash
fastfetch --format json

```

Relevant JSON excerpt:

```json
{
  "wifi": [
    {
      "inf": {
        "description": "wlp2s0",
        "status": "up"
      },
      "conn": {
        "status": "connected",
        "ssid": "MyNetwork",
        "bssid": "12:34:56:78:9A:BC",
        "protocol": "802.11ac (Wi-Fi 5)",
        "security": "WPA2",
        "signalQuality": 73,
        "rxRate": 144.0,
        "txRate": 150.0,
        "channel": 36,
        "frequency": 5180
      }
    }
  ]
}

```

### Custom Output Formatting

Display only the SSID and signal quality bar:

```bash
fastfetch --module wifi --format "{ssid} {signal-quality-bar}"

```

Result:

```

MyNetwork ▓▓▓▓▓▓░░░░

```

### Disable DBus Enrichment

Force Fastfetch to use only `iw` or ioctl methods, bypassing NetworkManager:

```bash
FF_DISABLE_DBUS=1 fastfetch --module wifi

```

## Key Source Files and Architecture

| File | Purpose |
|------|---------|
| [`src/detection/wifi/wifi_linux.c`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/detection/wifi/wifi_linux.c) | Core Linux detection logic including `detectWifiWithIw`, `detectWifiWithIoctls`, and `detectWifiWithNm` |
| [`src/detection/wifi/wifi.h`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/detection/wifi/wifi.h) | Public API declarations for `ffDetectWifi` and `ffWifiFreqToChannel` |
| [`src/modules/wifi/wifi.c`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/modules/wifi/wifi.c) | Output formatting and printing logic for `FFWifiResult` objects |
| [`src/common/dbus.h`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/common/dbus.h) | DBus communication wrappers for NetworkManager integration |
| [`src/common/netif.h`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/common/netif.h) | Network interface utilities including `if_nameindex` wrappers |

## Summary

- Fastfetch identifies wireless interfaces by checking for `/sys/class/net/<if>/phy80211/` directories after enumerating with `if_nameindex()`.
- The primary data source is the `iw dev <if> link` command, parsed in `detectWifiWithIw` for connection details, signal strength, and protocol information.
- If `iw` is unavailable, Fastfetch falls back to kernel `ioctl` calls via `detectWifiWithIoctls` when compiled with `FF_HAVE_LINUX_WIRELESS`.
- NetworkManager DBus enrichment provides enhanced security protocol detection and data verification when `FF_HAVE_DBUS` is enabled.
- Cross-platform support for BSD, macOS, and Android follows the same `FFWifiResult` structure defined in [`src/detection/wifi/wifi.h`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/detection/wifi/wifi.h).

## Frequently Asked Questions

### Does Fastfetch require NetworkManager to display WiFi information?

No. NetworkManager integration via DBus is optional. Fastfetch prioritizes the `iw` command and falls back to `ioctl` calls if `iw` is unavailable. You can explicitly disable DBus enrichment by setting `FF_DISABLE_DBUS=1` to force pure kernel-based detection methods.

### How does Fastfetch calculate WiFi signal percentage?

Fastfetch parses the dBm value from `iw` output or ioctl results and converts it to a percentage. In [`src/detection/wifi/wifi_linux.c`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/detection/wifi/wifi_linux.c), the parsing logic extracts the signal level from `"signal: "` lines and applies conversion logic to produce the final quality percentage displayed in the output.

### Can Fastfetch detect WiFi on macOS and BSD systems?

Yes. Fastfetch includes platform-specific implementations in `src/detection/wifi/wifi_apple.m` for macOS and [`src/detection/wifi/wifi_bsd.c`](https://github.com/fastfetch-cli/fastfetch/blob/main/src/detection/wifi/wifi_bsd.c) for BSD variants. These files follow the same detection contract as the Linux implementation, populating identical `FFWifiResult` structures with SSID, BSSID, security, and signal information using native platform APIs.

### What WiFi security protocols can Fastfetch identify?

Fastfetch can detect WEP, WPA, WPA2, WPA3, OWE (Opportunistic Wireless Encryption), and 802.1X security protocols. When using NetworkManager enrichment, it derives these values by analyzing the `Flags`, `WpaFlags`, and `RsnFlags` properties from the active access point object. Without NetworkManager, security detection relies on parsing `iw` output or wireless extension ioctls.