aboutsummaryrefslogtreecommitdiff
path: root/support/support_socket_so_timestamp_time64.c
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2021-12-13 11:36:42 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2022-01-28 17:46:43 -0300
commit38bc0f4e78934aab455b31af05cefcbf3c22bece (patch)
treeb2968c33e1c52ac5b4c0e3b783a88fc75cc208e6 /support/support_socket_so_timestamp_time64.c
parent1d1ce7d637fdeb911f82d10f6a23287b5dca2a3b (diff)
downloadglibc-38bc0f4e78934aab455b31af05cefcbf3c22bece.tar.xz
glibc-38bc0f4e78934aab455b31af05cefcbf3c22bece.zip
support: Add support_socket_so_timestamp_time64
Check if the socket support 64-bit network packages timestamps (SO_TIMESTAMP and SO_TIMESTAMPNS). This will be used on recvmsg and recvmmsg tests to check if the timestamp should be generated. Reviewed-by: Florian Weimer <fweimer@redhat.com>
Diffstat (limited to 'support/support_socket_so_timestamp_time64.c')
-rw-r--r--support/support_socket_so_timestamp_time64.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/support/support_socket_so_timestamp_time64.c b/support/support_socket_so_timestamp_time64.c
new file mode 100644
index 0000000000..54bf3f4272
--- /dev/null
+++ b/support/support_socket_so_timestamp_time64.c
@@ -0,0 +1,48 @@
+/* Return whether socket supports 64-bit timestamps.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, see
+ <https://www.gnu.org/licenses/>. */
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/syscall.h>
+#include <sys/socket.h>
+#include <support/support.h>
+#ifdef __linux__
+# include <socket-constants-time64.h>
+#endif
+
+bool
+support_socket_so_timestamp_time64 (int fd)
+{
+#ifdef __linux__
+# if __LINUX_KERNEL_VERSION >= 0x050100 \
+ || __WORDSIZE == 64 \
+ || (defined __SYSCALL_WORDSIZE && __SYSCALL_WORDSIZE == 64)
+ return true;
+# else
+ int level = SOL_SOCKET;
+ int optname = COMPAT_SO_TIMESTAMP_NEW;
+ int optval;
+ socklen_t len = sizeof (optval);
+
+ int r = syscall (__NR_getsockopt, fd, level, optname, &optval, &len);
+ return r != -1;
+# endif
+#else
+ return false;
+#endif
+}