freebsd-src/lib/libc/inet
Lexi Winter 857897013b libc: Import OpenBSD's inet_net_{ntop,pton}
Our versions of these functions (originally taken from BIND) simply
don't work correctly for AF_INET6.  These were removed from BIND itself
quite a while ago, but OpenBSD has made several fixes in the mean time,
so import their code.

Add tests for both functions.

PR:		289198
Reported by:	Nico Sonack <nsonack@herrhotzenplotz.de>
MFC after:	1 week
Reviewed by:	des
Obtained from:	OpenBSD (lib/libc/net)
Sponsored by:	https://www.patreon.com/bsdivy
Differential Revision:	https://reviews.freebsd.org/D52629

(cherry picked from commit 8f4a0d2f7b)

inet_net_test: Compare pointers against nullptr

GCC does not like passing NULL (__null) to std::ostringstream::operator<<
inside of ATF_REQUIRE_EQ:

lib/libc/tests/net/inet_net_test.cc: In member function 'virtual void {anonymous}::atfu_tc_inet_net_ntop_invalid::body() const':
lib/libc/tests/net/inet_net_test.cc:306:9: error: passing NULL to non-pointer argument 1 of 'std::__1::basic_ostream<_CharT, _Traits>& std::__1::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char; _Traits = std::__1::char_traits<char>]' [-Werror=conversion-null]
  306 |         ATF_REQUIRE_EQ(ret, NULL);
      |         ^~~~~~~~~~~~~~
In file included from /usr/obj/.../amd64.amd64/tmp/usr/include/c++/v1/sstream:317,
                 from /usr/obj/.../amd64.amd64/tmp/usr/include/atf-c++/macros.hpp:29,
                 from /usr/obj/.../amd64.amd64/tmp/usr/include/atf-c++.hpp:29,
                 from lib/libc/tests/net/inet_net_test.cc:33:
/usr/obj/.../amd64.amd64/tmp/usr/include/c++/v1/__ostream/basic_ostream.h:338:81: note:   declared here
  338 | basic_ostream<_CharT, _Traits>& basic_ostream<_CharT, _Traits>::operator<<(long __n) {
      |                                                                            ~~~~~^~~
...

Fixes:		8f4a0d2f7b ("libc: Import OpenBSD's inet_net_{ntop,pton}")
(cherry picked from commit aa358ce3ca)

inet_net_test: Use int to hold expected return values from inet_net_pton

GCC warns about the sign mismatch in comparisons:

lib/libc/tests/net/inet_net_test.cc: In member function 'virtual void {anonymous}::atfu_tc_inet_net_inet4::body() const':
lib/libc/tests/net/inet_net_test.cc:86:17: error: comparison of integer expressions of different signedness: 'int' and 'const unsigned int' [-Werror=sign-compare]
   86 |                 ATF_REQUIRE_EQ(bits, addr.bits);
      |                 ^~~~~~~~~~~~~~
lib/libc/tests/net/inet_net_test.cc: In member function 'virtual void {anonymous}::atfu_tc_inet_net_inet6::body() const':
lib/libc/tests/net/inet_net_test.cc:205:17: error: comparison of integer expressions of different signedness: 'int' and 'const unsigned int' [-Werror=sign-compare]
  205 |                 ATF_REQUIRE_EQ(bits, addr.bits);
      |                 ^~~~~~~~~~~~~~

Fixes:		8f4a0d2f7b ("libc: Import OpenBSD's inet_net_{ntop,pton}")
(cherry picked from commit e1aeb58cbb)
(cherry picked from commit b4871be349)
2025-10-25 05:41:37 +01:00
..
inet_addr.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
inet_cidr_ntop.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
inet_cidr_pton.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
inet_lnaof.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
inet_makeaddr.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
inet_net_ntop.c libc: Import OpenBSD's inet_net_{ntop,pton} 2025-10-25 05:41:37 +01:00
inet_net_pton.c libc: Import OpenBSD's inet_net_{ntop,pton} 2025-10-25 05:41:37 +01:00
inet_neta.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
inet_netof.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
inet_network.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
inet_ntoa.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
inet_ntop.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
inet_pton.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
Makefile.inc Remove $FreeBSD$: one-line sh pattern 2023-08-23 11:43:30 -06:00
nsap_addr.c Remove $FreeBSD$: one-line .c pattern 2023-08-23 11:43:26 -06:00
Symbol.map