[libc-commits] [libc] a712923 - [libc] Add IPv4 socket options and related structs (#204787)

via libc-commits libc-commits at lists.llvm.org
Wed Jun 24 02:17:08 PDT 2026


Author: Pavel Labath
Date: 2026-06-24T11:17:03+02:00
New Revision: a71292356656e0c516019aa6b571baeb572a7624

URL: https://github.com/llvm/llvm-project/commit/a71292356656e0c516019aa6b571baeb572a7624
DIFF: https://github.com/llvm/llvm-project/commit/a71292356656e0c516019aa6b571baeb572a7624.diff

LOG: [libc] Add IPv4 socket options and related structs (#204787)

This patch adds struct ip_mreq, ip_mreq_source, ip_mreqn, ip_opts, and
ip_msfilter to <netinet/in.h>, along with IP level socket option macros
(IP_TOS, IP_TTL, IP_ADD_MEMBERSHIP, etc.).

I add basic unit tests verifying the size and member offsets of the new
structures against standard layout expectations, mainly to make sure
that the files are used /somewhere/.

Assisted by Gemini.

Added: 
    libc/hdr/types/struct_ip_mreq.h
    libc/hdr/types/struct_ip_mreq_source.h
    libc/hdr/types/struct_ip_mreqn.h
    libc/hdr/types/struct_ip_msfilter.h
    libc/hdr/types/struct_ip_opts.h
    libc/include/llvm-libc-types/struct_ip_mreq.h
    libc/include/llvm-libc-types/struct_ip_mreq_source.h
    libc/include/llvm-libc-types/struct_ip_mreqn.h
    libc/include/llvm-libc-types/struct_ip_msfilter.h
    libc/include/llvm-libc-types/struct_ip_opts.h

Modified: 
    libc/hdr/types/CMakeLists.txt
    libc/include/CMakeLists.txt
    libc/include/llvm-libc-types/CMakeLists.txt
    libc/include/netinet/in.yaml
    libc/test/src/netinet/CMakeLists.txt
    libc/test/src/netinet/in_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index 1742e423b1d00..a130f7ee0000a 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -455,6 +455,51 @@ add_proxy_header_library(
     libc.include.netinet_in
 )
 
+add_proxy_header_library(
+  struct_ip_mreq
+  HDRS
+    struct_ip_mreq.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.struct_ip_mreq
+    libc.include.netinet_in
+)
+
+add_proxy_header_library(
+  struct_ip_mreq_source
+  HDRS
+    struct_ip_mreq_source.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.struct_ip_mreq_source
+    libc.include.netinet_in
+)
+
+add_proxy_header_library(
+  struct_ip_mreqn
+  HDRS
+    struct_ip_mreqn.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.struct_ip_mreqn
+    libc.include.netinet_in
+)
+
+add_proxy_header_library(
+  struct_ip_msfilter
+  HDRS
+    struct_ip_msfilter.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.struct_ip_msfilter
+    libc.include.netinet_in
+)
+
+add_proxy_header_library(
+  struct_ip_opts
+  HDRS
+    struct_ip_opts.h
+  FULL_BUILD_DEPENDS
+    libc.include.llvm-libc-types.struct_ip_opts
+    libc.include.netinet_in
+)
+
 add_proxy_header_library(
   in_addr_t
   HDRS

diff  --git a/libc/hdr/types/struct_ip_mreq.h b/libc/hdr/types/struct_ip_mreq.h
new file mode 100644
index 0000000000000..9799f892bf7ef
--- /dev/null
+++ b/libc/hdr/types/struct_ip_mreq.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Proxy header for struct ip_mreq.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_IP_MREQ_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_IP_MREQ_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_ip_mreq.h"
+
+#else
+
+#include <netinet/in.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_IP_MREQ_H

diff  --git a/libc/hdr/types/struct_ip_mreq_source.h b/libc/hdr/types/struct_ip_mreq_source.h
new file mode 100644
index 0000000000000..d19fd6cd19132
--- /dev/null
+++ b/libc/hdr/types/struct_ip_mreq_source.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Proxy header for struct ip_mreq_source.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_IP_MREQ_SOURCE_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_IP_MREQ_SOURCE_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_ip_mreq_source.h"
+
+#else
+
+#include <netinet/in.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_IP_MREQ_SOURCE_H

diff  --git a/libc/hdr/types/struct_ip_mreqn.h b/libc/hdr/types/struct_ip_mreqn.h
new file mode 100644
index 0000000000000..9672e2408f705
--- /dev/null
+++ b/libc/hdr/types/struct_ip_mreqn.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Proxy header for struct ip_mreqn.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_IP_MREQN_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_IP_MREQN_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_ip_mreqn.h"
+
+#else
+
+#include <netinet/in.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_IP_MREQN_H

diff  --git a/libc/hdr/types/struct_ip_msfilter.h b/libc/hdr/types/struct_ip_msfilter.h
new file mode 100644
index 0000000000000..7434815d95fd3
--- /dev/null
+++ b/libc/hdr/types/struct_ip_msfilter.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Proxy header for struct ip_msfilter.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_IP_MSFILTER_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_IP_MSFILTER_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_ip_msfilter.h"
+
+#else
+
+#include <netinet/in.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_IP_MSFILTER_H

diff  --git a/libc/hdr/types/struct_ip_opts.h b/libc/hdr/types/struct_ip_opts.h
new file mode 100644
index 0000000000000..44f922f941da0
--- /dev/null
+++ b/libc/hdr/types/struct_ip_opts.h
@@ -0,0 +1,26 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Proxy header for struct ip_opts.
+///
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_LIBC_HDR_TYPES_STRUCT_IP_OPTS_H
+#define LLVM_LIBC_HDR_TYPES_STRUCT_IP_OPTS_H
+
+#ifdef LIBC_FULL_BUILD
+
+#include "include/llvm-libc-types/struct_ip_opts.h"
+
+#else
+
+#include <netinet/in.h>
+
+#endif // LIBC_FULL_BUILD
+
+#endif // LLVM_LIBC_HDR_TYPES_STRUCT_IP_OPTS_H

diff  --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index ab24c854692d0..bb670b614742a 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -235,6 +235,11 @@ add_header_macro(
     .llvm-libc-types.struct_sockaddr_in6
     .llvm-libc-types.struct_in_addr
     .llvm-libc-types.struct_in6_addr
+    .llvm-libc-types.struct_ip_mreq
+    .llvm-libc-types.struct_ip_mreq_source
+    .llvm-libc-types.struct_ip_mreqn
+    .llvm-libc-types.struct_ip_msfilter
+    .llvm-libc-types.struct_ip_opts
     .llvm_libc_common_h
 )
 

diff  --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index c0c600983ba12..0512d3f0e642a 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -68,6 +68,11 @@ add_header(in_addr_t HDR in_addr_t.h)
 add_header(in_port_t HDR in_port_t.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
 add_header(struct_in_addr HDR struct_in_addr.h DEPENDS .in_addr_t)
 add_header(struct_in6_addr HDR struct_in6_addr.h DEPENDS libc.include.llvm-libc-macros.stdint_macros)
+add_header(struct_ip_mreq HDR struct_ip_mreq.h DEPENDS .struct_in_addr)
+add_header(struct_ip_mreq_source HDR struct_ip_mreq_source.h DEPENDS .struct_in_addr)
+add_header(struct_ip_mreqn HDR struct_ip_mreqn.h DEPENDS .struct_in_addr)
+add_header(struct_ip_msfilter HDR struct_ip_msfilter.h DEPENDS libc.include.llvm-libc-macros.stdint_macros .struct_in_addr)
+add_header(struct_ip_opts HDR struct_ip_opts.h DEPENDS .struct_in_addr)
 add_header(ino_t HDR ino_t.h)
 add_header(key_t HDR key_t.h)
 add_header(mbstate_t HDR mbstate_t.h)

diff  --git a/libc/include/llvm-libc-types/struct_ip_mreq.h b/libc/include/llvm-libc-types/struct_ip_mreq.h
new file mode 100644
index 0000000000000..614a38d8d95c6
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_ip_mreq.h
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct ip_mreq.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_IP_MREQ_H
+#define LLVM_LIBC_TYPES_STRUCT_IP_MREQ_H
+
+#include "struct_in_addr.h"
+
+struct ip_mreq {
+  struct in_addr imr_multiaddr;
+  struct in_addr imr_interface;
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_IP_MREQ_H

diff  --git a/libc/include/llvm-libc-types/struct_ip_mreq_source.h b/libc/include/llvm-libc-types/struct_ip_mreq_source.h
new file mode 100644
index 0000000000000..565c92ba43c7d
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_ip_mreq_source.h
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct ip_mreq_source.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_IP_MREQ_SOURCE_H
+#define LLVM_LIBC_TYPES_STRUCT_IP_MREQ_SOURCE_H
+
+#include "struct_in_addr.h"
+
+struct ip_mreq_source {
+  struct in_addr imr_multiaddr;
+  struct in_addr imr_interface;
+  struct in_addr imr_sourceaddr;
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_IP_MREQ_SOURCE_H

diff  --git a/libc/include/llvm-libc-types/struct_ip_mreqn.h b/libc/include/llvm-libc-types/struct_ip_mreqn.h
new file mode 100644
index 0000000000000..7fa7aaa2dd09b
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_ip_mreqn.h
@@ -0,0 +1,25 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct ip_mreqn.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_IP_MREQN_H
+#define LLVM_LIBC_TYPES_STRUCT_IP_MREQN_H
+
+#include "struct_in_addr.h"
+
+struct ip_mreqn {
+  struct in_addr imr_multiaddr;
+  struct in_addr imr_address;
+  int imr_ifindex;
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_IP_MREQN_H

diff  --git a/libc/include/llvm-libc-types/struct_ip_msfilter.h b/libc/include/llvm-libc-types/struct_ip_msfilter.h
new file mode 100644
index 0000000000000..6a5c4097cafcd
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_ip_msfilter.h
@@ -0,0 +1,28 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct ip_msfilter.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_IP_MSFILTER_H
+#define LLVM_LIBC_TYPES_STRUCT_IP_MSFILTER_H
+
+#include "../llvm-libc-macros/stdint-macros.h"
+#include "struct_in_addr.h"
+
+struct ip_msfilter {
+  struct in_addr imsf_multiaddr;
+  struct in_addr imsf_interface;
+  uint32_t imsf_fmode;
+  uint32_t imsf_numsrc;
+  struct in_addr imsf_slist[1]; // Variable size.
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_IP_MSFILTER_H

diff  --git a/libc/include/llvm-libc-types/struct_ip_opts.h b/libc/include/llvm-libc-types/struct_ip_opts.h
new file mode 100644
index 0000000000000..18c6d638cbcd4
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_ip_opts.h
@@ -0,0 +1,24 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Definition of struct ip_opts.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TYPES_STRUCT_IP_OPTS_H
+#define LLVM_LIBC_TYPES_STRUCT_IP_OPTS_H
+
+#include "struct_in_addr.h"
+
+struct ip_opts {
+  struct in_addr ip_dst;
+  char ip_opts[40]; // Variable size.
+};
+
+#endif // LLVM_LIBC_TYPES_STRUCT_IP_OPTS_H

diff  --git a/libc/include/netinet/in.yaml b/libc/include/netinet/in.yaml
index e4eb7d65bb42d..0244b160cb601 100644
--- a/libc/include/netinet/in.yaml
+++ b/libc/include/netinet/in.yaml
@@ -24,6 +24,82 @@ macros:
     macro_header: inet-address-macros.h
   - macro_name: INET6_ADDRSTRLEN
     macro_header: inet-address-macros.h
+
+  - macro_name: SOL_IP
+    macro_value: 0
+
+  # IP level socket options
+  - macro_name: IP_TOS
+    macro_value: 1 # int
+  - macro_name: IP_TTL
+    macro_value: 2 # int
+  - macro_name: IP_HDRINCL
+    macro_value: 3 # int
+  - macro_name: IP_OPTIONS
+    macro_value: 4 # struct ip_opts
+  - macro_name: IP_ROUTER_ALERT
+    macro_value: 5 # int
+  - macro_name: IP_RECVOPTS
+    macro_value: 6 # int
+  - macro_name: IP_RETOPTS
+    macro_value: 7 # int
+  - macro_name: IP_PKTINFO
+    macro_value: 8 # int
+  - macro_name: IP_MTU_DISCOVER
+    macro_value: 10 # int
+  - macro_name: IP_PMTUDISC_DONT
+    macro_value: 0
+  - macro_name: IP_PMTUDISC_WANT
+    macro_value: 1
+  - macro_name: IP_PMTUDISC_DO
+    macro_value: 2
+  - macro_name: IP_PMTUDISC_PROBE
+    macro_value: 3
+  - macro_name: IP_RECVERR
+    macro_value: 11 # int
+  - macro_name: IP_RECVTTL
+    macro_value: 12 # int
+  - macro_name: IP_RECVTOS
+    macro_value: 13 # int
+  - macro_name: IP_MTU
+    macro_value: 14 # int
+  - macro_name: IP_FREEBIND
+    macro_value: 15 # int
+  - macro_name: IP_PASSSEC
+    macro_value: 18 # int
+  - macro_name: IP_TRANSPARENT
+    macro_value: 19 # int
+  - macro_name: IP_RECVORIGDSTADDR
+    macro_value: 20 # int
+  - macro_name: IP_NODEFRAG
+    macro_value: 22 # int
+  - macro_name: IP_BIND_ADDRESS_NO_PORT
+    macro_value: 24 # int
+  - macro_name: IP_MULTICAST_IF
+    macro_value: 32 # struct in_addr or ip_mreq or ip_mreqn
+  - macro_name: IP_MULTICAST_TTL
+    macro_value: 33 # int
+  - macro_name: IP_MULTICAST_LOOP
+    macro_value: 34 # int
+  - macro_name: IP_ADD_MEMBERSHIP
+    macro_value: 35 # struct ip_mreq or ip_mreqn
+  - macro_name: IP_DROP_MEMBERSHIP
+    macro_value: 36 # struct ip_mreq or ip_mreqn
+  - macro_name: IP_UNBLOCK_SOURCE
+    macro_value: 37 # struct ip_mreq_source
+  - macro_name: IP_BLOCK_SOURCE
+    macro_value: 38 # struct ip_mreq_source
+  - macro_name: IP_ADD_SOURCE_MEMBERSHIP
+    macro_value: 39 # struct ip_mreq_source
+  - macro_name: IP_DROP_SOURCE_MEMBERSHIP
+    macro_value: 40 # struct ip_mreq_source
+  - macro_name: IP_MSFILTER
+    macro_value: 41 # struct ip_msfilter
+  - macro_name: IP_MULTICAST_ALL
+    macro_value: 49 # int
+  - macro_name: IP_LOCAL_PORT_RANGE
+    macro_value: 51 # uint32_t
+
 types:
   - type_name: in_port_t
   - type_name: in_addr_t
@@ -32,6 +108,11 @@ types:
   - type_name: struct_sockaddr_in6
   - type_name: struct_in_addr
   - type_name: struct_in6_addr
+  - type_name: struct_ip_mreq
+  - type_name: struct_ip_mreq_source
+  - type_name: struct_ip_mreqn
+  - type_name: struct_ip_msfilter
+  - type_name: struct_ip_opts
 enums: []
 objects:
   - object_name: in6addr_any

diff  --git a/libc/test/src/netinet/CMakeLists.txt b/libc/test/src/netinet/CMakeLists.txt
index 605f70ff193cd..f1adcf0f56f17 100644
--- a/libc/test/src/netinet/CMakeLists.txt
+++ b/libc/test/src/netinet/CMakeLists.txt
@@ -9,6 +9,11 @@ add_libc_unittest(
   DEPENDS
     libc.hdr.netinet_in_macros
     libc.hdr.types.struct_in6_addr
+    libc.hdr.types.struct_ip_mreq
+    libc.hdr.types.struct_ip_mreq_source
+    libc.hdr.types.struct_ip_mreqn
+    libc.hdr.types.struct_ip_msfilter
+    libc.hdr.types.struct_ip_opts
     libc.hdr.types.struct_sockaddr_in6
     libc.src.arpa.inet.htons
     libc.src.arpa.inet.htonl

diff  --git a/libc/test/src/netinet/in_test.cpp b/libc/test/src/netinet/in_test.cpp
index fb4c3be335605..eccfdf37d5514 100644
--- a/libc/test/src/netinet/in_test.cpp
+++ b/libc/test/src/netinet/in_test.cpp
@@ -18,6 +18,11 @@
 
 #include "hdr/netinet_in_macros.h"
 #include "hdr/types/struct_in6_addr.h"
+#include "hdr/types/struct_ip_mreq.h"
+#include "hdr/types/struct_ip_mreq_source.h"
+#include "hdr/types/struct_ip_mreqn.h"
+#include "hdr/types/struct_ip_msfilter.h"
+#include "hdr/types/struct_ip_opts.h"
 #include "hdr/types/struct_sockaddr_in6.h"
 #include "src/netinet/in6addr_any.h"
 #include "src/netinet/in6addr_loopback.h"
@@ -92,3 +97,36 @@ TEST(LlvmLibcNetinetInTest, SockaddrIn6Layout) {
             static_cast<size_t>(24));
   EXPECT_EQ(sizeof(struct sockaddr_in6), static_cast<size_t>(28));
 }
+
+TEST(LlvmLibcNetinetInTest, IpOptionLayout) {
+  EXPECT_EQ(sizeof(struct ip_mreq), static_cast<size_t>(8));
+  EXPECT_EQ(sizeof(struct ip_mreq_source), static_cast<size_t>(12));
+  EXPECT_EQ(sizeof(struct ip_mreqn), static_cast<size_t>(12));
+  EXPECT_EQ(sizeof(struct ip_msfilter), static_cast<size_t>(20));
+  EXPECT_EQ(sizeof(struct ip_opts), static_cast<size_t>(44));
+
+  EXPECT_EQ(offsetof(struct ip_mreq, imr_multiaddr), static_cast<size_t>(0));
+  EXPECT_EQ(offsetof(struct ip_mreq, imr_interface), static_cast<size_t>(4));
+
+  EXPECT_EQ(offsetof(struct ip_mreq_source, imr_multiaddr),
+            static_cast<size_t>(0));
+  EXPECT_EQ(offsetof(struct ip_mreq_source, imr_interface),
+            static_cast<size_t>(4));
+  EXPECT_EQ(offsetof(struct ip_mreq_source, imr_sourceaddr),
+            static_cast<size_t>(8));
+
+  EXPECT_EQ(offsetof(struct ip_mreqn, imr_multiaddr), static_cast<size_t>(0));
+  EXPECT_EQ(offsetof(struct ip_mreqn, imr_address), static_cast<size_t>(4));
+  EXPECT_EQ(offsetof(struct ip_mreqn, imr_ifindex), static_cast<size_t>(8));
+
+  EXPECT_EQ(offsetof(struct ip_msfilter, imsf_multiaddr),
+            static_cast<size_t>(0));
+  EXPECT_EQ(offsetof(struct ip_msfilter, imsf_interface),
+            static_cast<size_t>(4));
+  EXPECT_EQ(offsetof(struct ip_msfilter, imsf_fmode), static_cast<size_t>(8));
+  EXPECT_EQ(offsetof(struct ip_msfilter, imsf_numsrc), static_cast<size_t>(12));
+  EXPECT_EQ(offsetof(struct ip_msfilter, imsf_slist), static_cast<size_t>(16));
+
+  EXPECT_EQ(offsetof(struct ip_opts, ip_dst), static_cast<size_t>(0));
+  EXPECT_EQ(offsetof(struct ip_opts, ip_opts), static_cast<size_t>(4));
+}


        


More information about the libc-commits mailing list