gsocket: Fix credentials error-handling on Apple OSes
- When querying a TCP socket, getsockopt() may succeed but the resulting “optlen” will be zero. This means we'd previously be reading uninitialized stack memory in such cases.
- After a file-descriptor has gone through FD-passing, getsockopt() may fail with EINVAL. At least this is the case with TCP sockets.
- While at it also use SOL_LOCAL instead of hard-coding its value.