net: Avoid calling getnameinfo when formatting IP addresses
Summary:
Context from the PR description and related issues:
Calling CNetAddr::ToString triggers the use of the socket syscall. The syscall is made indirectly via getnameinfo.
Not a big deal of course, but it would be nice if kept the direct and indirect use of networking related syscalls such as socket to functions where they cannot be avoided. That would make reasoning about syscall restrictions and/or application-vs-kernel boundaries somewhat easier.
https://github.com/bitcoin/bitcoin/pull/21564/commits/58580573843858068db69a378b6e9363889b1f6d
net: Add IPv4ToString (we already have IPv6ToString)
https://github.com/bitcoin/bitcoin/pull/21564/commits/58580a827d10c0675c3483e2aeca1d3ab8050ae0
net: Avoid calling getnameinfo when formatting IPv4 addresses in CNetAddr::ToStringIP
https://github.com/bitcoin/bitcoin/pull/21756/commits/c10f27fdb2d335954dd1017ce6d5800159427374
net: Make IPv6ToString do zero compression as described in RFC 5952
https://github.com/bitcoin/bitcoin/pull/21756/commits/54548bae8004a8f49d73bd29aeca8b41894214c4
net: Avoid calling getnameinfo when formatting IPv6 addresses in CNetAddr::ToStringIP
https://github.com/bitcoin/bitcoin/pull/21985/commits/6c280adcd865ae3da4df53d630c9bf737283a56f
net: Return IPv6 scope id in CNetAddr::ToStringIP()
If a scope id is provided, return it back in the string representation.
Also bring back the test.Co-authored-by: Jon Atack <jon@atack.com>
This commit restores a feature removed in core#21756 and restores the corresponding test removed in D12175
This is a backport of core#21564, core#21756 and core#21985
Depends on D13319
Test Plan: ninja all check-all
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Subscribers: Fabien
Differential Revision: https://reviews.bitcoinabc.org/D13312