1 /*
2  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef TST_SAFE_NET_H__
19 #define TST_SAFE_NET_H__
20 
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <arpa/inet.h>
25 #include <sys/un.h>
26 
27 #include "safe_net_fn.h"
28 
29 #define SAFE_SOCKET(domain, type, protocol) \
30 	safe_socket(__FILE__, __LINE__, NULL, domain, type, protocol)
31 
32 #define SAFE_SETSOCKOPT(fd, level, optname, optval, optlen) \
33 	safe_setsockopt(__FILE__, __LINE__, fd, level, optname, optval, optlen)
34 
35 #define SAFE_SETSOCKOPT_INT(fd, l, n, val) \
36 	do { \
37 		int v = val; \
38 		safe_setsockopt(__FILE__, __LINE__, fd, l, n, &v, sizeof(v)); \
39 	} while (0)
40 
41 #define SAFE_SEND(strict, sockfd, buf, len, flags) \
42 	safe_send(__FILE__, __LINE__, strict, sockfd, buf, len, flags)
43 
44 #define SAFE_SENDTO(strict, fd, buf, len, flags, dest_addr, addrlen) \
45 	safe_sendto(__FILE__, __LINE__, strict, fd, buf, len, flags, \
46 		    dest_addr, addrlen)
47 
48 #define SAFE_BIND(socket, address, address_len) \
49 	safe_bind(__FILE__, __LINE__, NULL, socket, address, \
50 		  address_len)
51 
52 #define SAFE_LISTEN(socket, backlog) \
53 	safe_listen(__FILE__, __LINE__, NULL, socket, backlog)
54 
55 #define SAFE_CONNECT(sockfd, addr, addrlen) \
56 	safe_connect(__FILE__, __LINE__, NULL, sockfd, addr, addrlen)
57 
58 #define SAFE_GETSOCKNAME(sockfd, addr, addrlen) \
59 	safe_getsockname(__FILE__, __LINE__, NULL, sockfd, addr, \
60 			 addrlen)
61 
62 #define SAFE_GETHOSTNAME(name, size) \
63 	safe_gethostname(__FILE__, __LINE__, name, size)
64 
65 #endif /* TST_SAFE_NET_H__ */
66