Hacker News new | ask | show | jobs
by caf 2168 days ago
Do any programs get confused when they call getsockname() and the result is an AF_UNIX they weren't expecting?
1 comments

If programs call getsockname() the result is not a sockaddr_un, but instead sockaddr_in(6) is used from the original call to bind(). If the socket was implicitly bound, a random[1] address is generated.

Things are a bit trickier if it gets to getpeername(), since we want to have somewhat stable addresses. This is done by querying SO_PEERCRED and encoding[2] the pid for IPv4 or pid, uid and gid for IPv6 into the address.

In summary: Programs shouldn't get confused, but if they do, it's certainly a bug in ip2unix. Feel free to open an issue :-)

[1]: https://github.com/nixcloud/ip2unix/blob/d7d297ed68cdadc65dc...

[2]: https://github.com/nixcloud/ip2unix/blob/d7d297ed68cdadc65dc...