summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2020-11-16 12:41:39 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-03-12 16:24:29 +0100
commit5ba935045a419f48ef0cad68ad3cd62bd384639f (patch)
tree59c65d49effd8d6af934b6b2be7af2a8e57e6acb
parentc8b7432cba73a4215538726cd98da23a8de9b426 (diff)
downloadsystemd-5ba935045a419f48ef0cad68ad3cd62bd384639f.tar.gz
socket-util: add getsockopt_int() helper
(cherry picked from commit 4e25d4cf0f78ef7c960f2b77c941e3d8751535df)
-rw-r--r--src/basic/socket-util.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h
index 63dc00a58b..897edccda0 100644
--- a/src/basic/socket-util.h
+++ b/src/basic/socket-util.h
@@ -223,6 +223,19 @@ static inline int setsockopt_int(int fd, int level, int optname, int value) {
return 0;
}
+static inline int getsockopt_int(int fd, int level, int optname, int *ret) {
+ int v;
+ socklen_t sl = sizeof(v);
+
+ if (getsockopt(fd, level, optname, &v, &sl) < 0)
+ return -errno;
+ if (sl != sizeof(v))
+ return -EIO;
+
+ *ret = v;
+ return 0;
+}
+
int socket_bind_to_ifname(int fd, const char *ifname);
int socket_bind_to_ifindex(int fd, int ifindex);