1 /* SPDX-License-Identifier: GPL-2.0-or-later 2 * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz> 3 */ 4 5 #ifndef TST_SAFE_NET_H__ 6 #define TST_SAFE_NET_H__ 7 8 #include <sys/types.h> 9 #include <sys/socket.h> 10 #include <netinet/in.h> 11 #include <arpa/inet.h> 12 #include <sys/un.h> 13 14 #include "safe_net_fn.h" 15 #include "tst_net.h" 16 17 #define SAFE_SOCKET(domain, type, protocol) \ 18 safe_socket(__FILE__, __LINE__, NULL, domain, type, protocol) 19 20 #define SAFE_SOCKETPAIR(domain, type, protocol, sv) \ 21 safe_socketpair(__FILE__, __LINE__, domain, type, protocol, sv) 22 23 #define SAFE_GETSOCKOPT(fd, level, optname, optval, optlen) \ 24 safe_getsockopt(__FILE__, __LINE__, fd, level, optname, optval, optlen) 25 26 #define SAFE_SETSOCKOPT(fd, level, optname, optval, optlen) \ 27 safe_setsockopt(__FILE__, __LINE__, fd, level, optname, optval, optlen) 28 29 #define SAFE_SETSOCKOPT_INT(fd, l, n, val) \ 30 do { \ 31 int v = val; \ 32 safe_setsockopt(__FILE__, __LINE__, fd, l, n, &v, sizeof(v)); \ 33 } while (0) 34 35 #define SAFE_SEND(strict, sockfd, buf, len, flags) \ 36 safe_send(__FILE__, __LINE__, strict, sockfd, buf, len, flags) 37 38 #define SAFE_SENDTO(strict, fd, buf, len, flags, dest_addr, addrlen) \ 39 safe_sendto(__FILE__, __LINE__, strict, fd, buf, len, flags, \ 40 dest_addr, addrlen) 41 42 #define SAFE_SENDMSG(msg_len, fd, msg, flags) \ 43 safe_sendmsg(__FILE__, __LINE__, msg_len, fd, msg, flags) 44 45 #define SAFE_RECV(msg_len, fd, buf, size, flags) \ 46 safe_recv(__FILE__, __LINE__, (msg_len), (fd), (buf), (size), (flags)) 47 48 #define SAFE_RECVMSG(msg_len, fd, msg, flags) \ 49 safe_recvmsg(__FILE__, __LINE__, msg_len, fd, msg, flags) 50 51 #define SAFE_BIND(socket, address, address_len) \ 52 safe_bind(__FILE__, __LINE__, NULL, socket, address, \ 53 address_len) 54 55 #define SAFE_LISTEN(socket, backlog) \ 56 safe_listen(__FILE__, __LINE__, NULL, socket, backlog) 57 58 #define SAFE_ACCEPT(sockfd, addr, addrlen) \ 59 safe_accept(__FILE__, __LINE__, NULL, sockfd, addr, addrlen) 60 61 #define SAFE_CONNECT(sockfd, addr, addrlen) \ 62 safe_connect(__FILE__, __LINE__, NULL, sockfd, addr, addrlen) 63 64 #define SAFE_GETSOCKNAME(sockfd, addr, addrlen) \ 65 safe_getsockname(__FILE__, __LINE__, NULL, sockfd, addr, \ 66 addrlen) 67 68 #define SAFE_GETHOSTNAME(name, size) \ 69 safe_gethostname(__FILE__, __LINE__, name, size) 70 71 #define TST_GETSOCKPORT(sockfd) \ 72 tst_getsockport(__FILE__, __LINE__, sockfd) 73 74 #define TST_GET_UNUSED_PORT(family, type) \ 75 tst_get_unused_port(__FILE__, __LINE__, NULL, family, type) 76 77 /* new API only */ 78 79 #define SAFE_GETADDRINFO(src_addr, port, hints, addr_info) \ 80 safe_getaddrinfo(__FILE__, __LINE__, src_addr, port, hints, addr_info) 81 82 #endif /* TST_SAFE_NET_H__ */ 83