Devlog · September 2026

On macOS, asking a TCP socket who is connected can tell you it's root

LOCAL_PEERCRED is how you ask a Unix domain socket who is on the other end. Call it on a TCP socket and it doesn't fail. getsockopt returns 0 and writes zero bytes.

SOL_LOCAL is 0, which is also IPPROTO_IP, and LOCAL_PEERCRED is 1, which is also IP_OPTIONS. You're reading an empty IP options list.

If you zeroed the struct first, the version reads 0, which equals XUCRED_VERSION, and the uid reads 0. Both sanity checks pass and the answer is root. Check the returned length and the socket family.

AF_INET  getsockopt=0 len=0  cr_version=0 cr_uid=0
AF_UNIX  getsockopt=0 len=76 cr_version=0 cr_uid=501
Check it yourself
  • peercred.c, 25 lines of C. Run cc peercred.c && ./a.out. The output above is from macOS 15.6.1.
  • Port42 does not call this. We found it while designing how a local program proves who it is.
  • Not tested on other macOS versions.