• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 TST_GETSOCKPORT(sockfd) \
30 	tst_getsockport(__FILE__, __LINE__, sockfd)
31 
32 #define SAFE_SOCKET(domain, type, protocol) \
33 	safe_socket(__FILE__, __LINE__, NULL, domain, type, protocol)
34 
35 #define SAFE_GETSOCKOPT(fd, level, optname, optval, optlen) \
36 	safe_getsockopt(__FILE__, __LINE__, fd, level, optname, optval, optlen)
37 
38 #define SAFE_SETSOCKOPT(fd, level, optname, optval, optlen) \
39 	safe_setsockopt(__FILE__, __LINE__, fd, level, optname, optval, optlen)
40 
41 #define SAFE_SETSOCKOPT_INT(fd, l, n, val) \
42 	do { \
43 		int v = val; \
44 		safe_setsockopt(__FILE__, __LINE__, fd, l, n, &v, sizeof(v)); \
45 	} while (0)
46 
47 #define SAFE_SEND(strict, sockfd, buf, len, flags) \
48 	safe_send(__FILE__, __LINE__, strict, sockfd, buf, len, flags)
49 
50 #define SAFE_SENDTO(strict, fd, buf, len, flags, dest_addr, addrlen) \
51 	safe_sendto(__FILE__, __LINE__, strict, fd, buf, len, flags, \
52 		    dest_addr, addrlen)
53 
54 #define SAFE_SENDMSG(msg_len, fd, msg, flags) \
55 	safe_sendmsg(__FILE__, __LINE__, msg_len, fd, msg, flags)
56 
57 #define SAFE_RECVMSG(msg_len, fd, msg, flags)		\
58 	safe_recvmsg(__FILE__, __LINE__, msg_len, fd, msg, flags)
59 
60 #define SAFE_BIND(socket, address, address_len) \
61 	safe_bind(__FILE__, __LINE__, NULL, socket, address, \
62 		  address_len)
63 
64 #define SAFE_LISTEN(socket, backlog) \
65 	safe_listen(__FILE__, __LINE__, NULL, socket, backlog)
66 
67 #define SAFE_CONNECT(sockfd, addr, addrlen) \
68 	safe_connect(__FILE__, __LINE__, NULL, sockfd, addr, addrlen)
69 
70 #define SAFE_GETSOCKNAME(sockfd, addr, addrlen) \
71 	safe_getsockname(__FILE__, __LINE__, NULL, sockfd, addr, \
72 			 addrlen)
73 
74 #define SAFE_GETHOSTNAME(name, size) \
75 	safe_gethostname(__FILE__, __LINE__, name, size)
76 
77 #endif /* TST_SAFE_NET_H__ */
78