-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc] add IPPROTO related macros #161855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-backend-risc-v @llvm/pr-subscribers-libc Author: Connector Switch (c8ef) ChangesFull diff: https://github.com/llvm/llvm-project/pull/161855.diff 7 Files Affected:
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index 8fd37b0ee5ad6..2c38ab8b24a9a 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -191,6 +191,14 @@ add_header_macro(
.inttypes
)
+add_header_macro(
+ netinet_in
+ ../libc/include/netinet/in.yaml
+ netinet/in.h
+ DEPENDS
+ .llvm-libc-macros.netinet_in_macros
+)
+
add_header_macro(
assert
../libc/include/assert.yaml
diff --git a/libc/include/llvm-libc-macros/CMakeLists.txt b/libc/include/llvm-libc-macros/CMakeLists.txt
index f71540313f0b3..76c03d913ee12 100644
--- a/libc/include/llvm-libc-macros/CMakeLists.txt
+++ b/libc/include/llvm-libc-macros/CMakeLists.txt
@@ -152,6 +152,12 @@ add_macro_header(
.math_macros
)
+add_macro_header(
+ netinet_in_macros
+ HDR
+ netinet-in-macros.h
+)
+
add_macro_header(
offsetof_macro
HDR
diff --git a/libc/include/llvm-libc-macros/netinet-in-macros.h b/libc/include/llvm-libc-macros/netinet-in-macros.h
new file mode 100644
index 0000000000000..c05e5e2aec248
--- /dev/null
+++ b/libc/include/llvm-libc-macros/netinet-in-macros.h
@@ -0,0 +1,19 @@
+//===-- Definition of macros from netinet/in.h ----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
+#define LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
+
+#define IPPROTO_IP 0
+#define IPPROTO_ICMP 1
+#define IPPROTO_TCP 6
+#define IPPROTO_UDP 17
+#define IPPROTO_IPV6 41
+#define IPPROTO_RAW 255
+
+#endif // LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
diff --git a/libc/include/netinet/in.h.def b/libc/include/netinet/in.h.def
new file mode 100644
index 0000000000000..11c97e3b44b49
--- /dev/null
+++ b/libc/include/netinet/in.h.def
@@ -0,0 +1,16 @@
+//===-- C standard library header in.h ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_NETINET_IN_H
+#define LLVM_LIBC_NETINET_IN_H
+
+#include "../llvm-libc-macros/netinet-in-macros.h"
+
+%%public_api()
+
+#endif // LLVM_LIBC_NETINET_IN_H
diff --git a/libc/include/netinet/in.yaml b/libc/include/netinet/in.yaml
new file mode 100644
index 0000000000000..fbd798d60cbf9
--- /dev/null
+++ b/libc/include/netinet/in.yaml
@@ -0,0 +1,7 @@
+header: netinet/in.h
+header_template: in.h.def
+macros: []
+types: []
+enums: []
+objects: []
+functions: []
diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index 11e4c3a84157f..3ac5615d7e209 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -207,6 +207,16 @@ add_libc_test(
libc.include.llvm-libc-macros.math_function_macros
)
+add_libc_test(
+ netinet_in_test
+ SUITE
+ libc_include_tests
+ SRCS
+ netinet_in_test.cpp
+ DEPENDS
+ libc.include.llvm-libc-macros.netinet_in_macros
+)
+
add_libc_test(
signbit_test
SUITE
diff --git a/libc/test/include/netinet_in_test.cpp b/libc/test/include/netinet_in_test.cpp
new file mode 100644
index 0000000000000..a6c47a779ea44
--- /dev/null
+++ b/libc/test/include/netinet_in_test.cpp
@@ -0,0 +1,19 @@
+//===-- Unittests for netinet/in macro ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "include/llvm-libc-macros/netinet-in-macros.h"
+#include "test/UnitTest/Test.h"
+
+TEST(LlvmLibcNetinetInTest, IPPROTOMacro) {
+ EXPECT_EQ(IPPROTO_IP, 0);
+ EXPECT_EQ(IPPROTO_ICMP, 1);
+ EXPECT_EQ(IPPROTO_TCP, 6);
+ EXPECT_EQ(IPPROTO_UDP, 17);
+ EXPECT_EQ(IPPROTO_IPV6, 41);
+ EXPECT_EQ(IPPROTO_RAW, 255);
+}
|
lntue
approved these changes
Oct 6, 2025
aokblast
pushed a commit
to aokblast/llvm-project
that referenced
this pull request
Oct 6, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.