net: add new method Sock::GetSockName() that wraps getsockname()

This will help to increase `Sock` usage and make more code mockable.
This commit is contained in:
Vasil Dimov
2021-04-13 14:37:16 +02:00
parent 8e7eeb5971
commit 748dbcd9f2
5 changed files with 34 additions and 0 deletions

View File

@@ -206,6 +206,20 @@ int FuzzedSock::SetSockOpt(int, int, const void*, socklen_t) const
return 0;
}
int FuzzedSock::GetSockName(sockaddr* name, socklen_t* name_len) const
{
constexpr std::array getsockname_errnos{
ECONNRESET,
ENOBUFS,
};
if (m_fuzzed_data_provider.ConsumeBool()) {
SetFuzzedErrNo(m_fuzzed_data_provider, getsockname_errnos);
return -1;
}
*name_len = m_fuzzed_data_provider.ConsumeData(name, *name_len);
return 0;
}
bool FuzzedSock::Wait(std::chrono::milliseconds timeout, Event requested, Event* occurred) const
{
constexpr std::array wait_errnos{