net/PeerCredentials: wrapper for struct ucred
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "IPv4Address.hxx"
|
||||
#include "IPv6Address.hxx"
|
||||
#include "UniqueSocketDescriptor.hxx"
|
||||
#include "PeerCredentials.hxx"
|
||||
|
||||
#ifdef __linux__
|
||||
#include "io/UniqueFileDescriptor.hxx"
|
||||
@@ -225,19 +226,19 @@ SocketDescriptor::GetIntOption(int level, int name, int fallback) const noexcept
|
||||
return value;
|
||||
}
|
||||
|
||||
#ifdef HAVE_STRUCT_UCRED
|
||||
|
||||
struct ucred
|
||||
SocketPeerCredentials
|
||||
SocketDescriptor::GetPeerCredentials() const noexcept
|
||||
{
|
||||
struct ucred cred;
|
||||
#ifdef HAVE_STRUCT_UCRED
|
||||
SocketPeerCredentials cred;
|
||||
if (GetOption(SOL_SOCKET, SO_PEERCRED,
|
||||
&cred, sizeof(cred)) < sizeof(cred))
|
||||
cred.pid = -1;
|
||||
&cred.cred, sizeof(cred.cred)) < sizeof(cred.cred))
|
||||
return SocketPeerCredentials::Undefined();
|
||||
return cred;
|
||||
}
|
||||
|
||||
#else
|
||||
return SocketPeerCredentials::Undefined();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
|
Reference in New Issue
Block a user