[libc-commits] [libc] [libc] Add some types to netinet/in.h (PR #196932)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Mon May 11 05:17:38 PDT 2026


https://github.com/labath created https://github.com/llvm/llvm-project/pull/196932

Not including more types because I need to fix in_addr definition first.

This exposes stdint macros and types through the header, but POSIX permits that behavior (and explicitly requires that we define uint8_t and uint32_t).

No test as this is just adding a typedef, and I don't *think* we have tests for that, but I can add a "check that type is defined" test if that is desirable.

>From 0999718cea11922aa83671c998dffe3f823aa4ca Mon Sep 17 00:00:00 2001
From: Pavel Labath <pavel at labath.sk>
Date: Mon, 11 May 2026 12:08:33 +0000
Subject: [PATCH] [libc] Add some types to netinet/in.h

Not including more types because I need to fix in_addr definition first.

This exposes stdint macros and types through the header, but POSIX
permits that behavior (and explicitly requires that we define uint8_t
and uint32_t).

No test as this is just adding a typedef, and I don't *think* we have
tests for that, but I can add a "check that type is defined" test if
that is desirable.
---
 libc/include/CMakeLists.txt                 |  5 ++++-
 libc/include/llvm-libc-types/CMakeLists.txt |  1 +
 libc/include/llvm-libc-types/in_port_t.h    | 16 ++++++++++++++++
 libc/include/netinet/in.yaml                |  5 ++++-
 4 files changed, 25 insertions(+), 2 deletions(-)
 create mode 100644 libc/include/llvm-libc-types/in_port_t.h

diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index fac2b40ca45a8..859cc2b41a56a 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -216,8 +216,11 @@ add_header_macro(
   ../libc/include/netinet/in.yaml
   netinet/in.h
   DEPENDS
-    .llvm_libc_common_h
     .llvm-libc-macros.netinet_in_macros
+    .llvm-libc-types.in_addr_t
+    .llvm-libc-types.in_port_t
+    .llvm-libc-types.sa_family_t
+    .llvm_libc_common_h
 )
 
 add_header_macro(
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index ad294279e0f03..889a85dca169e 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -57,6 +57,7 @@ add_header(gid_t HDR gid_t.h)
 add_header(uid_t HDR uid_t.h)
 add_header(imaxdiv_t HDR imaxdiv_t.h)
 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(in_addr HDR in_addr.h DEPENDS .in_addr_t)
 add_header(ino_t HDR ino_t.h)
 add_header(key_t HDR key_t.h)
diff --git a/libc/include/llvm-libc-types/in_port_t.h b/libc/include/llvm-libc-types/in_port_t.h
new file mode 100644
index 0000000000000..daf33f91d95af
--- /dev/null
+++ b/libc/include/llvm-libc-types/in_port_t.h
@@ -0,0 +1,16 @@
+//===-- Definition of in_port_t type --------------------------------------===//
+//
+// 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_TYPES_IN_PORT_T_H
+#define LLVM_LIBC_TYPES_IN_PORT_T_H
+
+#include "../llvm-libc-types/stdint-macros.h"
+
+typedef uint16_t in_port_t;
+
+#endif // LLVM_LIBC_TYPES_IN_PORT_T_H
diff --git a/libc/include/netinet/in.yaml b/libc/include/netinet/in.yaml
index e7b33dc87334f..8d9749f36ab78 100644
--- a/libc/include/netinet/in.yaml
+++ b/libc/include/netinet/in.yaml
@@ -14,7 +14,10 @@ macros:
     macro_header: netinet-in-macros.h
   - macro_name: IPPROTO_RAW
     macro_header: netinet-in-macros.h
-types: []
+types:
+  - type_name: in_port_t
+  - type_name: in_addr_t
+  - type_name: sa_family_t
 enums: []
 objects: []
 functions: []



More information about the libc-commits mailing list