feat(libwebrtc): implement the rtc::IPAddress accessors, operator== and CountIPMaskBits #14095
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14095"
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 alvaroelpob on 2026-10-31T18:38:55Z.
What
Implements
rtc::IPAddress::ipv4_address(),ipv6_address(),v4AddressAsHostOrderInteger(),operator==andrtc::CountIPMaskBits(const IPAddress&)in libwebrtc, which threw and were declared without parameters.The module's WebRTC revision lies between M127 and M134, as recorded in the debt file by #13687. The bodies of these functions in
rtc_base/ip_address.ccare the same at M127 branch-heads/6533 and M134 branch-heads/6998; only the includes differ. The members ofIPAddressinip_address.hare the same at both.The functions are adapted from
ip_address.ccand live insrc/IpAddress.cpp, which starts with that file's WebRTC copyright notice and the BSD licence text from WebRTC'sLICENSE. The debt entry says it is adapted fromip_address.cc.WebRtcIpAddressis the 32-byte layout ofip_address.h: the vtable pointer of the virtual destructor at 0,int family_at 8, and thein_addr/in6_addrunion at 12.static_asserts check it. The constructors are inline in the header, so titles build these objects themselves; these functions only read them.AF_UNSPEC,AF_INETandAF_INET6are 0, 2 and 28, as in FreeBSD'ssocket.handNET_AF_INET6in libSceNet.ipv4_address()andipv6_address()return the union asin_addr(4 bytes, ineax) andin6_addr(16 bytes, inrax:rdx), whatever the family.v4AddressAsHostOrderInteger()returns the IPv4 address in host order forAF_INETand 0 otherwise.operator==is false for different families, compares the 4 or 16 address bytes forAF_INETandAF_INET6, is true for twoAF_UNSPECaddresses and false for any other family.CountIPMaskBitsreturns 0 for families other thanAF_INETandAF_INET6. Otherwise it skips the leading all-ones 32-bit words, then counts from the top bit of the next word down to its lowest set bit. As upstream, it does not check that the mask is contiguous: a gap is counted, and a zero word stops the count.Upstream reads through a null address, so a null
thisor argument throws. The inventory drops from 405 to 400.Tested
Ubuntu 26.04 (WSL2, kernel 6.18), GCC 15.2.0, Release, full build with
BUILD_TESTING=ON.guest_webrtc_ip_addresstest, on addresses with a vtable sentinel and 0x5A padding:ipv4_address()andipv6_address()return the union bytes for IPv4 and IPv6 addresses, whichever family is set.v4AddressAsHostOrderInteger()gives0xC0A8010Afor 192.168.1.10 and 0 forAF_INET6andAF_UNSPEC.operator==: equal and different IPv4 addresses, IPv4 bytes past the first 4 ignored, IPv4 against IPv6 with the same leading bytes, IPv6 differing in the last byte, twoAF_UNSPECaddresses with different bytes (equal) and family 1 against itself (not equal).CountIPMaskBits: IPv4 /24, /32, /1 and 0; 255.0.255.0 counts 24 and 0.0.0.1 counts 32; IPv6 prefixes of 0, 1, 31, 32, 33, 60, 64, 96, 127 and 128 bits; a /64 with a bit at 80 counts 80; an IPv6 mask whose first word is zero counts 0;AF_UNSPECand family 1 count 0.std::invalid_argumentin each function.ctest -j16on head 2555f26c85: 3034/3034 pass.check_conventions.py --base upstream/mainpasses.pr_overlap.pyreports the open pull requests listed in Depends on.1bc97b9527after #13736 merged; the only conflicts were the include, CMake source and debt count lines. Fullctest -j16on the top of the stack, #14148 head 0884de5716 (which contains this head, bc48f5d35e): 3087/3087 pass.check_conventions.py --base upstream/mainpasses.dc9dc7eaaeafter #13764 and #13816 merged. The conflicts were the debt count line and, in the AudioDeviceGeneric commit, theExport.cppstubs next to the removed VAD stubs; that commit keepsmain's side and removes only its own seven stubs. The count is now set from the stubs left inExport.cppplus the 60 bound by NID (37731 on this head,
9b777019a3). Fullctest -j16on the top of the stack, #14148 head44e052f6dd: 3113/3113 pass.check_conventions.py --base upstream/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:49:22Z.
Review: COMMENTED
Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (
Unblocks: noneis allowed), and it contained no code review.