net/SocketDescriptor: add GetPeerPidfd()
This commit is contained in:

committed by
Max Kellermann

parent
78e643150f
commit
88fa68f030
@@ -8,6 +8,10 @@
|
||||
#include "IPv6Address.hxx"
|
||||
#include "UniqueSocketDescriptor.hxx"
|
||||
|
||||
#ifdef __linux__
|
||||
#include "io/UniqueFileDescriptor.hxx"
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
@@ -235,6 +239,24 @@ SocketDescriptor::GetPeerCredentials() const noexcept
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
#ifndef SO_PEERPIDFD
|
||||
#define SO_PEERPIDFD 77
|
||||
#endif
|
||||
|
||||
UniqueFileDescriptor
|
||||
SocketDescriptor::GetPeerPidfd() const noexcept
|
||||
{
|
||||
int pidfd;
|
||||
if (GetOption(SOL_SOCKET, SO_PEERPIDFD, &pidfd, sizeof(pidfd)) < sizeof(pidfd))
|
||||
return {};
|
||||
|
||||
return UniqueFileDescriptor{pidfd};
|
||||
}
|
||||
|
||||
#endif // __linux__
|
||||
|
||||
#ifdef _WIN32
|
||||
|
||||
bool
|
||||
|
Reference in New Issue
Block a user