From 5d594d012da06bec9b22cac41ecea7ee77aa972b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 18 Mar 2019 11:58:11 +0100 Subject: socket-util: add wrappers for binding socket to ifindex/ifname socket_bind_to_ifindex() uses the the SO_BINDTOIFINDEX sockopt of kernel 5.0, with a fallback to SO_BINDTODEVICE on older kernels. socket_bind_to_ifname() is a trivial wrapper around SO_BINDTODEVICE, the only benefit of using it instead of SO_BINDTODEVICE directly is that it determines the size of the interface name properly so that it also works for unbinding. Moreover, it's an attempt to unify our invocations of the sockopt with a size of strlen(ifname) rather than strlen(ifname)+1... --- src/basic/socket-util.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/basic/socket-util.h') diff --git a/src/basic/socket-util.h b/src/basic/socket-util.h index 574d2b73f5..6920fd99ba 100644 --- a/src/basic/socket-util.h +++ b/src/basic/socket-util.h @@ -198,3 +198,6 @@ static inline int setsockopt_int(int fd, int level, int optname, int value) { return 0; } + +int socket_bind_to_ifname(int fd, const char *ifname); +int socket_bind_to_ifindex(int fd, int ifindex); -- cgit v1.2.1