代码拉取完成,页面将自动刷新
From 96681723232e9eb0182279086fef291283004806 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Wed, 27 May 2020 19:27:51 +0200
Subject: [PATCH] socket-util: add generic socket_pass_pktinfo() helper
The helper turns on the protocol specific "packet info" structure cmsg
for three relevant protocols we know.
(cherry picked from commit 35a3eb9bdc95d1e6ba25bc65c78959ea104e45a1)
Related: #1887181
---
src/basic/socket-util.c | 23 +++++++++++++++++++++++
src/basic/socket-util.h | 2 ++
2 files changed, 25 insertions(+)
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c
index 986bc6e67f..053bcba670 100644
--- a/src/basic/socket-util.c
+++ b/src/basic/socket-util.c
@@ -1246,3 +1246,26 @@ int socket_ioctl_fd(void) {
return fd;
}
+
+int socket_pass_pktinfo(int fd, bool b) {
+ int af;
+ socklen_t sl = sizeof(af);
+
+ if (getsockopt(fd, SOL_SOCKET, SO_DOMAIN, &af, &sl) < 0)
+ return -errno;
+
+ switch (af) {
+
+ case AF_INET:
+ return setsockopt_int(fd, IPPROTO_IP, IP_PKTINFO, b);
+
+ case AF_INET6:
+ return setsockopt_int(fd, IPPROTO_IPV6, IPV6_RECVPKTINFO, b);
+
+ case AF_NETLINK:
+ return setsockopt_int(fd, SOL_NETLINK, NETLINK_PKTINFO, b);
+
+ default:
+ return -EAFNOSUPPORT;
+ }
+}
diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h
index 616f2e0d05..c7c9ad34d6 100644
--- a/src/basic/socket-util.h
+++ b/src/basic/socket-util.h
@@ -190,3 +190,5 @@ static inline int setsockopt_int(int fd, int level, int optname, int value) {
return 0;
}
+
+int socket_pass_pktinfo(int fd, bool b);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。