fix(libkernel): follow FreeBSD's text rules in inet_pton and inet_ntop on Windows #2768
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2768"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-10T13:38:52Z.
What
The guest
inet_ptonandinet_ntopcalled Winsock'sInetPtonAandInetNtopA, whose text rules differ from FreeBSD'slib/libc/inet/inet_pton.candinet_ntop.c(releng/11.4):inet_pton(AF_INET6, "::01.2.3.4")(and::1.2.3.04,::0.0.0.00) returned 1 where FreeBSD returns 0 (no leading zeros in a dotted part),inet_ntopprinted::ffff:0.0.0.1as::ffff:0:1, and::ffff:0:1:0with a dotted tail (::ffff:0:0.1.0.0) where FreeBSD prints::ffff:0.0.0.1and::ffff:0:1:0.Both functions are now implemented in
AddressConversion.cppwithout the host: it is written from the text grammar (RFC 4291 section 2.2, RFC 3493) and FreeBSD's observable rules, not copied from any BSD, glibc or musl source:inet_ptonsplits the text at::and parses the two halves as group lists,inet_ntopfinds the longest zero run in a separate pass. The rules:AF_INETis four decimal parts of 1 to 3 digits with no leading zero;AF_INET6is up to eight groups of 1 to 4 hex digits with at most one::standing for one or more zero groups, a dotted IPv4 tail only as the last 32 bits, no zone id;inet_ntopprints lowercase hex without leading zeros, compresses the first longest run of two or more zero groups, and prints a dotted tail only for::a.b.c.d(not::,::1) and::ffff:a.b.c.d. Return values,EAFNOSUPPORT(47) for a bad family,ENOSPC(28) for a short buffer and the existing NULL handling are unchanged, and the file no longer needs Winsock.sceNetInetPtonandsceNetInetNtopinlibSceNetstill use the host functions and are noted in TechnicalDebt together with the assumption that this behaviour follows FreeBSD 11.4 and is unverified on a console.Tested
Windows 11 (10.0.26200), WinLibs GCC 15.2.0 r7, Release:
guest_addressesgains the leading-zero cases, the::ffff:and::2,::,::1,1::prints, invalid forms such as1:2:3:4:5:6:7:8::and a zone id, exact-fit and one-short buffers and the family errors; it fails without the change (exit0xc0000409) and passes with it.ctest -R "guest_addresses|guest_udp"passes.inet_pton.candinet_ntop.c(releng/11.4) compiled as a reference, comparing return value,errno, every destination byte and guard bytes past the buffer: more than 3 billion cases and 0 divergences, including all strings of length 7 or less over0123456789.xX-+ afor IPv4 and of length 6 over the hex alphabet for IPv6, 153 million strings of length up to 9 over0f:.1% 9, 20 million structured and 20 million mutated IPv6 forms, every 16-bit value in each group position, all{0, 1, ffff, 0x1234}^8combinations, 1 billion random 16-byte patterns biased to zero runs, and 2^28 IPv4 patterns, with buffer sizes 0 to 50; a second run with an undefined-behaviour-trapping build of the new file found no trap.tools/check_conventions.py --base origin/mainpasses;tools/pr_overlap.py --branchreports no overlap.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T13:39:00Z.
Thank you for your interest in the project! We are sorry, but we cannot accept more PRs while we work through the existing backlog. This PR has been automatically closed and labeled "intake paused". This is not a judgment of the quality of your changes.
Pull request closed