diff options
Diffstat (limited to 'src/fastd.h')
-rw-r--r-- | src/fastd.h | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/fastd.h b/src/fastd.h index 6666d70..73c7229 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -34,6 +34,7 @@ #include "vector.h" #include <errno.h> +#include <fcntl.h> #include <poll.h> #include <stdarg.h> #include <stddef.h> @@ -310,10 +311,6 @@ fastd_socket_t* fastd_socket_open(fastd_peer_t *peer, int af); void fastd_socket_close(fastd_socket_t *sock); void fastd_socket_error(fastd_socket_t *sock); -void fastd_open_pipe(int *readfd, int *writefd); -void fastd_setfd(const int fd, int set, int unset); -void fastd_setfl(const int fd, int set, int unset); - void fastd_resolve_peer(fastd_peer_t *peer, fastd_remote_t *remote); void fastd_tuntap_open(void); @@ -332,6 +329,25 @@ static inline int fastd_rand(int min, int max) { } +static inline void fastd_setfd(const int fd, int set) { + int flags = fcntl(fd, F_GETFD); + if (flags < 0) + exit_errno("Getting file descriptor flags failed: fcntl"); + + if (fcntl(fd, F_SETFD, flags|set) < 0) + exit_errno("Setting file descriptor flags failed: fcntl"); +} + +static inline void fastd_setfl(const int fd, int set) { + int flags = fcntl(fd, F_GETFL); + if (flags < 0) + exit_errno("Getting file status flags failed: fcntl"); + + if (fcntl(fd, F_SETFL, flags|set) < 0) + exit_errno("Setting file status flags failed: fcntl"); +} + + #define container_of(ptr, type, member) ({ \ const __typeof__(((type *)0)->member) *_mptr = (ptr); \ (type*)((char*)_mptr - offsetof(type, member)); \ |