@pemensik here's how Ladybird does it. Getting peer information is probably the least portable socket operation I've ever seen. Every unix does it slightly differently just for fun.
https://github.com/LadybirdBrowser/ladybird/blob/master/Libraries/LibCore/Socket.cpp#L482-L521

