[libc-commits] [libc] [libc] Add inet_ntop (PR #204143)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Tue Jun 23 06:46:05 PDT 2026


================
@@ -61,5 +68,160 @@ cpp::optional<in_addr_t> inet_addr(const char *cp) {
   return Endian::to_big_endian(result);
 }
 
+namespace {
+
+size_t ipv4_num_bytes(cpp::span<const uint8_t> src) {
+  size_t result = 8; // four digits, three dots and '\0'
+  for (unsigned i = 0; i < 4; ++i)
----------------
labath wrote:

I can use a range based loop right now.

As for hardening, the reason I used cpp::span instead of e.g. a raw pointer is that it enables hardening this by doing the range check inside span's operator[]. I was expecting this was already happening, at least in some debug/expensive check mode, but it does not.

Now, if we're talking about some sort of an always-on check that can be mostly elided for safe code, then that would probably be a case for implementing the static-extent version of cpp:span.

https://github.com/llvm/llvm-project/pull/204143


More information about the libc-commits mailing list