Skip to content

fix: support macOS in capture privilege check#1

Merged
tjnull merged 1 commit into
tjnull:mainfrom
keskinonur:fix/macos-capture-privilege
Apr 4, 2026
Merged

fix: support macOS in capture privilege check#1
tjnull merged 1 commit into
tjnull:mainfrom
keskinonur:fix/macos-capture-privilege

Conversation

@keskinonur
Copy link
Copy Markdown

Summary

  • _has_capture_privilege() in cli.py uses socket.AF_PACKET which is Linux-only and raises AttributeError on macOS
  • Replaced with a platform-aware approach:
    1. Check os.getuid() == 0 first (works on both Linux and macOS)
    2. Try AF_PACKET raw socket on Linux
    3. Fall back to checking /dev/bpf* device access on macOS/BSD

Reproduce

On macOS:

sudo uv run leetha -i en0 --web

Before fix:

AttributeError: module 'socket' has no attribute 'AF_PACKET'

After fix: starts normally.

Test plan

  • Verified on macOS (Darwin 25.4.0) — leetha starts and captures packets
  • Linux behavior unchanged (AF_PACKET path preserved)

`socket.AF_PACKET` is Linux-only and raises `AttributeError` on macOS.
Use a platform-aware approach: check UID for root, try AF_PACKET on
Linux, and fall back to BPF device access on macOS/BSD.
@tjnull
Copy link
Copy Markdown
Owner

tjnull commented Apr 4, 2026

Great Observation! I have not tested leetha on MacOS and there should be no regression to break any Linux changes.

Pull request has been approved. Thank you for your contributions to the project!

@tjnull tjnull merged commit afa1f2e into tjnull:main Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants