summaryrefslogtreecommitdiff
path: root/libc/include
diff options
context:
space:
mode:
authorMichael Jones <michaelrj@google.com>2023-04-24 16:55:54 -0700
committerMichael Jones <michaelrj@google.com>2023-05-03 11:01:11 -0700
commitee17fd7d46a914bed4619f656cc9062c40951e5c (patch)
tree673605e2495245a9d0510202bc3996db907126ad /libc/include
parentfc19204918136074483e576177e05bccb2543d44 (diff)
downloadllvm-ee17fd7d46a914bed4619f656cc9062c40951e5c.tar.gz
[libc] add socket function
This patch adds the function "socket" from the header "sys/socket". It's a simple syscall wrapper, and I plan on adding the related functions in a followup patch. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149622
Diffstat (limited to 'libc/include')
-rw-r--r--libc/include/CMakeLists.txt2
-rw-r--r--libc/include/llvm-libc-macros/linux/sys-socket-macros.h7
-rw-r--r--libc/include/llvm-libc-types/CMakeLists.txt2
-rw-r--r--libc/include/llvm-libc-types/sa_family_t.h19
-rw-r--r--libc/include/llvm-libc-types/struct_sockaddr.h21
5 files changed, 51 insertions, 0 deletions
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index f3b23a5e3e26..9482e16073aa 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -388,6 +388,8 @@ add_gen_header(
DEPENDS
.llvm_libc_common_h
.llvm-libc-macros.sys_socket_macros
+ .llvm-libc-types.struct_sockaddr
+ .llvm-libc-types.sa_family_t
)
add_gen_header(
diff --git a/libc/include/llvm-libc-macros/linux/sys-socket-macros.h b/libc/include/llvm-libc-macros/linux/sys-socket-macros.h
index 74a886408bd4..7de410225b71 100644
--- a/libc/include/llvm-libc-macros/linux/sys-socket-macros.h
+++ b/libc/include/llvm-libc-macros/linux/sys-socket-macros.h
@@ -18,4 +18,11 @@
#define AF_INET 2 // Internet IPv4 Protocol
#define AF_INET6 10 // IP version 6
+#define SOCK_STREAM 1
+#define SOCK_DGRAM 2
+#define SOCK_RAW 3
+#define SOCK_RDM 4
+#define SOCK_SEQPACKET 5
+#define SOCK_PACKET 10
+
#endif // __LLVM_LIBC_MACROS_LINUX_SYS_SOCKET_MACROS_H
diff --git a/libc/include/llvm-libc-types/CMakeLists.txt b/libc/include/llvm-libc-types/CMakeLists.txt
index 37230208e458..0ff124ac9e31 100644
--- a/libc/include/llvm-libc-types/CMakeLists.txt
+++ b/libc/include/llvm-libc-types/CMakeLists.txt
@@ -87,3 +87,5 @@ add_header(struct_termios HDR struct_termios.h DEPENDS .cc_t .speed_t .tcflag_t)
add_header(__getoptargv_t HDR __getoptargv_t.h)
add_header(wchar_t HDR wchar_t.h)
add_header(wint_t HDR wint_t.h)
+add_header(sa_family_t HDR sa_family_t.h)
+add_header(struct_sockaddr HDR struct_sockaddr.h)
diff --git a/libc/include/llvm-libc-types/sa_family_t.h b/libc/include/llvm-libc-types/sa_family_t.h
new file mode 100644
index 000000000000..52b69957b0d3
--- /dev/null
+++ b/libc/include/llvm-libc-types/sa_family_t.h
@@ -0,0 +1,19 @@
+//===-- Definition of sa_family_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_SA_FAMILY_T_H__
+#define __LLVM_LIBC_TYPES_SA_FAMILY_T_H__
+
+// The posix standard only says of sa_family_t that it must be unsigned. The
+// linux man page for "address_families" lists approximately 32 different
+// address families, meaning that a short 16 bit number will have plenty of
+// space for all of them.
+
+typedef unsigned short sa_family_t;
+
+#endif // __LLVM_LIBC_TYPES_SA_FAMILY_T_H__
diff --git a/libc/include/llvm-libc-types/struct_sockaddr.h b/libc/include/llvm-libc-types/struct_sockaddr.h
new file mode 100644
index 000000000000..1ef907904ca3
--- /dev/null
+++ b/libc/include/llvm-libc-types/struct_sockaddr.h
@@ -0,0 +1,21 @@
+//===-- Definition of struct stat -----------------------------------------===//
+//
+// 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_STRUCT_STAT_H__
+#define __LLVM_LIBC_TYPES_STRUCT_STAT_H__
+
+#include <llvm-libc-types/sa_family_t.h>
+
+struct sockaddr {
+ sa_family_t sa_family;
+ // sa_data is a variable length array. It is provided with a length of one
+ // here as a placeholder.
+ char sa_data[1];
+};
+
+#endif // __LLVM_LIBC_TYPES_STRUCT_STAT_H__