Skip to content

Conversation

@c8ef
Copy link
Contributor

@c8ef c8ef commented Oct 23, 2025

This patch adds 4 macros in the netinet/in.h header, as specified by POSIX standards.

Based on previous discussions, testing these unchanged values is redundant, so I did not add tests here. If there is a better way to test these, I would be happy to add them.

@llvmbot llvmbot added the libc label Oct 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Oct 23, 2025

@llvm/pr-subscribers-libc

Author: Connector Switch (c8ef)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/164830.diff

1 Files Affected:

  • (modified) libc/include/llvm-libc-macros/netinet-in-macros.h (+8)
diff --git a/libc/include/llvm-libc-macros/netinet-in-macros.h b/libc/include/llvm-libc-macros/netinet-in-macros.h
index fb7564cee9e80..31cd0223f846a 100644
--- a/libc/include/llvm-libc-macros/netinet-in-macros.h
+++ b/libc/include/llvm-libc-macros/netinet-in-macros.h
@@ -9,6 +9,8 @@
 #ifndef LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
 #define LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
 
+#include "../llvm-libc-types/in_addr_t.h"
+
 #define IPPROTO_IP 0
 #define IPPROTO_ICMP 1
 #define IPPROTO_TCP 6
@@ -24,4 +26,10 @@
 #define IPV6_LEAVE_GROUP 21
 #define IPV6_V6ONLY 26
 
+#define INADDR_ANY __LLVM_LIBC_CAST(static_cast, in_addr_t, 0x00000000)
+#define INADDR_BROADCAST __LLVM_LIBC_CAST(static_cast, in_addr_t, 0xffffffff)
+
+#define INET_ADDRSTRLEN 16
+#define INET6_ADDRSTRLEN 46
+
 #endif // LLVM_LIBC_MACROS_NETINET_IN_MACROS_H

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, and I agree that tests aren't necessary. You do need to add in_addr_t.h to the dependencies in cmake though.

@c8ef
Copy link
Contributor Author

c8ef commented Oct 31, 2025

This looks good, and I agree that tests aren't necessary. You do need to add in_addr_t.h to the dependencies in cmake though.

Hmmm.... The cmake dependencies are not natural because we declare llvm-libc-macros before llvm-libc-types. This means that when we add the macro target, cmake does not recognize the libc-types target.

add_subdirectory(llvm-libc-macros)
add_subdirectory(llvm-libc-types)

@c8ef c8ef requested a review from michaelrj-google October 31, 2025 14:34
@c8ef
Copy link
Contributor Author

c8ef commented Nov 8, 2025

Based on the Discord discussion, the current CMake settings make it difficult for the libc-macro to depend on the libc-type. Given that we have already had similar situations and the libc-types are considered stable, I believe we can merge this as it is.

@c8ef c8ef merged commit ffb5831 into llvm:main Nov 8, 2025
20 checks passed
vinay-deshmukh pushed a commit to vinay-deshmukh/llvm-project that referenced this pull request Nov 8, 2025
This patch adds 4 macros in the `netinet/in.h` header, as specified by
POSIX standards.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants