llvm-project
544b2ef6 - Reapply "[libc] Add network byte-order helpers to __support/net" (#243396)

Commit
4 days ago
Reapply "[libc] Add network byte-order helpers to __support/net" (#243396) Reverts llvm/llvm-project#243187, re-applying #243122. Dropping libc.src.arpa.inet.htons from udp_test removed the entrypoint gating that had been keeping it disabled on non-Linux targets. Move udp_test into test/src/netinet/linux/ so it only builds on Linux. The original commit message was: In overlay mode, system headers (<netinet/in.h>, <arpa/inet.h>) may define htons/htonl/ntohs/ntohl as macros. Including our entrypoint headers after those system headers or calling LIBC_NAMESPACE::htons(...) without extra parentheses runs into macro expansion issues. Add templated net::hton<T> and net::ntoh<T> helpers in __support/net/byte_order.h (along with making Endian conversions constexpr), and use them across internal networking code, the hton*/ntoh* entrypoints, and unit tests instead of the htons-family entrypoints or direct Endian::{to,from}_big_endian calls. Assisted-by: Gemini
Author
Parents
Loading