diff options
author | Vasil Dimov <vd@FreeBSD.org> | 2021-04-13 14:37:16 +0200 |
---|---|---|
committer | Vasil Dimov <vd@FreeBSD.org> | 2022-06-20 14:51:18 +0200 |
commit | 748dbcd9f29dbe4110da8a06f08e3eefa95f5321 (patch) | |
tree | 34a5c7076f0f18cbf5681cd6c59f624ff8cd31e5 /src/test/fuzz/util.cpp | |
parent | 8e7eeb5971444c0c93e9a89bbdcc3a51a19e09e9 (diff) | |
download | bitcoin-748dbcd9f29dbe4110da8a06f08e3eefa95f5321.tar.xz |
net: add new method Sock::GetSockName() that wraps getsockname()
This will help to increase `Sock` usage and make more code mockable.
Diffstat (limited to 'src/test/fuzz/util.cpp')
-rw-r--r-- | src/test/fuzz/util.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/test/fuzz/util.cpp b/src/test/fuzz/util.cpp index 883698aff1..76a85b7a13 100644 --- a/src/test/fuzz/util.cpp +++ b/src/test/fuzz/util.cpp @@ -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{ |