Skip to content

Commit 197dea8

Browse files
committed
[libc] Add IN6_IS_ADDR_UNSPECIFIED
1 parent df14096 commit 197dea8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

libc/include/llvm-libc-macros/netinet-in-macros.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
// int and takes a single argument of type const struct in6_addr *:
3939
// https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/netinet_in.h.html
4040

41+
#define IN6_IS_ADDR_UNSPECIFIED(a) \
42+
((__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[0]) == 0 && \
43+
(__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[1]) == 0 && \
44+
(__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[2]) == 0 && \
45+
(__LLVM_LIBC_CAST(reinterpret_cast, uint32_t *, a)[3]) == 0)
46+
4147
#define IN6_IS_ADDR_LINKLOCAL(a) \
4248
((__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[0]) == 0xfe && \
4349
(__LLVM_LIBC_CAST(reinterpret_cast, uint8_t *, a)[1] & 0xc0) == 0x80)

libc/test/include/netinet_in_test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
TEST(LlvmLibcNetinetInTest, IN6Macro) {
1313
char buff[16] = {};
1414

15+
EXPECT_TRUE(IN6_IS_ADDR_UNSPECIFIED(buff));
16+
for (int i = 0; i < 16; ++i) {
17+
buff[i] = 1;
18+
EXPECT_FALSE(IN6_IS_ADDR_UNSPECIFIED(buff));
19+
}
20+
1521
buff[0] = 0xfe;
1622
buff[1] = 0x80;
1723
EXPECT_TRUE(IN6_IS_ADDR_LINKLOCAL(buff));

0 commit comments

Comments
 (0)