Skip to content

Commit 6b1604a

Browse files
authored
[libc] add IPPROTO related macros (#161855)
1 parent 1f82e81 commit 6b1604a

File tree

10 files changed

+93
-0
lines changed

10 files changed

+93
-0
lines changed

libc/config/linux/aarch64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(TARGET_PUBLIC_HEADERS
1818
libc.include.locale
1919
libc.include.malloc
2020
libc.include.math
21+
libc.include.netinet_in
2122
libc.include.poll
2223
libc.include.pthread
2324
libc.include.sched

libc/config/linux/riscv/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(TARGET_PUBLIC_HEADERS
1818
libc.include.locale
1919
libc.include.malloc
2020
libc.include.math
21+
libc.include.netinet_in
2122
libc.include.poll
2223
libc.include.pthread
2324
libc.include.sched

libc/config/linux/x86_64/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(TARGET_PUBLIC_HEADERS
1818
libc.include.locale
1919
libc.include.malloc
2020
libc.include.math
21+
libc.include.netinet_in
2122
libc.include.poll
2223
libc.include.pthread
2324
libc.include.sched

libc/include/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ add_header_macro(
191191
.inttypes
192192
)
193193

194+
file(MAKE_DIRECTORY ${LIBC_INCLUDE_DIR}/netinet)
195+
196+
add_header_macro(
197+
netinet_in
198+
../libc/include/netinet/in.yaml
199+
netinet/in.h
200+
DEPENDS
201+
.llvm_libc_common_h
202+
.llvm-libc-macros.netinet_in_macros
203+
)
204+
194205
add_header_macro(
195206
assert
196207
../libc/include/assert.yaml

libc/include/llvm-libc-macros/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ add_macro_header(
152152
.math_macros
153153
)
154154

155+
add_macro_header(
156+
netinet_in_macros
157+
HDR
158+
netinet-in-macros.h
159+
)
160+
155161
add_macro_header(
156162
offsetof_macro
157163
HDR
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Definition of macros from netinet/in.h ----------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
10+
#define LLVM_LIBC_MACROS_NETINET_IN_MACROS_H
11+
12+
#define IPPROTO_IP 0
13+
#define IPPROTO_ICMP 1
14+
#define IPPROTO_TCP 6
15+
#define IPPROTO_UDP 17
16+
#define IPPROTO_IPV6 41
17+
#define IPPROTO_RAW 255
18+
19+
#endif // LLVM_LIBC_MACROS_NETINET_IN_MACROS_H

libc/include/netinet/in.h.def

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===-- C standard library header in.h ------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_NETINET_IN_H
10+
#define LLVM_LIBC_NETINET_IN_H
11+
12+
#include "__llvm-libc-common.h"
13+
14+
#include "../llvm-libc-macros/netinet-in-macros.h"
15+
16+
%%public_api()
17+
18+
#endif // LLVM_LIBC_NETINET_IN_H

libc/include/netinet/in.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
header: netinet/in.h
2+
header_template: in.h.def
3+
macros: []
4+
types: []
5+
enums: []
6+
objects: []
7+
functions: []

libc/test/include/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,16 @@ add_libc_test(
207207
libc.include.llvm-libc-macros.math_function_macros
208208
)
209209

210+
add_libc_test(
211+
netinet_in_test
212+
SUITE
213+
libc_include_tests
214+
SRCS
215+
netinet_in_test.cpp
216+
DEPENDS
217+
libc.include.llvm-libc-macros.netinet_in_macros
218+
)
219+
210220
add_libc_test(
211221
signbit_test
212222
SUITE
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//===-- Unittests for netinet/in macro ------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "include/llvm-libc-macros/netinet-in-macros.h"
10+
#include "test/UnitTest/Test.h"
11+
12+
TEST(LlvmLibcNetinetInTest, IPPROTOMacro) {
13+
EXPECT_EQ(IPPROTO_IP, 0);
14+
EXPECT_EQ(IPPROTO_ICMP, 1);
15+
EXPECT_EQ(IPPROTO_TCP, 6);
16+
EXPECT_EQ(IPPROTO_UDP, 17);
17+
EXPECT_EQ(IPPROTO_IPV6, 41);
18+
EXPECT_EQ(IPPROTO_RAW, 255);
19+
}

0 commit comments

Comments
 (0)