X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Ffd_device.c;h=0da82591cca8876351b13e83c0ae7998b0564cd1;hb=a459e57de5fa4d32ee1162e49770fd8730e3707d;hp=842955669a424dbda9965f05cdbbe97bae2dc51f;hpb=f5223937e62e1cc5e9b3d322490dd3af8d666750;p=tinc diff --git a/src/fd_device.c b/src/fd_device.c index 84295566..0da82591 100644 --- a/src/fd_device.c +++ b/src/fd_device.c @@ -1,7 +1,7 @@ /* fd_device.c -- Interaction with Android tun fd Copyright (C) 2001-2005 Ivo Timmermans, - 2001-2016 Guus Sliepen + 2001-2021 Guus Sliepen 2009 Grzegorz Dymarek 2016-2020 Pacien TRAN-GIRARD @@ -20,9 +20,11 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "system.h" + +#ifdef HAVE_SYS_UN_H #include -#include "system.h" #include "conf.h" #include "device.h" #include "ethernet.h" @@ -55,25 +57,35 @@ static int read_fd(int socket) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not read from unix socket (error %d)!", ret); return -1; } + +#ifdef IP_RECVERR + if(msg.msg_flags & (MSG_CTRUNC | MSG_OOB | MSG_ERRQUEUE)) { +#else + + if(msg.msg_flags & (MSG_CTRUNC | MSG_OOB)) { +#endif logger(DEBUG_ALWAYS, LOG_ERR, "Error while receiving message (flags %d)!", msg.msg_flags); return -1; } cmsgptr = CMSG_FIRSTHDR(&msg); + if(cmsgptr->cmsg_level != SOL_SOCKET) { logger(DEBUG_ALWAYS, LOG_ERR, "Wrong CMSG level: %d, expected %d!", - cmsgptr->cmsg_level, SOL_SOCKET); + cmsgptr->cmsg_level, SOL_SOCKET); return -1; } + if(cmsgptr->cmsg_type != SCM_RIGHTS) { logger(DEBUG_ALWAYS, LOG_ERR, "Wrong CMSG type: %d, expected %d!", - cmsgptr->cmsg_type, SCM_RIGHTS); + cmsgptr->cmsg_type, SCM_RIGHTS); return -1; } + if(cmsgptr->cmsg_len != CMSG_LEN(sizeof(device_fd))) { logger(DEBUG_ALWAYS, LOG_ERR, "Wrong CMSG data length: %lu, expected %lu!", - cmsgptr->cmsg_len, CMSG_LEN(sizeof(device_fd))); + (unsigned long)cmsgptr->cmsg_len, (unsigned long)CMSG_LEN(sizeof(device_fd))); return -1; } @@ -109,7 +121,9 @@ static struct unix_socket_addr parse_socket_addr(const char *path) { if(strlen(path) >= sizeof(socket_addr.sun_path)) { logger(DEBUG_ALWAYS, LOG_ERR, "Unix socket path too long!"); - return (struct unix_socket_addr) {0}; + return (struct unix_socket_addr) { + 0 + }; } socket_addr.sun_family = AF_UNIX; @@ -222,3 +236,4 @@ const devops_t fd_devops = { .read = read_packet, .write = write_packet, }; +#endif